* add custom.py to README
* Cython: add column_header to print_group * tdm_reaper.cpp/.hpp: allow for custom header and default header with ids * add custom.py as example * fix minimal.py/usage.py to run successfully by default
This commit is contained in:
50
python/custom.py
Normal file
50
python/custom.py
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
import tdm_reaper
|
||||
import json
|
||||
import re
|
||||
|
||||
# create 'tdm_reaper' instance object
|
||||
try :
|
||||
jack = tdm_reaper.tdmreaper(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))
|
@@ -10,6 +10,11 @@ try :
|
||||
for grp in grpids :
|
||||
# write channelgroup to file (prepend './' for local directory!!)
|
||||
grpfile = "./channelgroup_" + str(grp.decode()) + ".csv"
|
||||
jack.print_channelgroup(grp,grpfile.encode(),True,ord(' '))
|
||||
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))
|
||||
|
@@ -24,8 +24,8 @@ for grp in grpids[0:2] :
|
||||
# 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(' '))
|
||||
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))
|
||||
|
||||
@@ -49,7 +49,7 @@ for chn in chnids[0:2] :
|
||||
print(str(chndata[0:6]) + " ...")
|
||||
|
||||
# write channel to file
|
||||
chnfile = "channel_" + str(chn) + ".csv"
|
||||
chnfile = "./channel_" + str(chn) + ".csv"
|
||||
try :
|
||||
jack.print_channel(chn.encode(),chnfile.encode(),True)
|
||||
except RuntimeError as e :
|
||||
|
Reference in New Issue
Block a user