py_imc_termite.pyx: fix special character encoding

This commit is contained in:
Mario Fink 2021-04-16 09:37:58 +02:00
parent dbeb1b862a
commit 9feadb50c1
3 changed files with 46 additions and 6 deletions

View File

@ -21,7 +21,7 @@ cdef class imctermite:
# get JSON list of channels # get JSON list of channels
def get_channels(self, bool data): def get_channels(self, bool data):
chnlst = self.cpp_imc.get_channels(True,data) chnlst = self.cpp_imc.get_channels(True,data)
chnlstjn = [jn.loads(chn.decode()) for chn in chnlst] chnlstjn = [jn.loads(chn.decode(errors="ignore")) for chn in chnlst]
return chnlstjn return chnlstjn
# print channels # print channels
@ -31,11 +31,11 @@ cdef class imctermite:
# print table including channels # print table including channels
def print_table(self, string outputfile): def print_table(self, string outputfile):
chnlst = self.cpp_imc.get_channels(True,True) chnlst = self.cpp_imc.get_channels(True,True)
chnlstjn = [jn.loads(chn.decode()) for chn in chnlst] chnlstjn = [jn.loads(chn.decode(errors="ignore")) for chn in chnlst]
with open(outputfile.decode(),'w') as fout: with open(outputfile.decode(),'w') as fout:
for chn in chnlstjn: for chn in chnlstjn:
fout.write(str(chn['yname']).rjust(20)+str(chn['xname']).rjust(20)+'\n')
fout.write(str(chn['yunit']).rjust(20)+str(chn['xunit']).rjust(20)+'\n') fout.write(str(chn['yunit']).rjust(20)+str(chn['xunit']).rjust(20)+'\n')
fout.write(str(chn['yname']).rjust(20)+str(chn['xname']).rjust(20)+'\n')
for n in range(0,len(chn['ydata'])): for n in range(0,len(chn['ydata'])):
fout.write(str(chn['ydata'][n]).rjust(20)+ fout.write(str(chn['xdata'][n]).rjust(20)+
str(chn['xdata'][n]).rjust(20)+'\n') str(chn['ydata'][n]).rjust(20)+'\n')

View File

@ -25,4 +25,4 @@ print(len(chnxdata))
imcraw.print_channels(b"./") imcraw.print_channels(b"./")
# print all channels in single file # print all channels in single file
imcraw.print_table(b"./allchannels.csv") # imcraw.print_table(b"./allchannels.csv")

40
python/usage_adv.py Normal file
View File

@ -0,0 +1,40 @@
import imc_termite
import json
import glob
from pathlib import Path
# list files in sample directory
# fileobj1 = Path("samples/").rglob("*.raw")
# rawlist1 = [str(fl) for fl in fileobj1]
rawlist1 = ["samples/datasetB/datasetB_32.raw"]
print(rawlist1)
for fl in rawlist1:
print("converting " + str(fl))
# declare and initialize instance of "imctermite" by passing a raw-file
try :
imcraw = imc_termite.imctermite(fl.encode())
except RuntimeError as e :
print("failed to load/parse raw-file: " + str(e))
# obtain list of channels as list of dictionaries (without data)
channels = imcraw.get_channels(False)
print(json.dumps(channels,indent=4, sort_keys=False))
# # obtain data of first channel (with data)
# channelsdata = imcraw.get_channels(True)
# if len(channelsdata) > 0 :
# chnydata = channelsdata[0]['ydata']
# chnxdata = channelsdata[0]['xdata']
#
# print(len(chnydata))
# print(len(chnxdata))
#
# # print the channels into a specific directory
# imcraw.print_channels(b"./")
# print all channels in single file
# imcraw.print_table(b"./allchannels.csv")