py_imc_termite.pyx: fix special character encoding
This commit is contained in:
parent
dbeb1b862a
commit
9feadb50c1
@ -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')
|
||||
|
@ -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")
|
||||
|
40
python/usage_adv.py
Normal file
40
python/usage_adv.py
Normal 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")
|
Loading…
x
Reference in New Issue
Block a user