Showing with 288 additions and 211 deletions.
  1. +1 −12 pyKst/pykst.py
  2. +4 −3 src/libkst/editablevector.cpp
  3. +84 −3 src/libkst/vector.cpp
  4. +18 −7 src/libkst/vector.h
  5. +0 −3 src/libkstapp/csddialog.cpp
  6. +1 −2 src/libkstapp/datawizard.cpp
  7. +1 −6 src/libkstapp/powerspectrumdialog.cpp
  8. +9 −1 src/libkstmath/basicplugin.cpp
  9. +1 −1 src/libkstmath/basicplugin.h
  10. +2 −2 src/libkstmath/csd.cpp
  11. +2 −0 src/libkstmath/dataobject.cpp
  12. +1 −1 src/libkstmath/dataobject.h
  13. +2 −17 src/libkstmath/dataobjectscriptinterface.cpp
  14. +0 −1 src/libkstmath/dataobjectscriptinterface.h
  15. +2 −18 src/libkstmath/psd.cpp
  16. +1 −5 src/libkstmath/psd.h
  17. +2 −18 src/libkstmath/psdcalculator.cpp
  18. +1 −1 src/libkstmath/psdcalculator.h
  19. +2 −3 src/libkstmath/psdfactory.cpp
  20. +4 −4 src/plugins/dataobject/convolution/convolve/convolve.cpp
  21. +4 −4 src/plugins/dataobject/convolution/deconvolve/deconvolve.cpp
  22. +1 −1 src/plugins/dataobject/correlation/autocorrelation/autocorrelation.cpp
  23. +2 −2 src/plugins/dataobject/crossspectrum/crossspectrum.cpp
  24. +5 −2 src/plugins/dataobject/genericfilter/genericfilter.cpp
  25. +4 −2 src/plugins/dataobject/interpolations/interpolations.h
  26. +20 −15 src/plugins/dataobject/linefit/linefit.cpp
  27. +4 −2 src/plugins/filters/cumulativeaverage/cumulativeaverage.cpp
  28. +8 −3 src/plugins/filters/cumulativesum/cumulativesum.cpp
  29. +1 −1 src/plugins/filters/filters.h
  30. +2 −2 src/plugins/filters/unwind/filterunwind.cpp
  31. +8 −4 src/plugins/fits/common.h
  32. +3 −3 src/plugins/fits/linear.h
  33. +4 −4 src/plugins/fits/linear_weighted.h
  34. +8 −4 src/plugins/fits/non_linear.h
  35. +8 −4 src/plugins/fits/non_linear_weighted.h
  36. +0 −26 src/widgets/fftoptions.cpp
  37. +0 −5 src/widgets/fftoptions.h
  38. +50 −16 src/widgets/fftoptions.ui
  39. +18 −3 tests/dirfile_maker/dirfile_maker.c
