* tidy up and simplify python/cython/pypi setup and directory structure
* rename python modules with consistent nomenclature (breaking changes!)
This commit is contained in:
50
python/examples/custom.py
Normal file
50
python/examples/custom.py
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
import TDMtermite
|
||||
import json
|
||||
import re
|
||||
|
||||
# create 'tdm_termite' instance object
|
||||
try :
|
||||
jack = TDMtermite.tdmtermite(b'samples/SineData.tdm',b'samples/SineData.tdx')
|
||||
except RuntimeError as e :
|
||||
print("failed to load/decode TDM files: " + str(e))
|
||||
|
||||
# list ids of channelgroups
|
||||
grpids = jack.get_channelgroup_ids()
|
||||
|
||||
# iterate through group-ids
|
||||
for grp in grpids[0:2] :
|
||||
|
||||
# obtain meta data of channelgroups
|
||||
grpinfo = jack.get_channelgroup_info(grp)
|
||||
print( json.dumps(grpinfo,sort_keys=False,indent=4) )
|
||||
|
||||
# get channel meta-data and compose header
|
||||
column_header = ""
|
||||
chns = grpinfo['channels'].split(' ')
|
||||
for chn in chns :
|
||||
# obtain channel's meta-data as dictionary (JSON)
|
||||
chninfo = jack.get_channel_info(chn.encode())
|
||||
# print( json.dumps(chninfo,sort_keys=False,indent=4) )
|
||||
# choose e.g. channel-id and name to compose column header
|
||||
chnhead = ( str(chninfo['channel-id']) + "("
|
||||
+ str(chninfo['name']).replace(',',' ') + ")" )
|
||||
# append to full header
|
||||
column_header = column_header + chnhead + ","
|
||||
# remove last comma
|
||||
column_header = column_header[0:-1]
|
||||
|
||||
print("column_header:\n"+column_header+"\n")
|
||||
|
||||
# write channelgroup to file
|
||||
try :
|
||||
grpname = re.sub('[^A-Za-z0-9]','',grpinfo['name'])
|
||||
grpfile = str("./channelgroup_") + str(grp.decode()) + "_" + str(grpname) + str(".csv")
|
||||
jack.print_channelgroup(grp, # id of group to be written
|
||||
grpfile.encode(), # filename
|
||||
False, # no meta-data header
|
||||
ord(','), # csv separator character
|
||||
column_header.encode() # provide column header
|
||||
)
|
||||
except RuntimeError as e :
|
||||
print("failed to print channelgroup: " + str(grp) + " : " + str(e))
|
20
python/examples/minimal.py
Normal file
20
python/examples/minimal.py
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
import TDMtermite
|
||||
|
||||
# create 'tdm_termite' instance object
|
||||
try :
|
||||
jack = TDMtermite.tdmtermite(b'samples/SineData.tdm',b'samples/SineData.tdx')
|
||||
# list ids of channelgroups
|
||||
grpids = jack.get_channelgroup_ids()
|
||||
# iterate through groups
|
||||
for grp in grpids :
|
||||
# write channelgroup to file (prepend './' for local directory!!)
|
||||
grpfile = "./channelgroup_" + str(grp.decode()) + ".csv"
|
||||
jack.print_channelgroup(grp, # id of group to be written
|
||||
grpfile.encode(), # filename
|
||||
False, # include meta-data fileheader?
|
||||
ord(','), # csv separator character
|
||||
b"" # (empty=default) column header
|
||||
)
|
||||
except RuntimeError as e :
|
||||
print("failed to load/decode/write TDM files: " + str(e))
|
56
python/examples/usage.py
Normal file
56
python/examples/usage.py
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
import TDMtermite
|
||||
# import numpy as np
|
||||
import json
|
||||
import re
|
||||
|
||||
# create 'tdm_termite' instance object
|
||||
try :
|
||||
jack = TDMtermite.tdmtermite(b'samples/SineData.tdm',b'samples/SineData.tdx')
|
||||
except RuntimeError as e :
|
||||
print("failed to load/decode TDM files: " + str(e))
|
||||
|
||||
# list ids of channelgroups
|
||||
grpids = jack.get_channelgroup_ids()
|
||||
grpids = [x.decode() for x in grpids]
|
||||
print("list of channelgroups: ",grpids)
|
||||
|
||||
for grp in grpids[0:2] :
|
||||
|
||||
# obtain meta data of channelgroups
|
||||
grpinfo = jack.get_channelgroup_info(grp.encode())
|
||||
print( json.dumps(grpinfo,sort_keys=False,indent=4) )
|
||||
|
||||
# write channelgroup to file
|
||||
try :
|
||||
grpname = re.sub('[^A-Za-z0-9]','',grpinfo['name'])
|
||||
grpfile = "./channelgroup_" + str(grp) + "_" + str(grpname) + ".csv"
|
||||
jack.print_channelgroup(grp.encode(),grpfile.encode(),True,ord(' '),b'')
|
||||
except RuntimeError as e :
|
||||
print("failed to print channelgroup: " + str(grp) + " : " + str(e))
|
||||
|
||||
# list ids of channels
|
||||
chnids = jack.get_channel_ids()
|
||||
chnids = [x.decode() for x in chnids]
|
||||
print("list of channels: ",chnids)
|
||||
|
||||
for chn in chnids[0:2] :
|
||||
|
||||
# obtain meta-data
|
||||
chninfo = jack.get_channel_info(chn.encode())
|
||||
print( json.dumps(chninfo,sort_keys=False,indent=4) )
|
||||
|
||||
# channel data
|
||||
try :
|
||||
chndata = jack.get_channel(chn.encode())
|
||||
except RuntimeError as e :
|
||||
print("failed to extract channel: " + str(chn) + " : " + str(e))
|
||||
|
||||
print(str(chndata[0:6]) + " ...")
|
||||
|
||||
# write channel to file
|
||||
chnfile = "./channel_" + str(chn) + ".csv"
|
||||
try :
|
||||
jack.print_channel(chn.encode(),chnfile.encode(),True)
|
||||
except RuntimeError as e :
|
||||
print("failed to print channel: " + str(chn) + " : " + str(e))
|
Reference in New Issue
Block a user