20 changes: 2 additions & 18 deletions src/libkstmath/psd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ ScriptInterface* PSD::createScriptInterface() {
void PSD::change(VectorPtr in_V,
double in_freq, bool in_average, int in_averageLen, bool in_apodize,
bool in_removeMean, const QString& in_VUnits, const QString& in_RUnits,
ApodizeFunction in_apodizeFxn, double in_gaussianSigma, PSDType in_output,
bool interpolateHoles) {
ApodizeFunction in_apodizeFxn, double in_gaussianSigma, PSDType in_output) {

if (in_V) {
_inputVectors[INVECTOR] = in_V;
Expand All @@ -105,7 +104,6 @@ void PSD::change(VectorPtr in_V,
_vectorUnits = in_VUnits;
_rateUnits = in_RUnits;
_Output = in_output;
_interpolateHoles = interpolateHoles;
_averageLength = in_averageLen;

_last_n_subsets = 0;
Expand Down Expand Up @@ -174,7 +172,7 @@ void PSD::internalUpdate() {
}
//f[0] = -1E-280; // really 0 (this shouldn't be needed...)

_psdCalculator.calculatePowerSpectrum(iv->value(), v_len, psd, _PSDLength, _RemoveMean, _interpolateHoles, _Average, _averageLength, _Apodize, _apodizeFxn, _gaussianSigma, _Output, _Frequency);
_psdCalculator.calculatePowerSpectrum(iv->noNanValue(), v_len, psd, _PSDLength, _RemoveMean, _Average, _averageLength, _Apodize, _apodizeFxn, _gaussianSigma, _Output, _Frequency);

_last_n_subsets = n_subsets;
_last_n_new = 0;
Expand Down Expand Up @@ -221,7 +219,6 @@ void PSD::save(QXmlStreamWriter &s) {
s.writeAttribute("removemean", QVariant(_RemoveMean).toString());
s.writeAttribute("apodize", QVariant(_Apodize).toString());
s.writeAttribute("apodizefunction", QString::number(_apodizeFxn));
s.writeAttribute("interpolateholes", QVariant(_interpolateHoles).toString());
s.writeAttribute("vectorunits", _vectorUnits);
s.writeAttribute("rateunits", _rateUnits);
s.writeAttribute("outputtype", QString::number(_Output));
Expand Down Expand Up @@ -411,7 +408,6 @@ DataObjectPtr PSD::makeDuplicate() const {
powerspectrum->setApodizeFxn(_apodizeFxn);
powerspectrum->setGaussianSigma(_gaussianSigma);
powerspectrum->setOutput(_Output);
powerspectrum->setInterpolateHoles(_interpolateHoles);
if (descriptiveNameIsManual()) {
powerspectrum->setDescriptiveName(descriptiveName());
}
Expand All @@ -422,18 +418,6 @@ DataObjectPtr PSD::makeDuplicate() const {
}


bool PSD::interpolateHoles() const {
return _interpolateHoles;
}


void PSD::setInterpolateHoles(bool interpolate) {
if (interpolate != _interpolateHoles) {
_interpolateHoles = interpolate;
}
_changed = true;
}

void PSD::updateVectorLabels() {
LabelInfo label_info;

Expand Down
6 changes: 1 addition & 5 deletions src/libkstmath/psd.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ class KSTMATH_EXPORT PSD : public DataObject {
PSDType output() const;
void setOutput(PSDType in_output);

bool interpolateHoles() const;
void setInterpolateHoles(bool interpolate);

virtual bool slaveVectorsUsed() const;

virtual void showNewDialog();
Expand All @@ -94,7 +91,7 @@ class KSTMATH_EXPORT PSD : public DataObject {
void change(VectorPtr in_V,
double freq, bool average, int average_len, bool apodize, bool removeMean,
const QString& VUnits, const QString& RUnits, ApodizeFunction in_apodizeFxn = WindowOriginal,
double in_gaussianSigma = 3.0, PSDType in_output = PSDAmplitudeSpectralDensity, bool interpolateHoles = false);
double in_gaussianSigma = 3.0, PSDType in_output = PSDAmplitudeSpectralDensity);
virtual void internalUpdate();

void setChanged() { _changed=true;}
Expand All @@ -120,7 +117,6 @@ class KSTMATH_EXPORT PSD : public DataObject {
bool _Apodize;
bool _RemoveMean;
bool _Average;
bool _interpolateHoles;
PSDType _Output;
PSDType _prevOutput;
int _last_n_subsets;
Expand Down
20 changes: 2 additions & 18 deletions src/libkstmath/psdcalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void PSDCalculator::updateWindowFxn(ApodizeFunction apodizeFxn, double gaussianS
int PSDCalculator::calculatePowerSpectrum(
double *input, int inputLen,
double *output, int outputLen,
bool removeMean, bool interpolateHoles,
bool removeMean,
bool average, int averageLen,
bool apodize, ApodizeFunction apodizeFxn, double gaussianSigma,
PSDType outputType, double inputSamplingFreq) {
Expand Down Expand Up @@ -225,22 +225,10 @@ int PSDCalculator::calculatePowerSpectrum(

// apply the PSD options (removeMean, apodize, etc.)
// separate cases for speed- although this shouldn't really matter- the rdft should be the most time consuming step by far for any large data set.
if (removeMean && apodize && interpolateHoles) {
for (i_samp = 0; i_samp < currentCopyLen; ++i_samp) {
_a[i_samp] = (Kst::kstInterpolateNoHoles(input, inputLen, i_samp + ioffset, inputLen) - mean)*_w[i_samp];
}
} else if (removeMean && apodize) {
if (removeMean && apodize) {
for (i_samp = 0; i_samp < currentCopyLen; ++i_samp) {
_a[i_samp] = (input[i_samp + ioffset] - mean)*_w[i_samp];
}
} else if (removeMean && interpolateHoles) {
for (i_samp = 0; i_samp < currentCopyLen; ++i_samp) {
_a[i_samp] = Kst::kstInterpolateNoHoles(input, inputLen, i_samp + ioffset, inputLen) - mean;
}
} else if (apodize && interpolateHoles) {
for (i_samp = 0; i_samp < currentCopyLen; ++i_samp) {
_a[i_samp] = Kst::kstInterpolateNoHoles(input, inputLen, i_samp + ioffset, inputLen)*_w[i_samp];
}
} else if (removeMean) {
for (i_samp = 0; i_samp < currentCopyLen; ++i_samp) {
_a[i_samp] = input[i_samp + ioffset] - mean;
Expand All @@ -249,10 +237,6 @@ int PSDCalculator::calculatePowerSpectrum(
for (i_samp = 0; i_samp < currentCopyLen; ++i_samp) {
_a[i_samp] = input[i_samp + ioffset]*_w[i_samp];
}
} else if (interpolateHoles) {
for (i_samp = 0; i_samp < currentCopyLen; ++i_samp) {
_a[i_samp] = Kst::kstInterpolateNoHoles(input, inputLen, i_samp + ioffset, inputLen);
}
} else {
for (i_samp = 0; i_samp < currentCopyLen; ++i_samp) {
_a[i_samp] = input[i_samp + ioffset];
Expand Down
2 changes: 1 addition & 1 deletion src/libkstmath/psdcalculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PSDCalculator {
PSDCalculator();
~PSDCalculator();

int calculatePowerSpectrum(double *input, int inputLen, double *output, int outputLen, bool removeMean, bool interpolateHoles, bool average, int averageLen, bool apodize, ApodizeFunction apodizeFxn, double gaussianSigma, PSDType outputType, double inputSamplingFreq);
int calculatePowerSpectrum(double *input, int inputLen, double *output, int outputLen, bool removeMean, bool average, int averageLen, bool apodize, ApodizeFunction apodizeFxn, double gaussianSigma, PSDType outputType, double inputSamplingFreq);

static int calculateOutputVectorLength(int inputLen, bool average, int averageLen);

Expand Down
5 changes: 2 additions & 3 deletions src/libkstmath/psdfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ DataObjectPtr PSDFactory::generateObject(ObjectStore *store, QXmlStreamReader& x
double frequency=1.0, gaussianSigma=1.0;
int length=8, apodizeFunction=0, outputType=0;
QString vectorName, vectorUnits, rateUnits, descriptiveName;
bool average=false, removeMean=false, apodize=false, interpolateHoles=false;
bool average=false, removeMean=false, apodize=false;

while (!xml.atEnd()) {
const QString n = xml.name().toString();
Expand All @@ -54,7 +54,6 @@ DataObjectPtr PSDFactory::generateObject(ObjectStore *store, QXmlStreamReader& x
outputType = attrs.value("outputtype").toString().toInt();

average = attrs.value("average").toString() == "true" ? true : false;
interpolateHoles = attrs.value("interpolateholes").toString() == "true" ? true : false;
removeMean = attrs.value("removemean").toString() == "true" ? true : false;
apodize = attrs.value("apodize").toString() == "true" ? true : false;
if (attrs.value("descriptiveNameIsManual").toString() == "true") {
Expand Down Expand Up @@ -97,7 +96,7 @@ DataObjectPtr PSDFactory::generateObject(ObjectStore *store, QXmlStreamReader& x
powerspectrum->change(vector, frequency,
average, length, apodize, removeMean,
vectorUnits, rateUnits, (ApodizeFunction)apodizeFunction,
gaussianSigma, (PSDType)outputType, interpolateHoles);
gaussianSigma, (PSDType)outputType);

powerspectrum->setDescriptiveName(descriptiveName);

Expand Down
8 changes: 4 additions & 4 deletions src/plugins/dataobject/convolution/convolve/convolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,22 @@ bool ConvolveSource::algorithm() {
memset( pdResponse, 0, iLength * sizeof( double ) );

for (int i = 0; i < iResponseMidpoint; i++) {
pdResponse[i] = response->value()[iResponseMidpoint+i];
pdResponse[iLength-iResponseMidpoint+i] = response->value()[i];
pdResponse[i] = response->noNanValue()[iResponseMidpoint+i];
pdResponse[iLength-iResponseMidpoint+i] = response->noNanValue()[i];
}

//
// handle the case where the response function has an odd number of points...
//
if (iResponseMidpoint % 2 == 1) {
pdResponse[iResponseMidpoint] = response->value()[response->length()-1];
pdResponse[iResponseMidpoint] = response->noNanValue()[response->length()-1];
}

//
// zero-pad the convolve array...
//
memset( pdConvolve, 0, iLength * sizeof( double ) );
memcpy( pdConvolve, convolve->value(), convolve->length() * sizeof( double ) );
memcpy( pdConvolve, convolve->noNanValue(), convolve->length() * sizeof( double ) );

//
// calculate the FFTs of the two functions...
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/dataobject/convolution/deconvolve/deconvolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,23 @@ bool DeconvolveSource::algorithm() {
memset( pdResponse, 0, iLength * sizeof( double ) );

for ( int i=0; i < iResponseMidpoint; i++) {
pdResponse[i] = response->value()[iResponseMidpoint+i];
pdResponse[iLength-iResponseMidpoint+i] = response->value()[i];
pdResponse[i] = response->noNanValue()[iResponseMidpoint+i];
pdResponse[iLength-iResponseMidpoint+i] = response->noNanValue()[i];
}

//
// handle the case where the response function has an odd number of points...
//
if (iResponseMidpoint % 2 == 1) {
pdResponse[iResponseMidpoint] = response->value()[response->length()];
pdResponse[iResponseMidpoint] = response->noNanValue()[response->length()];

}

//
// zero-pad the convolve array...
//
memset( pdConvolve, 0, iLength * sizeof( double ) );
memcpy( pdConvolve, deconvolve->value(), deconvolve->length() * sizeof( double ) );
memcpy( pdConvolve, deconvolve->noNanValue(), deconvolve->length() * sizeof( double ) );

//
// calculate the FFTs of the two functions...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ bool AutoCorrelationSource::algorithm() {
// zero-pad the two arrays...
//
memset( pdArrayOne, 0, iLength * sizeof( double ) );
memcpy( pdArrayOne, inputVector->value(), inputVector->length() * sizeof( double ) );
memcpy( pdArrayOne, inputVector->noNanValue(), inputVector->length() * sizeof( double ) );

//
// calculate the FFTs of the two functions...
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/dataobject/crossspectrum/crossspectrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ bool CrossSpectrumSource::algorithm() {
for (i_samp = 0; i_samp < copyLen; ++i_samp) {
i = ( i_samp + i_subset*xps_len )/dv0;
mean_a += (
a[i_samp] = inputVectorOne->value()[i]
a[i_samp] = inputVectorOne->noNanValue()[i]
);
i = ( i_samp + i_subset*xps_len )/dv1;
mean_b += (
b[i_samp] = inputVectorTwo->value()[i]
b[i_samp] = inputVectorTwo->noNanValue()[i]
);
}
if (copyLen>1) {
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/dataobject/genericfilter/genericfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,13 @@ bool GenericFilterSource::algorithm() {
double in = 0.0;
theFilter.ConnectTo(in); // the filter keeps a pointer to "in"
theFilter.Reset();

double *v_in = inputVector->noNanValue();
double *v_out = outputVector->value();
for (int i=0; i<length; i++) {
in = inputVector->value()[i];
in = v_in[i];
theFilter.NextTimeStep();
outputVector->value()[i] = theFilter.out;
v_out[i] = theFilter.out;
}

return true;
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/dataobject/interpolations/interpolations.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ bool interpolate(Kst::VectorPtr xVector,
if (pAccel != NULL) {
pSpline = gsl_spline_alloc( pType, iLengthData );
if (pSpline != NULL) {
if (!gsl_spline_init( pSpline, xVector->value(), yVector->value(), iLengthData )) {
if (!gsl_spline_init( pSpline, xVector->noNanValue(), yVector->noNanValue(), iLengthData )) {
double *xV1 = x1Vector->noNanValue();
double *yVout = yOutVector->value();
for( int i=0; i<iLengthInterp; i++) {
yOutVector->value()[i] = gsl_spline_eval( pSpline, x1Vector->value()[i], pAccel );
yVout[i] = gsl_spline_eval( pSpline, xV1[i], pAccel );
}

bReturn = true;
Expand Down
35 changes: 20 additions & 15 deletions src/plugins/dataobject/linefit/linefit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,17 @@ bool LineFitSource::algorithm() {
outputVectorX->resize( 2, false );
outputVectorY->resize( 2, false );

double* vX_in = inputVectorX->noNanValue();
double* vY_in = inputVectorY->noNanValue();
double* vX_out = outputVectorX->value();
double* vY_out = outputVectorY->value();

if (inputVectorY->length() == 1) {
outputVectorX->value()[0] = inputVectorX->value()[0];
outputVectorX->value()[1] = inputVectorX->value()[inputVectorX->length() - 1];
outputVectorY->value()[0] = inputVectorY->value()[0];
outputVectorY->value()[1] = inputVectorY->value()[0];
outputScalarA->setValue( inputVectorY->value()[0] );
vX_out[0] = vX_in[0];
vX_out[1] = vX_in[inputVectorX->length() - 1];
vY_out[0] = vY_in[0];
vY_out[1] = vY_in[0];
outputScalarA->setValue( vY_in[0] );
outputScalarB->setValue( 0 );
outputScalarChi->setValue( chi2 );
return true;
Expand All @@ -190,30 +195,30 @@ bool LineFitSource::algorithm() {
long int idx = long(Kst::roundDouble(z));
double skew = z - floor(z); /* [0..1] */
long int idx2 = idx + 1;
sy += inputVectorY->value()[i];
sy += vY_in[i];
while (idx2 >= inputVectorY->length()) {
idx2--;
}
sx += inputVectorX->value()[idx] + (inputVectorX->value()[idx2] - inputVectorX->value()[idx])*skew;
sx += vX_in[idx] + (vX_in[idx2] - vX_in[idx])*skew;
}

sxoss = sx / inputVectorX->length();

for (i = 0; i < inputVectorX->length(); ++i) {
double t = inputVectorX->value()[i] - sxoss;
double t = vX_in[i] - sxoss;
st2 += t * t;
b += t * inputVectorY->value()[i];
b += t * vY_in[i];
}

b /= st2;
a = (sy - sx*b)/inputVectorX->length();

/* could put goodness of fit, etc, in here */

outputVectorX->value()[0] = inputVectorX->value()[0];
outputVectorX->value()[1] = inputVectorX->value()[inputVectorX->length()-1];
outputVectorY->value()[0] = a+b*outputVectorX->value()[0];
outputVectorY->value()[1] = a+b*outputVectorX->value()[1];
vX_out[0] = vX_in[0];
vX_out[1] = vX_in[inputVectorX->length()-1];
vY_out[0] = a+b*vX_out[0];
vY_out[1] = a+b*vX_out[1];

for (i = 0; i < inputVectorX->length(); ++i) {
double z = xScale*i;
Expand All @@ -225,8 +230,8 @@ bool LineFitSource::algorithm() {
while (idx2 >= inputVectorX->length()) {
idx2--;
}
newX = inputVectorX->value()[idx] + (inputVectorX->value()[idx2] - inputVectorX->value()[idx])*skew;
ci = inputVectorY->value()[i] - a - b*newX;
newX = vX_in[idx] + (vX_in[idx2] - vX_in[idx])*skew;
ci = vY_in[i] - a - b*newX;
chi2 += ci*ci;
}

Expand Down
6 changes: 4 additions & 2 deletions src/plugins/filters/cumulativeaverage/cumulativeaverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,12 @@ bool CumulativeAverageSource::algorithm() {
/* Memory allocation */
outputVector->resize(inputVector->length(), true);

outputVector->value()[0] = inputVector->value()[0]; // i = 1
double *v_in = inputVector->noNanValue();
double *v_out = outputVector->value();
v_out[0] = v_in[0]; // i = 1

for (int i = 1; i < inputVector->length(); ++i) {
outputVector->value()[i] = (inputVector->value()[i] + (i * outputVector->value()[i-1])) / (i+1);
v_out[i] = (v_in[i] + (i * v_out[i-1])) / (i+1);
}

return true;
Expand Down
11 changes: 8 additions & 3 deletions src/plugins/filters/cumulativesum/cumulativesum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,15 @@ bool CumulativeSumSource::algorithm() {
/* Memory allocation */
outputVector->resize(inputVector->length(), true);

outputVector->value()[0] = inputVector->value()[0];
double *v_in = inputVector->noNanValue();
double *v_out = outputVector->value();
double s_in = inputScalar->value();
int len = inputVector->length();

for (int i = 1; i < inputVector->length(); i++) {
outputVector->value()[i] = inputVector->value()[i]*inputScalar->value() + outputVector->value()[i-1];
v_out[0] = v_in[0];

for (int i = 1; i < len; i++) {
v_out[i] = v_in[i]*s_in + v_out[i-1];
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/filters/filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ bool kst_pass_filter(
if( real != NULL ) {
work = gsl_fft_real_workspace_alloc( iLengthDataPadded );
if( work != NULL ) {
memcpy( pPadded, vector->value(), iLengthData * sizeof( double ) );
memcpy( pPadded, vector->noNanValue(), iLengthData * sizeof( double ) );

// We are going to do a cubic spline extrapolation on the data
// to improve behavior for high pass filters.
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/filters/unwind/filterunwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ bool FilterUnwindSource::algorithm() {
step *= (max-min)/100.0;


last_x_in = inputVector->value(0);
last_x_in = inputVector->noNanValue(0);
outputVector->value()[0] = last_x_in;

for (i=1; i<N; ++i) {
x = inputVector->value(i);
x = inputVector->noNanValue(i);
if ((x>max) || (x<min)) { // invalid/spike... ignore.
x = last_x_in;
}
Expand Down
12 changes: 8 additions & 4 deletions src/plugins/fits/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,28 @@ bool precursor( Kst::VectorPtr xVector, Kst::VectorPtr yVector, Kst::VectorPtr w
// do any necessary interpolations...
//
pInputs[XVALUES] = (double*)malloc(*piLength * sizeof( double ));

double *v_x = xVector->noNanValue();
double *v_y = yVector->noNanValue();

if (xVector->length() == *piLength) {
for( i=0; i<*piLength; i++) {
pInputs[XVALUES][i] = xVector->value()[i];
pInputs[XVALUES][i] = v_x[i];
}
} else {
for( i=0; i<*piLength; i++) {
pInputs[XVALUES][i] = interpolate( i, *piLength, xVector->value(), xVector->length() );
pInputs[XVALUES][i] = interpolate( i, *piLength, v_x, xVector->length() );
}
}

pInputs[YVALUES] = (double*)malloc(*piLength * sizeof( double ));
if (yVector->length() == *piLength) {
for( i=0; i<*piLength; i++) {
pInputs[YVALUES][i] = yVector->value()[i];
pInputs[YVALUES][i] = v_y[i];
}
} else {
for( i=0; i<*piLength; i++) {
pInputs[YVALUES][i] = interpolate( i, *piLength, yVector->value(), yVector->length() );
pInputs[YVALUES][i] = interpolate( i, *piLength, v_y, yVector->length() );
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/plugins/fits/linear.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ bool kstfit_linear_unweighted(
// fill in the matrices and vectors...
//
for( i=0; i<iLength; i++ ) {
gsl_vector_set( pVectorY, i, interpolate(i, iLength, yVector->value(), yVector->length()));
dXInterpolated = interpolate(i, iLength, xVector->value(), xVector->length());
gsl_vector_set( pVectorY, i, interpolate(i, iLength, yVector->noNanValue(), yVector->length()));
dXInterpolated = interpolate(i, iLength, xVector->noNanValue(), xVector->length());
for( j=0; j<iNumParams; j++ ) {
dX = calculate_matrix_entry( dXInterpolated, j );
gsl_matrix_set( pMatrixX, i, j, dX );
Expand All @@ -99,7 +99,7 @@ bool kstfit_linear_unweighted(
gsl_vector_get( pVectorParameters, j );
}
vectorOutYFitted->value()[i] = dY;
vectorOutYResiduals->value()[i] = interpolate(i, iLength, yVector->value(), yVector->length()) - dY;
vectorOutYResiduals->value()[i] = interpolate(i, iLength, yVector->noNanValue(), yVector->length()) - dY;
}

for( i=0; i<iNumParams; i++ ) {
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/fits/linear_weighted.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ bool kstfit_linear_weighted(
// fill in the matrices and vectors...
//
for( i=0; i<iLength; i++ ) {
gsl_vector_set( pVectorY, i, interpolate(i, iLength, yVector->value(), yVector->length()));
gsl_vector_set( pVectorWeights, i, interpolate(i, iLength, weightsVector->value(), weightsVector->length()));
gsl_vector_set( pVectorY, i, interpolate(i, iLength, yVector->noNanValue(), yVector->length()));
gsl_vector_set( pVectorWeights, i, interpolate(i, iLength, weightsVector->noNanValue(), weightsVector->length()));
for( j=0; j<iNumParams; j++ ) {
dX = calculate_matrix_entry( interpolate(i, iLength, xVector->value(), xVector->length()), j );
dX = calculate_matrix_entry( interpolate(i, iLength, xVector->noNanValue(), xVector->length()), j );
gsl_matrix_set( pMatrixX, i, j, dX );
}
}
Expand All @@ -102,7 +102,7 @@ bool kstfit_linear_weighted(
gsl_vector_get( pVectorParameters, j );
}
vectorOutYFitted->value()[i] = dY;
vectorOutYResiduals->value()[i] = interpolate(i, iLength, yVector->value(), yVector->length()) - dY;
vectorOutYResiduals->value()[i] = interpolate(i, iLength, yVector->noNanValue(), yVector->length()) - dY;
}

for( i=0; i<iNumParams; i++ ) {
Expand Down
12 changes: 8 additions & 4 deletions src/plugins/fits/non_linear.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,28 @@ bool kstfit_nonlinear(
}

pInputX = (double*)malloc(iLength * sizeof( double ));

double *v_x = xVector->noNanValue();
double *v_y = yVector->noNanValue();

if (xVector->length() == iLength) {
for( i=0; i<iLength; i++) {
pInputX[i] = xVector->value()[i];
pInputX[i] = v_x[i];
}
} else {
for( i=0; i<iLength; i++) {
pInputX[i] = interpolate( i, iLength, xVector->value(), xVector->length() );
pInputX[i] = interpolate( i, iLength, v_x, xVector->length() );
}
}

pInputY = (double*)malloc(iLength * sizeof( double ));
if (yVector->length() == iLength) {
for( i=0; i<iLength; i++) {
pInputY[i] = yVector->value()[i];
pInputY[i] = v_y[i];
}
} else {
for( i=0; i<iLength; i++) {
pInputY[i] = interpolate( i, iLength, yVector->value(), yVector->length() );
pInputY[i] = interpolate( i, iLength, v_y, yVector->length() );
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/plugins/fits/non_linear_weighted.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,24 +121,28 @@ bool kstfit_nonlinear_weighted(

// do any necessary interpolation...
pInputs[XVALUES] = (double*)malloc(iLength * sizeof( double ));

double *v_x = xVector->noNanValue();
double *v_y = yVector->noNanValue();

if (xVector->length() == iLength) {
for( i=0; i<iLength; i++) {
pInputs[XVALUES][i] = xVector->value()[i];
pInputs[XVALUES][i] = v_x[i];
}
} else {
for( i=0; i<iLength; i++) {
pInputs[XVALUES][i] = interpolate( i, iLength, xVector->value(), xVector->length() );
pInputs[XVALUES][i] = interpolate( i, iLength, v_x, xVector->length() );
}
}

pInputs[YVALUES] = (double*)malloc(iLength * sizeof( double ));
if (yVector->length() == iLength) {
for( i=0; i<iLength; i++) {
pInputs[YVALUES][i] = yVector->value()[i];
pInputs[YVALUES][i] = v_y[i];
}
} else {
for( i=0; i<iLength; i++) {
pInputs[YVALUES][i] = interpolate( i, iLength, yVector->value(), yVector->length() );
pInputs[YVALUES][i] = interpolate( i, iLength, v_y, yVector->length() );
}
}

Expand Down
26 changes: 0 additions & 26 deletions src/widgets/fftoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ FFTOptions::FFTOptions(QWidget *parent)
connect(_apodize, SIGNAL(clicked()), this, SIGNAL(modified()));
connect(_removeMean, SIGNAL(clicked()), this, SIGNAL(modified()));
connect(_interleavedAverage, SIGNAL(clicked()), this, SIGNAL(modified()));
connect(_interpolateOverHoles, SIGNAL(clicked()), this, SIGNAL(modified()));
connect(_sampleRate, SIGNAL(textChanged(QString)), this, SIGNAL(modified()));
connect(_vectorUnits, SIGNAL(textChanged(QString)), this, SIGNAL(modified()));
connect(_rateUnits, SIGNAL(textChanged(QString)), this, SIGNAL(modified()));
Expand All @@ -46,7 +45,6 @@ FFTOptions::FFTOptions(QWidget *parent)
_removeMean->setProperty("si","Remo&ve mean");
_FFTLengthLabel->setProperty("si","FFT &length: 2^");
_interleavedAverage->setProperty("si","Interleave&d average");
_interpolateOverHoles->setProperty("si","Interpolate over &holes");
TextLabel1_9_2->setProperty("si","Sa&mple rate:");
TextLabel1_9_3->setProperty("si","Vector units:");
TextLabel1_9_2_2->setProperty("si","Rate units:");
Expand Down Expand Up @@ -138,21 +136,6 @@ void FFTOptions::setRemoveMean(const bool removeMean) {
}


bool FFTOptions::interpolateOverHoles() const {
return _interpolateOverHoles->isChecked();
}


bool FFTOptions::interpolateOverHolesDirty() const {
return _interpolateOverHoles->checkState() == Qt::PartiallyChecked;
}


void FFTOptions::setInterpolateOverHoles(const bool interpolateOverHoles) {
_interpolateOverHoles->setChecked(interpolateOverHoles);
}


int FFTOptions::FFTLength() const {
return _FFTLength->value();
}
Expand Down Expand Up @@ -237,18 +220,11 @@ void FFTOptions::clearValues() {
_apodize->setCheckState(Qt::PartiallyChecked);
_interleavedAverage->setCheckState(Qt::PartiallyChecked);
_removeMean->setCheckState(Qt::PartiallyChecked);
_interpolateOverHoles->setCheckState(Qt::PartiallyChecked);
_apodizeFunction->setCurrentIndex(-1);
_output->setCurrentIndex(-1);
}


void FFTOptions::disableInterpolateOverHoles() {
_interpolateOverHoles->setChecked(false);
_interpolateOverHoles->setEnabled(false);
}


void FFTOptions::changedApodizeFxn() {
int gaussianIndex = 5;
if (_apodizeFunction->itemText(0).isEmpty()) {
Expand Down Expand Up @@ -305,7 +281,6 @@ void FFTOptions::setWidgetDefaults() {
dialogDefaults().setValue("spectrum/apodizeFxn", apodizeFunction());
dialogDefaults().setValue("spectrum/gaussianSigma", sigma());
dialogDefaults().setValue("spectrum/output", output());
dialogDefaults().setValue("spectrum/interpolateHoles", interpolateOverHoles());
}

// set the widget to the stored default values
Expand All @@ -320,7 +295,6 @@ void FFTOptions::loadWidgetDefaults() {
setApodizeFunction(ApodizeFunction(dialogDefaults().value("spectrum/apodizeFxn",WindowOriginal).toInt()));
setSigma(dialogDefaults().value("spectrum/gaussianSigma",1.0).toDouble());
setOutput(PSDType(dialogDefaults().value("spectrum/output",PSDPowerSpectralDensity).toInt()));
setInterpolateOverHoles(dialogDefaults().value("spectrum/interpolateHoles",true).toInt());
}

}
Expand Down
5 changes: 0 additions & 5 deletions src/widgets/fftoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ class KSTWIDGETS_EXPORT FFTOptions : public QWidget, public Ui::FFTOptions
bool outputDirty() const;
void setOutput(const PSDType output);

bool interpolateOverHoles() const;
bool interpolateOverHolesDirty() const;
void setInterpolateOverHoles(const bool interpolateOverHoles);

void disableInterpolateOverHoles();
void clearValues();

void setWidgetDefaults();
Expand Down
66 changes: 50 additions & 16 deletions src/widgets/fftoptions.ui
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
Expand All @@ -31,7 +40,16 @@
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QGridLayout">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="3">
Expand Down Expand Up @@ -167,7 +185,16 @@
</item>
<item row="1" column="0">
<layout class="QGridLayout">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="2">
Expand Down Expand Up @@ -218,21 +245,20 @@
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QCheckBox" name="_interpolateOverHoles">
<property name="text">
<string>Interpolate over &amp;holes</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand Down Expand Up @@ -338,7 +364,16 @@
</item>
<item row="3" column="0">
<layout class="QHBoxLayout">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand Down Expand Up @@ -399,7 +434,6 @@
<tabstop>_sigma</tabstop>
<tabstop>_interleavedAverage</tabstop>
<tabstop>_FFTLength</tabstop>
<tabstop>_interpolateOverHoles</tabstop>
<tabstop>_sampleRate</tabstop>
<tabstop>_vectorUnits</tabstop>
<tabstop>_rateUnits</tabstop>
Expand Down
21 changes: 18 additions & 3 deletions tests/dirfile_maker/dirfile_maker.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ struct DFEntryType {
char type;
};

#define NDF 15
#define NDF 16
#define SCOUNT 0
#define FCOUNT 1
#define SINE 2
#define SSINE 3
#define COS 4
#define TIME 5
#define EXTRA 6
#define HASNANS 6
#define EXTRA 7

struct DFEntryType df[NDF] = {
{"scount", 1, -1, 'f'},
Expand All @@ -31,6 +32,7 @@ struct DFEntryType df[NDF] = {
{"ssine", 1, -1, 'f'},
{"cos", 20, -1, 'f'},
{"time", 20, -1, 'd'},
{"hasnans", 20, -1, 'f'},
{"E0", 20, -1, 'f'},
{"E1", 20, -1, 'f'},
{"E2", 20, -1, 'f'},
Expand Down Expand Up @@ -146,7 +148,20 @@ int main() {
}

}


/* write 'hasnans' */
for (i=0; i<df[HASNANS].spf; i++) {
dx = count*df[HASNANS].spf+i;
x = (double)rand()/(double)RAND_MAX;
if (x<0.01) {
x = NAN;
}
nw = write(df[HASNANS].fp, &x, sizeof(float));
if (nw<0) {
fprintf(stderr, "error writing cos\n");
}
}

/* write extras */
for (j=6; j<NDF; j++) {
for (i=0; i<df[j].spf; i++) {
Expand Down