* 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
This commit is contained in:
parent
9feadb50c1
commit
8708d2d008
@ -3,6 +3,7 @@
|
|||||||
from imc_termite cimport imc_termite
|
from imc_termite cimport imc_termite
|
||||||
|
|
||||||
import json as jn
|
import json as jn
|
||||||
|
import decimal
|
||||||
# import numpy as np
|
# import numpy as np
|
||||||
|
|
||||||
cdef class imctermite:
|
cdef class imctermite:
|
||||||
@ -21,7 +22,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(errors="ignore")) for chn in chnlst]
|
chnlstjn = [jn.loads(chn.decode(errors="ignore"),parse_float=decimal.Decimal) for chn in chnlst]
|
||||||
return chnlstjn
|
return chnlstjn
|
||||||
|
|
||||||
# print channels
|
# print channels
|
||||||
@ -31,11 +32,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(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:
|
with open(outputfile.decode(),'w') as fout:
|
||||||
for chn in chnlstjn:
|
for chn in chnlstjn:
|
||||||
fout.write(str(chn['yunit']).rjust(20)+str(chn['xunit']).rjust(20)+'\n')
|
fout.write('#' +str(chn['xname']).rjust(19)+str(chn['yname']).rjust(20)+'\n')
|
||||||
fout.write(str(chn['yname']).rjust(20)+str(chn['xname']).rjust(20)+'\n')
|
fout.write('#'+str(chn['xunit']).rjust(19)+str(chn['yunit']).rjust(20)+'\n')
|
||||||
for n in range(0,len(chn['ydata'])):
|
for n in range(0,len(chn['ydata'])):
|
||||||
fout.write(str(chn['xdata'][n]).rjust(20)+
|
fout.write(str(chn['xdata'][n]).rjust(20)+
|
||||||
str(chn['ydata'][n]).rjust(20)+'\n')
|
str(chn['ydata'][n]).rjust(20)+'\n')
|
||||||
|
@ -95,7 +95,7 @@ namespace imc
|
|||||||
ss<<"[";
|
ss<<"[";
|
||||||
if ( myvec.size() <= limit )
|
if ( myvec.size() <= limit )
|
||||||
{
|
{
|
||||||
for ( dt el: myvec ) ss<<el<<",";
|
for ( dt el: myvec ) ss<<std::setprecision(10)<<el<<",";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -104,7 +104,7 @@ namespace imc
|
|||||||
ss<<"...";
|
ss<<"...";
|
||||||
for ( unsigned long int i = myvec.size()-heals; i < myvec.size(); i++ )
|
for ( unsigned long int i = myvec.size()-heals; i < myvec.size(); i++ )
|
||||||
{
|
{
|
||||||
ss<<myvec[i]<<",";
|
ss<<std::setprecision(10)<<myvec[i]<<",";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::string sumstr = ss.str();
|
std::string sumstr = ss.str();
|
||||||
|
@ -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")
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import imc_termite
|
import imc_termite
|
||||||
import json
|
import json
|
||||||
import glob
|
import glob
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# list files in sample directory
|
# list files in sample directory
|
||||||
@ -12,29 +13,20 @@ print(rawlist1)
|
|||||||
|
|
||||||
for fl in rawlist1:
|
for fl in rawlist1:
|
||||||
|
|
||||||
print("converting " + str(fl))
|
print("converting " + str(fl) + " : " + str(os.path.basename(fl)) )
|
||||||
|
|
||||||
# declare and initialize instance of "imctermite" by passing a raw-file
|
# declare and initialize instance of "imctermite" by passing a raw-file
|
||||||
try :
|
try :
|
||||||
imcraw = imc_termite.imctermite(fl.encode())
|
imcraw = imc_termite.imctermite(fl.encode())
|
||||||
except RuntimeError as e :
|
except RuntimeError as e :
|
||||||
print("failed to load/parse raw-file: " + str(e))
|
raise Exception("failed to load/parse raw-file: " + str(e))
|
||||||
|
|
||||||
# obtain list of channels as list of dictionaries (without data)
|
# obtain list of channels as list of dictionaries (without data)
|
||||||
channels = imcraw.get_channels(False)
|
channels = imcraw.get_channels(False)
|
||||||
print(json.dumps(channels,indent=4, sort_keys=False))
|
print(json.dumps(channels,indent=4, sort_keys=False))
|
||||||
|
|
||||||
# # obtain data of first channel (with data)
|
# print the channels into a specific directory
|
||||||
# channelsdata = imcraw.get_channels(True)
|
imcraw.print_channels(b"./")
|
||||||
# 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
|
# print all channels in single file
|
||||||
# imcraw.print_table(b"./allchannels.csv")
|
imcraw.print_table(("./"+str(os.path.basename(fl).split('.')[0])+"_allchannels.csv").encode())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user