clean up repo, prepare CLI tool
This commit is contained in:
56
python/example.py
Normal file
56
python/example.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import tdm_ripper
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
tdmpatha = b"samples/SineData.tdm"
|
||||
tdxpatha = b"samples/SineData.tdx"
|
||||
tdmpathb = b"/Users/mariofink/Downloads/CONTI_HBS_samples/config_id_1/001_Test_DIAdem/Messung.tdm"
|
||||
tdxpathb = b"/Users/mariofink/Downloads/CONTI_HBS_samples/config_id_1/001_Test_DIAdem/Messung.tdx"
|
||||
|
||||
tdmpathchz = tdmpathb
|
||||
tdxpathchz = tdxpathb
|
||||
|
||||
# create instance of ripper class
|
||||
# RP = tdm_ripper.pytdmripper(tdmpath)
|
||||
RP = tdm_ripper.pytdmripper(tdmpathchz,tdxpathchz)
|
||||
|
||||
# provide overview of available channels
|
||||
RP.show_channels()
|
||||
|
||||
print(RP.num_channels())
|
||||
print(RP.num_groups())
|
||||
|
||||
for i in range(0,RP.num_groups()):
|
||||
print(str(i+1).rjust(10)+str(RP.no_channels(i)).rjust(10))
|
||||
|
||||
# print particular channel to file
|
||||
RP.print_channel(1,b"SineData_extract.dat")
|
||||
|
||||
# show some meta information
|
||||
print(RP.meta_info(b"SMP_Name").decode('utf-8'))
|
||||
print(RP.meta_info(b"Location").decode('utf-8'))
|
||||
print('\n')
|
||||
|
||||
RP.print_meta(b"meta_information.dat")
|
||||
|
||||
# extract channel and return it to numpy array
|
||||
# channels = RP.get_channel(1)
|
||||
# Nlen = len(channels)
|
||||
# channels = np.append(channels,RP.get_channel(2))
|
||||
# channels = np.append(channels,RP.get_channel(3))
|
||||
# channels = np.append(channels,RP.get_channel(4))
|
||||
# channels = np.append(channels,RP.get_channel(5))
|
||||
# channels = np.append(channels,RP.get_channel(6))
|
||||
# channels = np.append(channels,RP.get_channel(7))
|
||||
# channels = np.append(channels,RP.get_channel(8))
|
||||
# print(channels.shape)
|
||||
# print("\n\n")
|
||||
# print(channels[0:40])
|
||||
#
|
||||
# x = np.linspace(0,Nlen,Nlen)
|
||||
# plt.plot(x,channels[0:Nlen])
|
||||
# plt.plot(x,channels[Nlen:2*Nlen])
|
||||
# plt.plot(x,channels[2*Nlen:3*Nlen])
|
||||
#
|
||||
# plt.grid()
|
||||
# plt.show()
|
62
python/extract_all.py
Normal file
62
python/extract_all.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import tdm_ripper
|
||||
import numpy as np
|
||||
import argparse
|
||||
import re
|
||||
|
||||
parser = argparse.ArgumentParser(description='provide path of both .tdm and corresponding .tdx file')
|
||||
parser.add_argument('tdm_file',type=str,help='path of .tdm file')
|
||||
parser.add_argument('tdx_file',type=str,help='path of .tdx file')
|
||||
#parser.add_argument('--tdx_file',type=str,help='path of .tdx file',default='')
|
||||
parser.add_argument('--out_directory',type=str,help='choose directory where to write data',default='./')
|
||||
parser.add_argument('--prefix_name',type=str,help='provide dataset name used as filename prefix',default='')
|
||||
args = parser.parse_args()
|
||||
#print(args)
|
||||
|
||||
# process arguments
|
||||
tdmpath = args.tdm_file #"samples/SineData.tdm"
|
||||
tdxpath = args.tdx_file #"samples/SineData.tdx"
|
||||
outdirx = args.out_directory
|
||||
fprefix = args.prefix_name
|
||||
|
||||
# if no prefix is given, .tdm filename will be used
|
||||
if fprefix == '' :
|
||||
fprefix = tdmpath.rstrip('.tdm').split('/')[-1]
|
||||
# TODO better use os.path !!
|
||||
|
||||
#print(fprefix)
|
||||
|
||||
# create instance of ripper class
|
||||
RP = tdm_ripper.pytdmripper(tdmpath.encode('utf-8'),tdxpath.encode('utf-8'))
|
||||
|
||||
# provide overview over available groups and channels
|
||||
#RP.show_groups()
|
||||
#RP.show_channels()
|
||||
|
||||
# obtain number of available groups and channels
|
||||
numgr = RP.num_groups()
|
||||
numch = RP.num_channels()
|
||||
|
||||
# dump all meta information
|
||||
RP.print_meta((outdirx+fprefix+'.csv').encode('utf-8'))
|
||||
|
||||
# dump all available groups and channels
|
||||
for g in range(0,numgr):
|
||||
numgrch = RP.no_channels(g)
|
||||
for c in range(0,numgrch):
|
||||
#print(str(g).rjust(10)+str(c).rjust(10))
|
||||
# print(str(RP.channel_length(g,c)))
|
||||
# print(RP.channel_name(g,c))
|
||||
#print(RP.channel(g,c))
|
||||
# obtained overall channel id
|
||||
chid = RP.obtain_channel_id(g,c)
|
||||
# get group's and channel's name
|
||||
gname = RP.group_name(g)
|
||||
cname = RP.channel_name(g,c)
|
||||
#print(gname.rjust(30)+cname.rjust(30))
|
||||
# use regular expression replacement to sanitize group and channel names
|
||||
gname = re.sub('[!@#$%^&*()-+= ,]','',gname)
|
||||
cname = re.sub('[!@#$%^&*()-+= ,]','',cname)
|
||||
# generate filename
|
||||
fichan = fprefix + '_' + str(g+1) + '_' + str(c+1) + '_' + gname + '_' + cname + '.csv'
|
||||
# print channel
|
||||
RP.print_channel(chid,(outdirx+fichan).encode('utf-8'))
|
Reference in New Issue
Block a user