added group_name and obtain_channel_id to cython, added extract_all.py producing .csv dump of all .tdm and .tdx data
This commit is contained in:
parent
3247ac531e
commit
a29370cd6e
@ -2,7 +2,7 @@
|
||||
|
||||
## C++ core
|
||||
|
||||
- XML parser employs pugixml https://pugixml.org/
|
||||
- XML parser employs pugixml https://pugixml.org/ and it's repository https://github.com/zeux/pugixml
|
||||
- analyse .tdm file
|
||||
- buffer binary .tdx data
|
||||
- convert binary data to datatypes according to given .tdm information
|
||||
|
62
extract_all.py
Normal file
62
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 staff !!
|
||||
|
||||
#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'))
|
@ -542,13 +542,13 @@ std::vector<double> tdm_ripper::get_channel(int channelid)
|
||||
std::vector<double> chann = convert_channel(channel_ext_[channelid]);
|
||||
|
||||
// check if converted value is within expected range
|
||||
// for ( int i = 0; i < (int)chann.size(); i++ )
|
||||
// {
|
||||
// if ( chann[i] < minmax_[channelid-1].first
|
||||
// || chann[i] > minmax_[channelid-1].second ) std::cout<<std::setw(20)<<chann[i]<<std::setw(20)<<minmax_[channelid-1].first<<std::setw(20)<<minmax_[channelid-1].second<<"\n";
|
||||
// assert( chann[i] >= minmax_[channelid-1].first - 1.0e-6
|
||||
// && chann[i] <= minmax_[channelid-1].second + 1.0e-6 );
|
||||
// }
|
||||
for ( int i = 0; i < (int)chann.size(); i++ )
|
||||
{
|
||||
// if ( chann[i] < minmax_[channelid-1].first
|
||||
// || chann[i] > minmax_[channelid-1].second ) std::cout<<std::setw(20)<<chann[i]<<std::setw(20)<<minmax_[channelid-1].first<<std::setw(20)<<minmax_[channelid-1].second<<"\n";
|
||||
assert( chann[i] >= minmax_[channelid-1].first - 1.0e-6
|
||||
&& chann[i] <= minmax_[channelid-1].second + 1.0e-6 );
|
||||
}
|
||||
|
||||
return chann;
|
||||
}
|
||||
|
@ -35,12 +35,18 @@ cdef class pytdmripper:
|
||||
def channel_name(self,int groupid,int channelid):
|
||||
return self.cripp.channel_name(groupid,channelid).decode('utf-8')
|
||||
|
||||
def group_name(self,int groupid):
|
||||
return self.cripp.group_name(groupid).decode('utf-8')
|
||||
|
||||
def channel_unit(self,int groupid,int channelid):
|
||||
return (self.cripp.channel_unit(groupid,channelid))
|
||||
|
||||
def channel_exists(self,int groupid, string channelname):
|
||||
return self.cripp.channel_exists(groupid,channelname)
|
||||
|
||||
def obtain_channel_id(self,int groupid, int channelid):
|
||||
return self.cripp.obtain_channel_id(groupid,channelid)
|
||||
|
||||
def get_channel(self, int channelid):
|
||||
return np.asarray(self.cripp.get_channel(channelid))
|
||||
|
||||
|
@ -19,8 +19,10 @@ cdef extern from "tdm_ripper.hpp":
|
||||
int num_groups()
|
||||
int no_channel_groups()
|
||||
string channel_name(int,int)
|
||||
string group_name(int)
|
||||
string channel_unit(int,int)
|
||||
int channel_exists(int,string)
|
||||
int obtain_channel_id(int,int)
|
||||
vector[double] get_channel(int)
|
||||
int channel_length(int,int)
|
||||
string time_stamp(int,bool)
|
||||
|
Loading…
x
Reference in New Issue
Block a user