13 changes: 1 addition & 12 deletions pyKst/pykst.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ def new_spectrum(self,
apodize_function = 0,
sigma = 1.0,
output_type = 0,
interpolate_over_holes = True,
name=""):
""" Create a new Spectrum in kst.
Expand All @@ -437,7 +436,6 @@ def new_spectrum(self,
apodize_function,
sigma,
output_type,
interpolate_over_holes,
name)

def spectrum(self, name):
Expand Down Expand Up @@ -1862,7 +1860,6 @@ class Spectrum(Object) :
:param apodize_function: index of the apodization function - see apodize_function()
:param sigma: only used if gausian apodization is selected.
:param output_type: index for the output type - see output_type()
:param interpolate_over_holes: interpolate over NaNs, if true.
The apodize funcition is::
Expand Down Expand Up @@ -1891,7 +1888,6 @@ def __init__(self, client,
apodize_function = 0,
sigma = 1.0,
output_type = 0,
interpolate_over_holes = True,
name="", new=True) :

Object.__init__(self,client)
Expand All @@ -1909,8 +1905,7 @@ def __init__(self, client,
rate_units + "," +
b2str(apodize_function) + "," +
b2str(sigma) + "," +
b2str(output_type) + "," +
b2str(interpolate_over_holes) + ")")
b2str(output_type) + "," + ")")

self.handle=self.client.send("endEdit()")
self.handle.remove(0,self.handle.indexOf("ing ")+4)
Expand Down Expand Up @@ -2002,12 +1997,6 @@ def output_type(self):
retval = self.client.send_si(self.handle, "outputTypeIndex()")
return retval

def interpolate_over_holes(self):
""" replace NaNs with an interpolation, if true. """
retval = self.client.send_si(self.handle, "interpolateOverHoles()")
return retval


# FIT ###################################################################
class Fit(Object) :
""" This is a class which provides some methods common to all fits """
Expand Down
7 changes: 4 additions & 3 deletions src/libkst/editablevector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ void EditableVector::setValue(const int &i, const double &val) { //sa Vector::ch
_scalars["sum"]->setValue(_sum+val-_v[i]);
_scalars["sumsquared"]->setValue(_sum*_sum);
_scalars["max"]->setValue(qMax(_max,val));
_scalars["min"]->setValue(qMin(_min,_min));
double b=qMax(double(0.0),_minPos);
_scalars["minpos"]->setValue(qMin(_min,b));
_scalars["min"]->setValue(qMin(_min,val));
if (val>=0.0) {
_scalars["minpos"]->setValue(qMin(_minPos,val));
}
_scalars["last"]->setValue(_v[_size-1]);
_scalars["first"]->setValue(_v[0]);
_v[i]=val;
Expand Down
87 changes: 84 additions & 3 deletions src/libkst/vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ Vector::Vector(ObjectStore *store)
_size = size;
}
_is_rising = false;
_has_nan = false;
_v_no_nans_dirty = true;
_v_no_nans_size = 0;

_scalars.clear();
_strings.clear();
Expand Down Expand Up @@ -156,7 +159,7 @@ double Vector::interpolate(int in_i, int ns_i) const {
GENERATE_INTERPOLATION
}


/** same as above, but as a function for use in plugins, etc */
double kstInterpolate(double *_v, int _size, int in_i, int ns_i) {
GENERATE_INTERPOLATION
}
Expand Down Expand Up @@ -193,7 +196,6 @@ double kstInterpolate(double *_v, int _size, int in_i, int ns_i) {
} \
}


#define GENERATE_INTERPOLATION \
assert(_size > 0); \
/** Limits checks - optional? **/ \
Expand Down Expand Up @@ -244,9 +246,12 @@ double Vector::interpolateNoHoles(int in_i, int ns_i) const {
}


#if 0
double kstInterpolateNoHoles(double *_v, int _size, int in_i, int ns_i) {
GENERATE_INTERPOLATION
}
#endif


#undef FIND_LEFT
#undef FIND_RIGHT
Expand All @@ -261,6 +266,19 @@ double Vector::value(int i) const {
return _v[i];
}

double Vector::noNanValue(int i) {
if (i < 0 || i >= _size) { // can't look before beginning or past end
return 0.0;
}
if (_has_nan) {
if (_v_no_nans_dirty) {
updateVNoNans();
}
return _v_no_nans[i];
}
return _v[i];
}

void Vector::CreateScalars(ObjectStore *store) {
if (!_isScalarList) {
_min = _max = _mean = _minPos = 0.0;
Expand Down Expand Up @@ -345,6 +363,8 @@ void Vector::updateScalars() {
}
}


#if 0
double* Vector::realloced(double *memptr, int newSize) {
double *old = _v;
_v = memptr;
Expand All @@ -357,14 +377,57 @@ double* Vector::realloced(double *memptr, int newSize) {
updateScalars();
return old;
}

#endif

void Vector::setV(double *memptr, int newSize) {
_v = memptr;
NumNew = newSize;
_size = newSize;
}

#define FIND_LEFT(val, idx) \
for (; idx >= 0; --idx) { \
if (_v[idx] == _v[idx]) { \
val = _v[idx]; break; \
} \
}

#define FIND_RIGHT(val, idx) \
for (; idx < _size; ++idx) { \
if (_v[idx] == _v[idx]) { \
val = _v[idx]; break; \
} \
}

void Vector::updateVNoNans() {

if (_size != _v_no_nans_size) {
kstrealloc(_v_no_nans, _size*sizeof(double));
_v_no_nans_size = _size;
}

for (int in_i = 0; in_i < _size; in_i++) {
if (_v[in_i] == _v[in_i]) {
_v_no_nans[in_i] = _v[in_i];
} else {
double left = 0., right = 0.;
int leftIndex = in_i, rightIndex = in_i;
FIND_LEFT(left, leftIndex);
FIND_RIGHT(right, rightIndex);
if (leftIndex == -1) {
_v_no_nans[in_i] = right;
} else if (rightIndex == _size) {
_v_no_nans[in_i] = left;
} else {
_v_no_nans[in_i] = left + (right - left) * double(in_i - leftIndex) / double(rightIndex - leftIndex);
}
}
}
_v_no_nans_dirty = false;
}
#undef FIND_LEFT
#undef FIND_RIGHT


void Vector::zero() {
_ns_min = _ns_max = 0.0;
Expand Down Expand Up @@ -428,6 +491,9 @@ void Vector::internalUpdate() {
_imax = _imin = 0;
_nsum = 0;

_has_nan = false;
_v_no_nans_dirty = true;

if (_size > 0) {
_is_rising = true;

Expand All @@ -436,6 +502,10 @@ void Vector::internalUpdate() {
// do nothing
}

if (i>0) {
_has_nan = true;
}

if (i == _size) { // there were no finite points:
if (!_isScalarList) {
_scalars["sum"]->setValue(sum);
Expand Down Expand Up @@ -506,6 +576,7 @@ void Vector::internalUpdate() {
}
} else {
_is_rising = false;
_has_nan = true;
}
}

Expand Down Expand Up @@ -586,6 +657,16 @@ double *Vector::value() const {
return _v;
}

double *Vector::noNanValue() {
if (_has_nan) {
if (_v_no_nans_dirty) {
updateVNoNans();
}
return _v_no_nans;
}
return _v;
}


void Vector::newSync() {
NumNew = NumShifted = 0;
Expand Down
25 changes: 18 additions & 7 deletions src/libkst/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class KstDataObject;

// KST::interpolate is still too polluting
KSTCORE_EXPORT double kstInterpolate(double *v, int _size, int in_i, int ns_i);
KSTCORE_EXPORT double kstInterpolateNoHoles(double *v, int _size, int in_i, int ns_i);
//KSTCORE_EXPORT double kstInterpolateNoHoles(double *v, int _size, int in_i, int ns_i);

class Vector;
typedef SharedPtr<Vector> VectorPtr;
Expand Down Expand Up @@ -77,11 +77,16 @@ class KSTCORE_EXPORT Vector : public Primitive
/** Return V[i], interpolated/decimated to have ns_i total samples */
double interpolate(int i, int ns_i) const;

/** Return V[i], interpolated/decimated to have ns_i total samples, without any holes */
/** Return V[i], interpolated/decimated to have ns_i total samples, without any NaNs */
double interpolateNoHoles(int i, int ns_i) const;

/** Return V[i] uninterpolated */
double value(int i) const;
double noNanValue(int i);

/** Return a pointer to the raw vector */
double *value() const;
double *noNanValue();

/** Return Minimum value in Vector */
inline double min() const { return _min; }
Expand Down Expand Up @@ -139,9 +144,6 @@ class KSTCORE_EXPORT Vector : public Primitive
/** Save vector information */
virtual void save(QXmlStreamWriter &s);

/** Return a pointer to the raw vector */
double *value() const;

/** access functions for _isScalarList */
bool isScalarList() const { return _isScalarList; }

Expand Down Expand Up @@ -196,6 +198,11 @@ class KSTCORE_EXPORT Vector : public Primitive
/** Where the vector is held */
double *_v;

/** _v with nans removed **/
double *_v_no_nans;
bool _v_no_nans_dirty : 1;
int _v_no_nans_size;

/** number of samples shifted since last newSync */
int NumShifted;

Expand All @@ -205,6 +212,9 @@ class KSTCORE_EXPORT Vector : public Primitive
/** is the vector monotonically rising */
bool _is_rising : 1;

/** the vector has at least one NaN */
bool _has_nan : 1;

/** if true then we have a scalar list and do not want to be able to
use it in a curve, display statistics for it, etc. */
bool _isScalarList : 1;
Expand Down Expand Up @@ -232,13 +242,14 @@ class KSTCORE_EXPORT Vector : public Primitive

friend class DataObject;
friend class Matrix;
virtual double* realloced(double *memptr, int newSize);
//virtual double* realloced(double *memptr, int newSize);
virtual void setV(double *memptr, int newSize);

ObjectMap<Scalar> _scalars;
ObjectMap<String> _strings;


private:
void updateVNoNans();
};


Expand Down
3 changes: 0 additions & 3 deletions src/libkstapp/csddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ void CSDTab::clearTabValues() {
_vector->clearSelection();
_windowSize->clear();
_FFTOptions->clearValues();
_FFTOptions->disableInterpolateOverHoles();
}


Expand All @@ -140,8 +139,6 @@ CSDDialog::CSDDialog(ObjectPtr dataObject, QWidget *parent)
configureTab(dataObject);
}

_CSDTab->FFTOptionsWidget()->disableInterpolateOverHoles();

connect(_CSDTab, SIGNAL(optionsChanged()), this, SLOT(updateButtons()));
connect(this, SIGNAL(editMultipleMode()), this, SLOT(editMultipleMode()));
connect(this, SIGNAL(editSingleMode()), this, SLOT(editSingleMode()));
Expand Down
3 changes: 1 addition & 2 deletions src/libkstapp/datawizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1219,8 +1219,7 @@ void DataWizard::finished() {
_pageDataPresentation->getFFTOptions()->rateUnits(),
_pageDataPresentation->getFFTOptions()->apodizeFunction(),
_pageDataPresentation->getFFTOptions()->sigma(),
_pageDataPresentation->getFFTOptions()->output(),
_pageDataPresentation->getFFTOptions()->interpolateOverHoles());
_pageDataPresentation->getFFTOptions()->output());

powerspectrum->registerChange();
powerspectrum->unlock();
Expand Down
7 changes: 1 addition & 6 deletions src/libkstapp/powerspectrumdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ void PowerSpectrumDialog::configureTab(ObjectPtr object) {
_powerSpectrumTab->FFTOptionsWidget()->setApodizeFunction(psd->apodizeFxn());
_powerSpectrumTab->FFTOptionsWidget()->setSigma(psd->gaussianSigma());
_powerSpectrumTab->FFTOptionsWidget()->setOutput(psd->output());
_powerSpectrumTab->FFTOptionsWidget()->setInterpolateOverHoles(psd->interpolateHoles());
_powerSpectrumTab->hideCurveOptions();
if (_editMultipleWidget) {
PSDList objects = _document->objectStore()->getObjects<PSD>();
Expand Down Expand Up @@ -215,8 +214,7 @@ ObjectPtr PowerSpectrumDialog::createNewDataObject() {
_powerSpectrumTab->FFTOptionsWidget()->rateUnits(),
_powerSpectrumTab->FFTOptionsWidget()->apodizeFunction(),
_powerSpectrumTab->FFTOptionsWidget()->sigma(),
_powerSpectrumTab->FFTOptionsWidget()->output(),
_powerSpectrumTab->FFTOptionsWidget()->interpolateOverHoles());
_powerSpectrumTab->FFTOptionsWidget()->output());

if (DataDialog::tagStringAuto()) {
powerspectrum->setDescriptiveName(QString());
Expand Down Expand Up @@ -315,7 +313,6 @@ ObjectPtr PowerSpectrumDialog::editExistingDataObject() const {

const bool apodize = options->apodizeDirty() ? options->apodize() : powerspectrum->apodize();
const bool removeMean = options->removeMeanDirty() ? options->removeMean() : powerspectrum->removeMean();
const bool interpolateOverHoles = options->interpolateOverHolesDirty() ? options->interpolateOverHoles() : powerspectrum->interpolateHoles();
const bool interleavedAverage = options->interleavedAverageDirty() ? options->interleavedAverage() : powerspectrum->average();
const int FFTLength = options->FFTLengthDirty() ? options->FFTLength() : powerspectrum->length();
const ApodizeFunction apodizeFunction = options->apodizeFunctionDirty() ? options->apodizeFunction() : powerspectrum->apodizeFxn();
Expand All @@ -335,7 +332,6 @@ ObjectPtr PowerSpectrumDialog::editExistingDataObject() const {
powerspectrum->setApodizeFxn(apodizeFunction);
powerspectrum->setGaussianSigma(sigma);
powerspectrum->setOutput(output);
powerspectrum->setInterpolateHoles(interpolateOverHoles);

powerspectrum->registerChange();
powerspectrum->unlock();
Expand All @@ -354,7 +350,6 @@ ObjectPtr PowerSpectrumDialog::editExistingDataObject() const {
powerspectrum->setApodizeFxn(_powerSpectrumTab->FFTOptionsWidget()->apodizeFunction());
powerspectrum->setGaussianSigma(_powerSpectrumTab->FFTOptionsWidget()->sigma());
powerspectrum->setOutput(_powerSpectrumTab->FFTOptionsWidget()->output());
powerspectrum->setInterpolateHoles(_powerSpectrumTab->FFTOptionsWidget()->interpolateOverHoles());
if (DataDialog::tagStringAuto()) {
powerspectrum->setDescriptiveName(QString());
} else {
Expand Down
Loading