* add github workflow for building wheels
* rename cython module for more consistency * restructure python code * proper python module setup * bump major version 2.0.0
This commit is contained in:
38
python/examples/usage.py
Normal file
38
python/examples/usage.py
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
import IMCtermite
|
||||
import json
|
||||
import os
|
||||
|
||||
# declare and initialize instance of "imctermite" by passing a raw-file
|
||||
try :
|
||||
imcraw = IMCtermite.imctermite(b"samples/exampleB.raw")
|
||||
except RuntimeError as e :
|
||||
raise Exception("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"./data",ord(','))
|
||||
|
||||
# print all channels separately
|
||||
idx = 0
|
||||
for chn in channels :
|
||||
print(str(idx)+" : "+chn['name']+" : "+chn['uuid'])
|
||||
filname = os.path.join("./data",str(idx) + "_" + chn['name']+".csv")
|
||||
print(filname)
|
||||
imcraw.print_channel(chn['uuid'].encode(),filname.encode(),ord(','))
|
||||
idx = idx + 1
|
||||
|
||||
# print all channels in single file
|
||||
# imcraw.print_table(b"./data/allchannels.csv")
|
30
python/examples/usage_adv.py
Normal file
30
python/examples/usage_adv.py
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
import IMCtermite
|
||||
import json
|
||||
import os
|
||||
|
||||
# list files in sample directory
|
||||
# fileobj1 = Path("samples/").rglob("*.raw")
|
||||
# rawlist1 = [str(fl) for fl in fileobj1]
|
||||
rawlist1 = ["samples/datasetB/datasetB_29.raw"]
|
||||
print(rawlist1)
|
||||
|
||||
for fl in rawlist1:
|
||||
|
||||
print("converting " + str(fl) + " : " + str(os.path.basename(fl)) )
|
||||
|
||||
# declare and initialize instance of "imctermite" by passing a raw-file
|
||||
try :
|
||||
imcraw = IMCtermite.imctermite(fl.encode())
|
||||
except RuntimeError as e :
|
||||
raise Exception("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))
|
||||
|
||||
# print the channels into a specific directory
|
||||
imcraw.print_channels(b"./",ord(','))
|
||||
|
||||
# print all channels in single file
|
||||
imcraw.print_table(("./"+str(os.path.basename(fl).split('.')[0])+"_allchannels.csv").encode())
|
50
python/examples/usage_ext.py
Normal file
50
python/examples/usage_ext.py
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
import IMCtermite
|
||||
import json
|
||||
import os
|
||||
import datetime
|
||||
|
||||
# declare and initialize instance of "imctermite" by passing a raw-file
|
||||
try :
|
||||
imcraw = IMCtermite.imctermite(b"samples/sampleB.raw")
|
||||
except RuntimeError as e :
|
||||
raise Exception("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 all channels (including full data)
|
||||
channelsdata = imcraw.get_channels(True)
|
||||
|
||||
# everything that follows is an example that specifically makes use only of
|
||||
# the first (index = 0) channel ...
|
||||
idx = 0
|
||||
|
||||
if len(channelsdata) > 0 :
|
||||
|
||||
# get first channel's data
|
||||
chnydata = channelsdata[idx]['ydata']
|
||||
chnxdata = channelsdata[idx]['xdata']
|
||||
print("xdata: " + str(len(chnxdata)))
|
||||
print("ydata: " + str(len(chnydata)))
|
||||
|
||||
# extract trigger-time
|
||||
trigtim = datetime.datetime.fromisoformat(channels[idx]["trigger-time"])
|
||||
print(trigtim)
|
||||
|
||||
# file output of data with absolute timestamp in 1st column
|
||||
filname = os.path.join("./",channelsdata[idx]['name']+".csv")
|
||||
print("writing output into " + filname)
|
||||
with open(filname,'w') as fout :
|
||||
# include column header
|
||||
fout.write( str(channelsdata[idx]['xname']) + '[' + str(channelsdata[idx]['xunit']) + "]"
|
||||
+ ","
|
||||
+ str(channelsdata[idx]['yname']) + '[' + str(channelsdata[idx]['yunit']) + "]"
|
||||
+ "\n" )
|
||||
# add data (introduce time shift according to trigger-time)
|
||||
for row in range(0,len(chnxdata)) :
|
||||
fout.write( str( (trigtim + datetime.timedelta(seconds=chnxdata[row])).isoformat() )
|
||||
+ ","
|
||||
+ str( chnydata[row])
|
||||
+ "\n" )
|
29
python/examples/usage_files.py
Normal file
29
python/examples/usage_files.py
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
from IMCtermite import imctermite
|
||||
|
||||
def show_results(imcraw) :
|
||||
|
||||
channels = imcraw.get_channels(False)
|
||||
print(channels)
|
||||
|
||||
channelsData = imcraw.get_channels(True)
|
||||
print("number of channels: " + str(len(channelsData)))
|
||||
|
||||
for (i,chn) in enumerate(channelsData) :
|
||||
print(str(i) + " | " + chn['name'])
|
||||
print(chn['xname'] + " | " + chn['xunit'])
|
||||
print(chn['xdata'][:10])
|
||||
print(chn['yname'] + " | " + chn['yunit'])
|
||||
print(chn['ydata'][:10])
|
||||
|
||||
print("")
|
||||
|
||||
# create instance of 'imctermite'
|
||||
imcraw = imctermite(b'samples/sampleA.raw')
|
||||
|
||||
show_results(imcraw)
|
||||
|
||||
# use previous instance of 'imctermite' to provide new file
|
||||
imcraw.submit_file(b'samples/sampleB.raw')
|
||||
|
||||
show_results(imcraw)
|
Reference in New Issue
Block a user