From 9feadb50c194f3492d183a25fc97f117cb4f5951 Mon Sep 17 00:00:00 2001 From: Mario Fink Date: Fri, 16 Apr 2021 09:37:58 +0200 Subject: [PATCH] py_imc_termite.pyx: fix special character encoding --- cython/py_imc_termite.pyx | 10 +++++----- python/usage.py | 2 +- python/usage_adv.py | 40 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 python/usage_adv.py diff --git a/cython/py_imc_termite.pyx b/cython/py_imc_termite.pyx index 44506b9..d103984 100644 --- a/cython/py_imc_termite.pyx +++ b/cython/py_imc_termite.pyx @@ -21,7 +21,7 @@ cdef class imctermite: # get JSON list of channels def get_channels(self, bool 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 # print channels @@ -31,11 +31,11 @@ cdef class imctermite: # print table including channels def print_table(self, string outputfile): 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: 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['yname']).rjust(20)+str(chn['xname']).rjust(20)+'\n') for n in range(0,len(chn['ydata'])): - fout.write(str(chn['ydata'][n]).rjust(20)+ - str(chn['xdata'][n]).rjust(20)+'\n') + fout.write(str(chn['xdata'][n]).rjust(20)+ + str(chn['ydata'][n]).rjust(20)+'\n') diff --git a/python/usage.py b/python/usage.py index 2efe44a..1f7eef9 100644 --- a/python/usage.py +++ b/python/usage.py @@ -25,4 +25,4 @@ print(len(chnxdata)) imcraw.print_channels(b"./") # print all channels in single file -imcraw.print_table(b"./allchannels.csv") +# imcraw.print_table(b"./allchannels.csv") diff --git a/python/usage_adv.py b/python/usage_adv.py new file mode 100644 index 0000000..d3ad76e --- /dev/null +++ b/python/usage_adv.py @@ -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")