Skip to content

Commit

Permalink
add datavector.change_frames() to pykst
Browse files Browse the repository at this point in the history
  • Loading branch information
netterfield committed Sep 6, 2016
1 parent 077515b commit f39ef48
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pyKst/demo/datavector.py
Expand Up @@ -13,3 +13,6 @@
c1 = client.new_curve(V1, V2)
p1 = client.new_plot(font_size = 12)
p1.add(c1)

V1.change_frames(1000, 500, 0, False)
V2.change_frames(1000, 500, 0, False)
16 changes: 16 additions & 0 deletions pyKst/pykst.py
Expand Up @@ -1107,6 +1107,22 @@ def change(self, filename, field, start, num_frames, skip, boxcarFirst):
+b2str(start)+","+b2str(num_frames)+","+b2str(skip)
+","+b2str(boxcarFirst)+")")

def change_frames(self, start, num_frames, skip, boxcarFirst):
""" Change the parameters of a data vector.
:param start: The starting index of the vector.
start = -1 for count from end.
:param num_frames: The number of frames to read.
num_frames = -1 for read to end.
:param skip: The number of frames per sample read.
skip = 0 to read every sample.
:param boxcarFirst: apply a boxcar filter before skiping.
"""
self.client.send_si(self.handle, "changeFrames("
+b2str(start)+","+b2str(num_frames)+","+b2str(skip)
+","+b2str(boxcarFirst)+")")

def field(self):
""" Returns the fieldname. """
return self.client.send_si(self.handle, "field()")
Expand Down
1 change: 1 addition & 0 deletions src/libkst/datavector.cpp
Expand Up @@ -185,6 +185,7 @@ void DataVector::changeFile(DataSourcePtr in_file) {
void DataVector::changeFrames(int in_f0, int in_n,
int in_skip, bool in_DoSkip,
bool in_DoAve) {

Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);

if (dataSource()) {
Expand Down
17 changes: 17 additions & 0 deletions src/libkst/vectorscriptinterface.cpp
Expand Up @@ -132,6 +132,7 @@ DataVectorSI::DataVectorSI(DataVectorPtr it) {
}

_fnMap.insert("change",&DataVectorSI::change);
_fnMap.insert("changeFrames",&DataVectorSI::changeFrames);
_fnMap.insert("field",&DataVectorSI::field);
_fnMap.insert("filename",&DataVectorSI::filename);
_fnMap.insert("start",&DataVectorSI::start);
Expand Down Expand Up @@ -191,6 +192,22 @@ QByteArray DataVectorSI::endEditUpdate() {
/* data vector commands */
/***************************/

QString DataVectorSI::changeFrames(QString &command) {
QStringList vars = getArgs(command);

_datavector->writeLock();
_datavector->changeFrames(
vars.at(0).toInt(), // f0
vars.at(1).toInt(), // n
vars.at(2).toInt(), // skip
vars.at(2).toInt() > 0, // do skip
vars.at(3) == "True" // do average
);
_datavector->unlock();
return "Done";
}


QString DataVectorSI::change(QString& command) {
QStringList vars = getArgs(command);

Expand Down
1 change: 1 addition & 0 deletions src/libkst/vectorscriptinterface.h
Expand Up @@ -78,6 +78,7 @@ class KSTCORE_EXPORT DataVectorSI : public VectorCommonSI
static ScriptInterface* newVector(ObjectStore *store);

QString change(QString &command);
QString changeFrames(QString &command);
QString field(QString &command);
QString filename(QString &command);
QString start(QString &command);
Expand Down

0 comments on commit f39ef48

Please sign in to comment.