From 8708d2d0083e8260f72629717c5fa1a8650a8c44 Mon Sep 17 00:00:00 2001 From: Mario Fink Date: Mon, 26 Apr 2021 19:41:56 +0200 Subject: [PATCH] * cython/py_imc_termite.pyx: json loads take care of floats, fix column assignment * imc_channel.hpp: fix floating precision for get_channel() * extend/include advanced usage in examples --- cython/py_imc_termite.pyx | 9 +++++---- lib/imc_channel.hpp | 4 ++-- python/usage.py | 2 +- python/usage_adv.py | 22 +++++++--------------- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/cython/py_imc_termite.pyx b/cython/py_imc_termite.pyx index d103984..4c5500d 100644 --- a/cython/py_imc_termite.pyx +++ b/cython/py_imc_termite.pyx @@ -3,6 +3,7 @@ from imc_termite cimport imc_termite import json as jn +import decimal # import numpy as np cdef class imctermite: @@ -21,7 +22,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(errors="ignore")) for chn in chnlst] + chnlstjn = [jn.loads(chn.decode(errors="ignore"),parse_float=decimal.Decimal) for chn in chnlst] return chnlstjn # print channels @@ -31,11 +32,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(errors="ignore")) for chn in chnlst] + chnlstjn = [jn.loads(chn.decode(errors="ignore"),parse_float=decimal.Decimal) for chn in chnlst] with open(outputfile.decode(),'w') as fout: for chn in chnlstjn: - 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') + fout.write('#' +str(chn['xname']).rjust(19)+str(chn['yname']).rjust(20)+'\n') + fout.write('#'+str(chn['xunit']).rjust(19)+str(chn['yunit']).rjust(20)+'\n') for n in range(0,len(chn['ydata'])): fout.write(str(chn['xdata'][n]).rjust(20)+ str(chn['ydata'][n]).rjust(20)+'\n') diff --git a/lib/imc_channel.hpp b/lib/imc_channel.hpp index a5766cf..26f5d3f 100644 --- a/lib/imc_channel.hpp +++ b/lib/imc_channel.hpp @@ -95,7 +95,7 @@ namespace imc ss<<"["; if ( myvec.size() <= limit ) { - for ( dt el: myvec ) ss< 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 the channels into a specific directory + imcraw.print_channels(b"./") -# print all channels in single file -# imcraw.print_table(b"./allchannels.csv") + # print all channels in single file + imcraw.print_table(("./"+str(os.path.basename(fl).split('.')[0])+"_allchannels.csv").encode())