adjusted python interface
This commit is contained in:
parent
89dc943dce
commit
4d31dcd32d
@ -279,6 +279,40 @@ void tdm_ripper::list_channels(std::ostream& gout, int width, int maxshow)
|
||||
}
|
||||
}
|
||||
|
||||
void tdm_ripper::list_groups(std::ostream& gout, int width, int maxshow)
|
||||
{
|
||||
gout<<std::setw(width)<<"group";
|
||||
gout<<std::setw(width)<<"group id";
|
||||
gout<<std::setw(width)<<"group name";
|
||||
gout<<std::setw(width)<<"num channels";
|
||||
gout<<"\n";
|
||||
gout<<std::setfill('-')<<std::setw(4*width+1)<<"\n";
|
||||
gout<<std::setfill(' ');
|
||||
|
||||
for ( int i = 0; i < num_groups_ && i < maxshow; i++ )
|
||||
{
|
||||
gout<<std::setw(width)<<i+1;
|
||||
gout<<std::setw(width)<<group_id_[i];
|
||||
gout<<std::setw(width)<<group_name_[i];
|
||||
gout<<std::setw(width)<<num_channels_group_[i];
|
||||
gout<<"\n";
|
||||
}
|
||||
gout<<"\n\n";
|
||||
|
||||
if ( num_channels_ > maxshow )
|
||||
{
|
||||
for ( int i = num_groups_-maxshow; i < num_channels_; i++ )
|
||||
{
|
||||
gout<<std::setw(width)<<i+1;
|
||||
gout<<std::setw(width)<<group_id_[i];
|
||||
gout<<std::setw(width)<<group_name_[i];
|
||||
gout<<std::setw(width)<<num_channels_group_[i];
|
||||
gout<<"\n";
|
||||
}
|
||||
gout<<"\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
void tdm_ripper::show_structure()
|
||||
{
|
||||
int width = 25;
|
||||
@ -444,11 +478,13 @@ std::vector<double> tdm_ripper::get_channel(int channelid)
|
||||
std::vector<double> chann = convert_channel(channel_ext_[channelid-1]);
|
||||
|
||||
// check if converted value is within expected range
|
||||
for ( int i = 0; i < (int)chann.size(); i++ )
|
||||
{
|
||||
assert( chann[i] >= minmax_[channelid-1].first - 1.0e-10
|
||||
&& chann[i] <= minmax_[channelid-1].second + 1.0e-10 );
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ public:
|
||||
void parse_structure();
|
||||
|
||||
void list_channels(std::ostream& gout = std::cout, int width = 15, int maxshow = 50);
|
||||
void list_groups(std::ostream& gout = std::cout, int width = 15, int maxshow = 50);
|
||||
|
||||
void show_structure();
|
||||
|
||||
@ -148,9 +149,11 @@ public:
|
||||
{
|
||||
return num_groups_;
|
||||
}
|
||||
|
||||
// get number of channels in specific group
|
||||
const int& no_channels(int groupid)
|
||||
{
|
||||
assert( groupid > 0 && groupid <= num_channels_ );
|
||||
assert( groupid > 0 && groupid <= num_groups_ );
|
||||
|
||||
return num_channels_group_[groupid-1];
|
||||
}
|
||||
@ -162,6 +165,28 @@ public:
|
||||
return channel_name_[channelid-1];
|
||||
}
|
||||
|
||||
// obtain overall channel id from combined group and group-specific channel id
|
||||
int obtain_channel_id(int groupid, int channelid)
|
||||
{
|
||||
assert( groupid > 0 && groupid <= num_groups_ );
|
||||
assert( channelid > 0 && channelid <= num_channels_group_[groupid-1] );
|
||||
|
||||
// find cummulative number of channels
|
||||
int numsum = 0;
|
||||
for ( int i = 0; i < groupid-1; i++ )
|
||||
{
|
||||
numsum += num_channels_group_[i];
|
||||
}
|
||||
assert( (numsum + channelid) > 0 && (numsum + channelid) <= num_channels_ );
|
||||
|
||||
return numsum+channelid;
|
||||
}
|
||||
|
||||
const std::string& channel_name(int groupid, int channelid)
|
||||
{
|
||||
return channel_name_[obtain_channel_id(groupid,channelid)-1];
|
||||
}
|
||||
|
||||
const std::string& group_name(int groupid)
|
||||
{
|
||||
assert( groupid > 0 && groupid <= num_channels_ );
|
||||
@ -169,6 +194,11 @@ public:
|
||||
return group_name_[groupid-1];
|
||||
}
|
||||
|
||||
const std::string& channel_unit(int groupid, int channelid)
|
||||
{
|
||||
return units_[obtain_channel_id(groupid,channelid)-1];
|
||||
}
|
||||
|
||||
void list_datatypes();
|
||||
|
||||
// convert array of chars to single integer or floating point double
|
||||
@ -183,7 +213,13 @@ public:
|
||||
// std::vector<double> convert_channel(int byteoffset, int length, int typesize);
|
||||
std::vector<double> convert_channel(int channelid);
|
||||
|
||||
// obtain channel from overall channel id...
|
||||
std::vector<double> get_channel(int channelid);
|
||||
// ...or from group id and group-specific channel id
|
||||
std::vector<double> channel(int groupid, int channelid)
|
||||
{
|
||||
return get_channel(obtain_channel_id(groupid,channelid));
|
||||
}
|
||||
|
||||
void print_channel(int channelid, const char* filename, int width = 15);
|
||||
|
||||
|
33
main.cpp
33
main.cpp
@ -22,25 +22,34 @@ int main(int argc, char* argv[])
|
||||
ripper.list_channels(fout);
|
||||
fout.close();
|
||||
|
||||
std::cout<<"number of channels "<<ripper.num_channels()<<"\n\n";
|
||||
ripper.list_groups();
|
||||
std::ofstream gout("data/list_of_groups.dat");
|
||||
ripper.list_groups(gout);
|
||||
gout.close();
|
||||
|
||||
std::cout<<"number of channels "<<ripper.num_channels()<<"\n";
|
||||
std::cout<<"number of groups "<<ripper.num_groups()<<"\n\n";
|
||||
|
||||
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";
|
||||
}
|
||||
// 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";
|
||||
// for ( int j = 0; j < ripper.no_channels(i+1); j++ )
|
||||
// {
|
||||
// std::cout<<std::setw(10)<<i+1<<std::setw(10)<<j+1<<std::setw(30)<<ripper.channel_name(i+1,j+1)<<"\n";
|
||||
// }
|
||||
// }
|
||||
|
||||
// std::vector<double> channA = ripper.get_channel(1);
|
||||
// for ( auto el: channA ) std::cout<<el<<"\n";
|
||||
// std::cout<<"\n\n";
|
||||
|
||||
// for ( int i = 0; i < 30; i++ )
|
||||
// // for ( int i = 0; i < ripper.num_channels(); i++ )
|
||||
// // for ( int i = 11880; i < ripper.num_channels(); i++ )
|
||||
// {
|
||||
// ripper.print_channel(i+1,("data/channel_"+std::to_string(i+1)+"_"
|
||||
// +ripper.channel_name(i+1)+".dat").c_str());
|
||||
// }
|
||||
for ( int i = 3; i < 10; i++ )
|
||||
// for ( int i = 0; i < ripper.num_channels(); i++ )
|
||||
// for ( int i = 11880; i < ripper.num_channels(); i++ )
|
||||
{
|
||||
ripper.print_channel(i+1,("data/channel_"+std::to_string(i+1)+"_"
|
||||
+ripper.channel_name(i+1)+".dat").c_str());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -21,18 +21,32 @@ cdef class pytdmripper:
|
||||
|
||||
def no_channels(self, int groupid):
|
||||
assert (groupid >= 0 and groupid < self.cripp.num_groups()), "index of group must be in [0,n-1]"
|
||||
groupidinc = groupid+1
|
||||
return self.cripp.no_channels(groupidinc)
|
||||
return self.cripp.no_channels(groupid+1)
|
||||
|
||||
def num_groups(self):
|
||||
return self.cripp.num_groups()
|
||||
|
||||
def no_channel_groups(self):
|
||||
return self.cripp.num_groups()
|
||||
|
||||
def channel_name(self,int groupid,int channelid):
|
||||
return self.cripp.channel_name(groupid+1,channelid+1).decode('utf-8')
|
||||
|
||||
def channel_unit(self,int groupid,int channelid):
|
||||
return (self.cripp.channel_unit(groupid+1,channelid+1))
|
||||
|
||||
def get_channel(self, int channelid):
|
||||
return np.asarray(self.cripp.get_channel(channelid))
|
||||
|
||||
def channel(self,int groupid,int channelid):
|
||||
return self.cripp.channel(groupid+1,channelid+1)
|
||||
|
||||
def print_channel(self, int channelid, const char* filename):
|
||||
self.cripp.print_channel(channelid,filename)
|
||||
|
||||
def close(self):
|
||||
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()
|
||||
|
@ -15,5 +15,11 @@ cdef extern from "tdm_ripper.hpp":
|
||||
int num_channels()
|
||||
int no_channels(int)
|
||||
int num_groups()
|
||||
int no_channel_groups()
|
||||
string channel_name(int,int)
|
||||
string channel_unit(int,int)
|
||||
vector[double] get_channel(int)
|
||||
vector[double] channel(int,int)
|
||||
void print_channel(int,const char*)
|
||||
# dummy method for compatibility
|
||||
void close()
|
||||
|
Loading…
x
Reference in New Issue
Block a user