obtain meta information tags
This commit is contained in:
parent
53ed09967a
commit
5b1b2622bd
17
example.py
17
example.py
@ -2,13 +2,17 @@ import tdm_ripper
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
tdmpath = b"samples/SineData.tdm"
|
tdmpatha = b"samples/SineData.tdm"
|
||||||
tdxpath = b"samples/SineData.tdx"
|
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
|
# create instance of ripper class
|
||||||
# RP = tdm_ripper.pytdmripper(tdmpath)
|
# RP = tdm_ripper.pytdmripper(tdmpath)
|
||||||
RP = tdm_ripper.pytdmripper(tdmpath,tdxpath)
|
RP = tdm_ripper.pytdmripper(tdmpathchz,tdxpathchz)
|
||||||
# RP = tdm_ripper.pytdmripper(b"/Users/mariofink/git/Conti_HBS/data_science/python/features/tdm_tmp_slow/75_1/Messung.tdm")
|
|
||||||
|
|
||||||
# provide overview of available channels
|
# provide overview of available channels
|
||||||
RP.show_channels()
|
RP.show_channels()
|
||||||
@ -22,6 +26,11 @@ for i in range(0,RP.num_groups()):
|
|||||||
# print particular channel to file
|
# print particular channel to file
|
||||||
RP.print_channel(1,b"SineData_extract.dat")
|
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')
|
||||||
|
|
||||||
# extract channel and return it to numpy array
|
# extract channel and return it to numpy array
|
||||||
# channels = RP.get_channel(1)
|
# channels = RP.get_channel(1)
|
||||||
# Nlen = len(channels)
|
# Nlen = len(channels)
|
||||||
|
@ -112,10 +112,24 @@ void tdm_ripper::parse_structure()
|
|||||||
pugi::xml_node subtreedata = xml_doc_.child("usi:tdm").child("usi:data");
|
pugi::xml_node subtreedata = xml_doc_.child("usi:tdm").child("usi:data");
|
||||||
|
|
||||||
// extract basic information about available groups
|
// extract basic information about available groups
|
||||||
|
int groupcount = 0;
|
||||||
for (pugi::xml_node anode: subtreedata.children())
|
for (pugi::xml_node anode: subtreedata.children())
|
||||||
{
|
{
|
||||||
if ( std::string(anode.name()).compare("tdm_channelgroup") == 0 )
|
if ( std::string(anode.name()).compare("tdm_channelgroup") == 0 )
|
||||||
{
|
{
|
||||||
|
groupcount++;
|
||||||
|
|
||||||
|
// meta-info is pressumably contained in FIRST channel-group xml tree element
|
||||||
|
// (eventually identify by name = TESTINFOS ??? )
|
||||||
|
if ( groupcount == 1 )
|
||||||
|
{
|
||||||
|
for ( pugi::xml_node mnode: anode.child("instance_attributes").children() )
|
||||||
|
{
|
||||||
|
meta_info_.insert(std::pair<std::string,std::string>(mnode.attribute("name").value(),
|
||||||
|
mnode.child_value("s")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int numchann = count_occ_string(anode.child_value("channels"),"id");
|
int numchann = count_occ_string(anode.child_value("channels"),"id");
|
||||||
if ( numchann > 0 || !neglect_empty_groups_ )
|
if ( numchann > 0 || !neglect_empty_groups_ )
|
||||||
{
|
{
|
||||||
@ -183,6 +197,8 @@ void tdm_ripper::parse_structure()
|
|||||||
std::cout<<std::setw(25)<<std::left<<"xml_values_:"<<xml_values_.size()<<"\n";
|
std::cout<<std::setw(25)<<std::left<<"xml_values_:"<<xml_values_.size()<<"\n";
|
||||||
std::cout<<std::setw(25)<<std::left<<"xml_double_sequence_:"<<xml_double_sequence_.size()<<"\n";
|
std::cout<<std::setw(25)<<std::left<<"xml_double_sequence_:"<<xml_double_sequence_.size()<<"\n";
|
||||||
std::cout<<std::right<<"\n\n";
|
std::cout<<std::right<<"\n\n";
|
||||||
|
|
||||||
|
std::cout<<"meta-info snippets "<<meta_info_.size()<<"\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract basic information about available channels
|
// extract basic information about available channels
|
||||||
@ -212,29 +228,7 @@ void tdm_ripper::parse_structure()
|
|||||||
minmax_.push_back(minmaxchan);
|
minmax_.push_back(minmaxchan);
|
||||||
|
|
||||||
// get correct assignment of channels to byteoffset, length and datatype
|
// get correct assignment of channels to byteoffset, length and datatype
|
||||||
// std::string locol = get_str_between(anode.child_value("local_columns"),"\"","\"");
|
|
||||||
// std::string locolval;
|
|
||||||
// locolval = local_columns_val_[locol];
|
|
||||||
// for (pugi::xml_node anode: subtreedata.children())
|
|
||||||
// {
|
|
||||||
// if ( std::string(anode.name()).compare("localcolumn") == 0
|
|
||||||
// && std::string(anode.attribute("id").value()).compare(locol) == 0 )
|
|
||||||
// {
|
|
||||||
// locolval = get_str_between(anode.child_value("values"),"\"","\"");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
std::string locolvalext;
|
std::string locolvalext;
|
||||||
// locolvalext = double_sequence_id_[locolval];
|
|
||||||
// for (pugi::xml_node anode: subtreedata.children())
|
|
||||||
// {
|
|
||||||
// if ( std::string(anode.name()).compare("double_sequence") == 0
|
|
||||||
// && std::string(anode.attribute("id").value()).compare(locolval) == 0 )
|
|
||||||
// {
|
|
||||||
// locolvalext = anode.child("values").attribute("external").value();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
locolvalext = xml_double_sequence_[xml_values_[xml_local_columns_[anode.attribute("id").value()]]];
|
locolvalext = xml_double_sequence_[xml_values_[xml_local_columns_[anode.attribute("id").value()]]];
|
||||||
|
|
||||||
// save external id of channel and get corresponding channel index
|
// save external id of channel and get corresponding channel index
|
||||||
|
@ -57,6 +57,9 @@ class tdm_ripper
|
|||||||
pugi::xml_document xml_doc_;
|
pugi::xml_document xml_doc_;
|
||||||
pugi::xml_parse_result xml_result_;
|
pugi::xml_parse_result xml_result_;
|
||||||
|
|
||||||
|
// .tdm-file eventually contains some meta information about measurement
|
||||||
|
std::map<std::string,std::string> meta_info_;
|
||||||
|
|
||||||
// binary data container
|
// binary data container
|
||||||
std::vector<unsigned char> tdxbuf_;
|
std::vector<unsigned char> tdxbuf_;
|
||||||
|
|
||||||
@ -250,18 +253,18 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// evtl. get group time_stamp of .tdm file given in unix format
|
// get time-stamp of channel-group in .tdm file given in unix format
|
||||||
static std::string unix_timestamp(std::string unixts)
|
static std::string unix_timestamp(std::string unixts)
|
||||||
{
|
{
|
||||||
// average year of Gregorian calender
|
// average year of Gregorian calender
|
||||||
const double avgdaysofyear = 365.0 + 1./4 - 1./100 + 1./400
|
const double avgdaysofyear = 365.0 + 1./4 - 1./100 + 1./400
|
||||||
- 8./24561; // gauge timestamp according to DIADEM result
|
- 8./24561; // gauge timestamp according to DIADEM result
|
||||||
|
|
||||||
// convert string to long int = number of second since 0000/01/01 00:00
|
// convert string to long int = number of seconds since 0000/01/01 00:00
|
||||||
long int ts = atol(unixts.c_str());
|
long int ts = atol(unixts.c_str());
|
||||||
assert( ts >= 0 );
|
assert( ts >= 0 );
|
||||||
|
|
||||||
// use STL to convert timestamp (epoch usually starts from 01.01.1970)
|
// use STL to convert timestamp (epoch usually starts on 01.01.1970)
|
||||||
std::time_t tstime = ts - 1970*avgdaysofyear*86400;
|
std::time_t tstime = ts - 1970*avgdaysofyear*86400;
|
||||||
|
|
||||||
// get rid of linebreak character and return the result
|
// get rid of linebreak character and return the result
|
||||||
@ -314,6 +317,12 @@ public:
|
|||||||
|
|
||||||
void print_channel(int channelid, const char* filename, int width = 15);
|
void print_channel(int channelid, const char* filename, int width = 15);
|
||||||
|
|
||||||
|
// obtain any meta information about .tdm-file if available
|
||||||
|
std::string get_meta(std::string attribute_name)
|
||||||
|
{
|
||||||
|
return meta_info_[attribute_name];
|
||||||
|
}
|
||||||
|
|
||||||
// TODO add elements/methods to build .tdm and write .tdx files for your own data
|
// TODO add elements/methods to build .tdm and write .tdx files for your own data
|
||||||
// by constructing xml document tree and write data to binary .tdx
|
// by constructing xml document tree and write data to binary .tdx
|
||||||
// void set_channels(std::vector<std::string> channels);
|
// void set_channels(std::vector<std::string> channels);
|
||||||
|
7
main.cpp
7
main.cpp
@ -8,7 +8,7 @@ int main(int argc, char* argv[])
|
|||||||
assert( argc > 1 && "please provide a filename and path" );
|
assert( argc > 1 && "please provide a filename and path" );
|
||||||
|
|
||||||
// declare and initialize tdm_ripper
|
// declare and initialize tdm_ripper
|
||||||
tdm_ripper ripper(argv[1]); //,"samples/SineData.tdx",false);
|
tdm_ripper ripper(argv[1],argv[2],false); //,"samples/SineData.tdx",false);
|
||||||
|
|
||||||
// ripper.list_datatypes();
|
// ripper.list_datatypes();
|
||||||
// ripper.show_structure();
|
// ripper.show_structure();
|
||||||
@ -36,6 +36,11 @@ int main(int argc, char* argv[])
|
|||||||
std::cout<<"number of channels "<<ripper.num_channels()<<"\n";
|
std::cout<<"number of channels "<<ripper.num_channels()<<"\n";
|
||||||
std::cout<<"number of groups "<<ripper.num_groups()<<"\n\n";
|
std::cout<<"number of groups "<<ripper.num_groups()<<"\n\n";
|
||||||
|
|
||||||
|
std::cout<<"\n"<<ripper.get_meta("SMP_Name")<<"\n";
|
||||||
|
std::cout<<ripper.get_meta("SMP_Aufbau_Nr")<<"\n";
|
||||||
|
std::cout<<ripper.get_meta("SMP_Type")<<"\n";
|
||||||
|
std::cout<<ripper.get_meta("Location")<<"\n\n";
|
||||||
|
|
||||||
// for ( int i = 0; i < ripper.num_groups(); i++ )
|
// for ( int i = 0; i < ripper.num_groups(); i++ )
|
||||||
// {
|
// {
|
||||||
// std::cout<<std::setw(10)<<i+1<<std::setw(10)<<ripper.no_channels(i+1)<<"\n";
|
// std::cout<<std::setw(10)<<i+1<<std::setw(10)<<ripper.no_channels(i+1)<<"\n";
|
||||||
|
@ -62,13 +62,8 @@ cdef class pytdmripper:
|
|||||||
def print_channel(self, int channelid, const char* filename):
|
def print_channel(self, int channelid, const char* filename):
|
||||||
self.cripp.print_channel(channelid,filename)
|
self.cripp.print_channel(channelid,filename)
|
||||||
|
|
||||||
|
def meta_info(self, string attribute_name):
|
||||||
|
return self.cripp.get_meta(attribute_name)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
dummy = ""
|
dummy = ""
|
||||||
|
|
||||||
# integrate into CONTI_HBS workflow by adding methods: (29.04.2019)
|
|
||||||
# tdm_loader.OpenFile(tmp_path + name_prefix + '/Messung.tdm', encoding='utf-8')
|
|
||||||
# .no_channel_groups()
|
|
||||||
# .no_channels(i)
|
|
||||||
# .channel_name(i, j)
|
|
||||||
# .channel(i, j)
|
|
||||||
# .close()
|
|
||||||
|
@ -28,5 +28,6 @@ cdef extern from "tdm_ripper.hpp":
|
|||||||
double get_max(int,int)
|
double get_max(int,int)
|
||||||
vector[double] channel(int,int)
|
vector[double] channel(int,int)
|
||||||
void print_channel(int,const char*)
|
void print_channel(int,const char*)
|
||||||
|
string get_meta(string attribute_name)
|
||||||
# dummy method for compatibility
|
# dummy method for compatibility
|
||||||
void close()
|
void close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user