return proper numpy array

This commit is contained in:
Mario Fink 2019-04-26 14:55:29 +02:00
parent 5333441336
commit 61d8473cbd
3 changed files with 28 additions and 3 deletions

View File

@ -1,5 +1,6 @@
import tdm_ripper
import numpy as np
import matplotlib.pyplot as plt
tdmpath = b"samples/SineData.tdm"
tdxpath = b"samples/SineData.tdx"
@ -17,6 +18,27 @@ print(RP.num_groups())
RP.print_channel(1,b"SineData_extract.dat")
# extract channel and return it to numpy array
chann = RP.get_channel(1)
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])
print(dim(chann))
x = np.linspace(0,Nlen,Nlen)
plt.plot(x,channels[0:1000])
plt.plot(x,channels[1000:2000])
plt.plot(x,channels[2000:3000])
plt.plot(x,channels[3000:4000])
plt.plot(x,channels[4000:5000])
plt.plot(x,channels[5000:6000])
plt.plot(x,channels[6000:7000])
plt.plot(x,channels[7000:8000])
plt.grid()
plt.show()

View File

@ -278,6 +278,8 @@ std::vector<double> tdm_ripper::get_channel(int channelid)
void tdm_ripper::print_channel(int channelid, const char* filename, int width)
{
assert( channelid > 0 && channelid <= num_channels_ && "please provide valid channel id" );
std::ofstream fout(filename);
std::vector<double> channdat = get_channel(channelid);

View File

@ -2,6 +2,7 @@
# distutils: language = c++
from tdm_ripper cimport tdm_ripper
import numpy as np
cdef class pytdmripper:
@ -24,7 +25,7 @@ cdef class pytdmripper:
return self.cripp.num_groups()
def get_channel(self, int channelid):
return self.cripp.get_channel(channelid)
return np.asarray(self.cripp.get_channel(channelid))
def print_channel(self, int channelid, const char* filename):
self.cripp.print_channel(channelid,filename)