QString SpectrumSI::change(QString& command) {
  if (_psd) {
    QStringList vars = getArgs(command);

    QString vec_name = vars.at(0);
    VectorPtr vector = kst_cast<Vector>(_dataObject->store()->retrieveObject(vec_name));


    _psd->change(vector,
                 vars.at(1).toDouble(),            // sample_rate
                 (vars.at(2).toLower() == "true"), // interleaved_average,
                 vars.at(3).toInt(),               // fft_length,
                 (vars.at(4).toLower() == "true"), // apodize,
                 (vars.at(5).toLower() == "true"), // remove_mean,
                 vars.at(6),                       // vector unints
                 vars.at(7),                       // rate units
                 ApodizeFunction(vars.at(8).toInt()), // apodizeFunction,
                 vars.at(9).toDouble(),            // sigma,
                 PSDType(vars.at(10).toInt())     // output type
                 );
    
    
    return "done";
  } else {
    return "Invalid";
  }
}
示例#2
0
KstCSD::KstCSD(const QDomElement &e)
: KstDataObject(e) {
  
    QString in_tag;
    QString vecName;
    QString in_vectorUnits, in_rateUnits;
    KstVectorPtr in_V;
    double in_freq = 60.0;
    bool in_average = true;
    int in_averageLength = 8;
    bool in_removeMean = true;
    bool in_apodize = true;
    ApodizeFunction in_apodizeFxn = WindowOriginal;
    int in_windowSize = 5000;
    double in_gaussianSigma = 3.0;
    PSDType in_outputType = PSDAmplitudeSpectralDensity;
    
    QDomNode n = e.firstChild();
    while (!n.isNull()) {
      QDomElement e = n.toElement(); // try to convert the node to an element.
      if (!e.isNull()) { // the node was really an element.
        if (e.tagName() == "tag") {
          in_tag = e.text();
        } else if (e.tagName() == "vectag") {
          vecName = e.text();
        } else if (e.tagName() == "sampRate") {
          in_freq = e.text().toDouble();
        } else if (e.tagName() == "average") {
          in_average = (e.text() != "0");
        } else if (e.tagName() == "fftLen") {
          in_averageLength = e.text().toInt();
        } else if (e.tagName() == "apodize") {
          in_apodize = (e.text() != "0");
        } else if (e.tagName() == "apodizefxn") {
          in_apodizeFxn = ApodizeFunction(e.text().toInt());
        } else if (e.tagName() == "gaussiansigma") {
          in_gaussianSigma = e.text().toDouble();
        } else if (e.tagName() == "removeMean") {
          in_removeMean = (e.text() != "0");
        } else if (e.tagName() == "windowsize") {
          in_windowSize = e.text().toInt();
        } else if (e.tagName() == "vectorunits") {
          in_vectorUnits = e.text();
        } else if (e.tagName() == "rateunits") {
          in_rateUnits = e.text();
        } else if (e.tagName() == "output") {
          in_outputType = (PSDType)e.text().toInt();
        }
      }
      n = n.nextSibling();
    }
    
    _inputVectorLoadQueue.append(qMakePair(INVECTOR, vecName));
    
    commonConstructor(in_tag, in_V, in_freq, in_average, in_removeMean,
                      in_apodize, in_apodizeFxn, in_windowSize, in_averageLength, in_gaussianSigma,
                      in_vectorUnits, in_rateUnits, in_outputType, vecName);
}
示例#3
0
/* returns true if succesful */
bool KstCsdDialogI::newObject() {
    QString tag_name = _tagName->text();
    if (tag_name == defaultTag) {
        tag_name = KST::suggestCSDName(_w->_vector->selectedVector());
    }

    // verify that the curve name is unique
    if (KstData::self()->dataTagNameNotUnique(tag_name)) {
        _tagName->setFocus();
        return false;
    }

    if (_w->_vector->selectedVector().isEmpty()) {
        KMessageBox::sorry(this, i18n("New CSD not made: define vectors first."));
        return false;
    }

    KST::vectorList.lock().readLock();
    KstVectorPtr p = *KST::vectorList.findTag(_w->_vector->selectedVector());
    KST::vectorList.lock().unlock();
    if (!p) {
        kstdFatal() << "Bug in kst: the vector field in CSD dialog refers to "
                    << "a non existant vector...." << endl;
    }

    ApodizeFunction apodizeFxn = ApodizeFunction(_w->_kstFFTOptions->ApodizeFxn->currentItem());
    bool apodize = _w->_kstFFTOptions->Apodize->isChecked();
    double gaussianSigma = _w->_kstFFTOptions->Sigma->value();
    bool removeMean = _w->_kstFFTOptions->RemoveMean->isChecked();
    bool average = _w->_kstFFTOptions->Interleaved->isChecked();
    int windowSize = _w->_windowSize->value();
    int length = _w->_kstFFTOptions->FFTLen->value();
    double freq = _w->_kstFFTOptions->SampRate->text().toDouble();
    PSDType output = PSDType(_w->_kstFFTOptions->Output->currentItem());
    QString vectorUnits = _w->_kstFFTOptions->VectorUnits->text();
    QString rateUnits = _w->_kstFFTOptions->RateUnits->text();
    _w->_kstFFTOptions->synch();

    KstCSDPtr csd = new KstCSD(tag_name, p, freq, average, removeMean,
                               apodize, apodizeFxn, windowSize, length, gaussianSigma, output,
                               vectorUnits, rateUnits);
    //csd->setInterpolateHoles(_w->_kstFFTOptions->InterpolateHoles->isChecked());

    KstImagePtr image = createImage(csd);

    KST::dataObjectList.lock().writeLock();
    KST::dataObjectList.append(csd.data());
    KST::dataObjectList.append(image.data());
    KST::dataObjectList.lock().unlock();

    csd = 0L;
    emit modified();
    return true;
}
// set the widget to the stored default values
void FFTOptions::loadWidgetDefaults() {
  setSampleRate(_dialogDefaults->value("spectrum/freq",100.0).toDouble());
  setInterleavedAverage(_dialogDefaults->value("spectrum/average",true).toBool());
  setFFTLength(_dialogDefaults->value("spectrum/len",12).toInt());
  setApodize(_dialogDefaults->value("spectrum/apodize",true).toBool());
  setRemoveMean(_dialogDefaults->value("spectrum/removeMean",true).toBool());
  setVectorUnits(_dialogDefaults->value("spectrum/vUnits","V").toString());
  setRateUnits(_dialogDefaults->value("spectrum/rUnits","Hz").toString());
  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());
}
示例#5
0
bool KstCsdDialogI::editSingleObject(KstCSDPtr csPtr) {
    csPtr->writeLock();

    KST::vectorList.lock().readLock();
    csPtr->setVector(*KST::vectorList.findTag(_w->_vector->selectedVector()));
    KST::vectorList.lock().unlock();

    // get the values that need to be checked for consistency
    double pSampRate;
    int pFFTLen;

    if (_sampRateDirty) {
        pSampRate = _w->_kstFFTOptions->SampRate->text().toDouble();
    } else {
        pSampRate = csPtr->freq();
    }

    if (_fFTLenDirty) {
        pFFTLen = _w->_kstFFTOptions->FFTLen->text().toInt();
    } else {
        pFFTLen = csPtr->length();
    }

    if (!_w->_kstFFTOptions->checkGivenValues(pSampRate, pFFTLen)) {
        csPtr->unlock();
        return false;
    }

    if (_sampRateDirty) {
        csPtr->setFreq(_w->_kstFFTOptions->SampRate->text().toDouble());
    }

    if (_fFTLenDirty) {
        csPtr->setLength(_w->_kstFFTOptions->FFTLen->text().toInt());
    }

    if (_apodizeDirty) {
        csPtr->setApodize(_w->_kstFFTOptions->Apodize->isChecked());
    }

    if (_apodizeFxnDirty) {
        csPtr->setApodizeFxn(ApodizeFunction(_w->_kstFFTOptions->ApodizeFxn->currentItem()));
    }

    if (_gaussianSigmaDirty) {
        csPtr->setGaussianSigma(_editMultipleMode ? _w->_kstFFTOptions->Sigma->value() - 1 :
                                _w->_kstFFTOptions->Sigma->value());
    }

    if (_removeMeanDirty) {
        csPtr->setRemoveMean(_w->_kstFFTOptions->RemoveMean->isChecked());
    }

    if (_interleavedDirty) {
        csPtr->setAverage(_w->_kstFFTOptions->Interleaved->isChecked());
    }

    if (_windowSizeDirty) {
        csPtr->setWindowSize(_w->_windowSize->value());
    }

    if (_rateUnitsDirty) {
        csPtr->setRateUnits(_w->_kstFFTOptions->RateUnits->text());
    }

    if (_vectorUnitsDirty) {
        csPtr->setVectorUnits(_w->_kstFFTOptions->VectorUnits->text());
    }

    if (_outputDirty) {
        csPtr->setOutput(PSDType(_w->_kstFFTOptions->Output->currentItem()));
    }

    csPtr->unlock();
    return true;
}
示例#6
0
bool KstPsdDialog::editSingleObject(KstPSDPtr psPtr) {
  psPtr->writeLock();

  KST::vectorList.lock().readLock();
  KstVectorPtr v = *KST::vectorList.findTag(_w->_vector->selectedVector());
  KST::vectorList.lock().unlock();

  if (v) { // Can be null if edit multiple and it wasn't changed
    psPtr->setVector(v);
  }

  // get the values that need to be checked for consistency
  double pSampRate;
  int pFFTLen;

  if (_sampRateDirty) {
    pSampRate = _w->_kstFFTOptions->SampRate->text().toDouble();
  } else {
    pSampRate = psPtr->freq();
  }

  if (_fFTLenDirty) {
    pFFTLen = _w->_kstFFTOptions->FFTLen->text().toInt();
  } else {
    pFFTLen = psPtr->len();
  }

  if (!_w->_kstFFTOptions->checkGivenValues(pSampRate, pFFTLen)) {
    psPtr->unlock();
    return false;
  }

  if (_sampRateDirty) {
    psPtr->setFreq(_w->_kstFFTOptions->SampRate->text().toDouble());
  }

  if (_fFTLenDirty) {
    psPtr->setLen(_w->_kstFFTOptions->FFTLen->text().toInt());
  }

  if (_vectorUnitsDirty) {
    psPtr->setVUnits(_w->_kstFFTOptions->VectorUnits->text());
  }

  if (_rateUnitsDirty) {
    psPtr->setRUnits(_w->_kstFFTOptions->RateUnits->text());
  }

  if (_apodizeDirty) {
    psPtr->setApodize(_w->_kstFFTOptions->Apodize->isChecked());
  }

  if (_apodizeFxnDirty) {
    if (_editMultipleMode) {
      psPtr->setApodizeFxn(ApodizeFunction(_w->_kstFFTOptions->ApodizeFxn->currentIndex()-1));
    } else {
      psPtr->setApodizeFxn(ApodizeFunction(_w->_kstFFTOptions->ApodizeFxn->currentIndex()));
    }
  }

  if (_gaussianSigmaDirty) {
    psPtr->setGaussianSigma(_editMultipleMode ? _w->_kstFFTOptions->Sigma->value() - 1 :
                                                _w->_kstFFTOptions->Sigma->value());
  }

  if (_removeMeanDirty) {
    psPtr->setRemoveMean(_w->_kstFFTOptions->RemoveMean->isChecked());
  }

  if (_interleavedDirty) {
    psPtr->setAverage(_w->_kstFFTOptions->Interleaved->isChecked());
  }

  if (_outputDirty) {
    if (_editMultipleMode) {
      psPtr->setOutput(PSDType(_w->_kstFFTOptions->Output->currentIndex()-1));
    } else {
      psPtr->setOutput(PSDType(_w->_kstFFTOptions->Output->currentIndex()));
    }
  }

  if (_interpolateHolesDirty) {
    psPtr->setInterpolateHoles(_w->_kstFFTOptions->InterpolateHoles->isChecked());
  }

  psPtr->setRecursed(false);
  if (psPtr->recursion()) {
    psPtr->setRecursed(true);
    psPtr->unlock();
    QMessageBox::critical(this, QObject::tr("Kst"), QObject::tr("There is a recursion resulting from the spectrum  you entered."));
    return false;
  }

  psPtr->unlock();
  return true;
}
示例#7
0
bool KstPsdDialog::newObject() {
  QString tag_name = _tagName->text();
  bool retVal = false;

  if (tag_name == defaultTag) {
    tag_name = KST::suggestPSDName(KstObjectTag::fromString(_w->_vector->selectedVector()));
  }

  if (KstData::self()->dataTagNameNotUnique(tag_name)) {
    _tagName->setFocus();
    return false;
  }

  if (_w->_vector->selectedVector().isEmpty()) {
    QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("New spectrum not made: define vectors first."));
    return false;
  }

  KST::vectorList.lock().readLock();
  KstVectorPtr p = *KST::vectorList.findTag(_w->_vector->selectedVector());
  KST::vectorList.lock().unlock();

  if (_w->_kstFFTOptions->checkValues()) {
    if (p) {
      KstVCurvePtr vc;
      KstPSDPtr psd;
      QColor color;

      p->readLock();
      psd = new KstPSD(tag_name, p,
                       _w->_kstFFTOptions->SampRate->text().toDouble(),
                       _w->_kstFFTOptions->Interleaved->isChecked(),
                       _w->_kstFFTOptions->FFTLen->text().toInt(),
                       _w->_kstFFTOptions->Apodize->isChecked(),
                       _w->_kstFFTOptions->RemoveMean->isChecked(),
                       _w->_kstFFTOptions->VectorUnits->text(),
                       _w->_kstFFTOptions->RateUnits->text(),
                       ApodizeFunction(_w->_kstFFTOptions->ApodizeFxn->currentIndex()),
                       _w->_kstFFTOptions->Sigma->value(),
                       PSDType(_w->_kstFFTOptions->Output->currentIndex()));
      psd->setInterpolateHoles(_w->_kstFFTOptions->InterpolateHoles->isChecked());
      p->unlock();
  
// xxx      color = KstApp::inst()->chooseColorDlg()->getColorForCurve(psd->vX(), psd->vY());
      if (!color.isValid()) {
        color = _w->_curveAppearance->color();
      }

      vc = new KstVCurve(KST::suggestCurveName(psd->tag(),true), psd->vX(), psd->vY(), KstVectorPtr(), KstVectorPtr(), KstVectorPtr(), KstVectorPtr(), color);
      vc->setHasPoints(_w->_curveAppearance->showPoints());
      vc->setHasLines(_w->_curveAppearance->showLines());
      vc->setHasBars(_w->_curveAppearance->showBars());
      vc->setPointStyle(_w->_curveAppearance->pointType());
      vc->setLineWidth(_w->_curveAppearance->lineWidth());
      vc->setLineStyle(_w->_curveAppearance->lineStyle());
      vc->setBarStyle(_w->_curveAppearance->barStyle());
      vc->setPointDensity(_w->_curveAppearance->pointDensity());
  
      QString legend_text = _legendText->text();

      if (legend_text == defaultTag) {
        vc->setLegendText(QString::null);
      } else {
        vc->setLegendText(legend_text);
      }
  
      Kst2DPlotPtr plot;
      KstViewWindow *w;
/* xxx
      w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(_w->_curvePlacement->_plotWindow->currentText()));
      if (!w) {
        QString n = KstApp::inst()->newWindow(KST::suggestWinName());
        w = static_cast<KstViewWindow*>(KstApp::inst()->findWindow(n));
      }
*/
      if (w) {
        if (_w->_curvePlacement->existingPlot()) {
          plot = kst_cast<Kst2DPlot>(w->view()->findChild(_w->_curvePlacement->plotName()));
          if (plot) {
            plot->addCurve(vc);
          }
        }
  
        if (_w->_curvePlacement->newPlot()) {
          QString name = w->createPlot(KST::suggestPlotName());

          if (_w->_curvePlacement->reGrid()) {
            w->view()->cleanup(_w->_curvePlacement->columns());
          }
          plot = kst_cast<Kst2DPlot>(w->view()->findChild(name));
          if (plot) {
            plot->setXAxisInterpretation(false, KstAxisInterpretation(), KstAxisDisplay());
            plot->setYAxisInterpretation(false, KstAxisInterpretation(), KstAxisDisplay());
            _w->_curvePlacement->update();
            _w->_curvePlacement->setCurrentPlot(plot->tagName());
            plot->addCurve(vc);
            plot->generateDefaultLabels();
          }
        }
      }
      KST::dataObjectList.lock().writeLock();
      KST::dataObjectList.append(psd);
      KST::dataObjectList.append(vc);
      KST::dataObjectList.lock().unlock();

      psd = 0L;
      vc = 0L;

      emit modified();

      retVal = true;
    }
  }

  return retVal;
}
示例#8
0
/* returns true if succesful */
bool KstPsdDialogI::newObject() {
  QString tag_name = _tagName->text();
  if (tag_name == defaultTag) {
    tag_name = KST::suggestPSDName(KstObjectTag::fromString(_w->_vector->selectedVector()));
  }

  // verify that the curve name is unique
  if (KstData::self()->dataTagNameNotUnique(tag_name)) {
    _tagName->setFocus();
    return false;
  }

  if (_w->_vector->selectedVector().isEmpty()) {
    KMessageBox::sorry(this, i18n("New PSD not made: define vectors first."));
    return false;
  }

  KST::vectorList.lock().readLock();
  KstVectorPtr p = *KST::vectorList.findTag(_w->_vector->selectedVector());
  KST::vectorList.lock().unlock();
  if (!p) {
    kstdFatal() << "Bug in kst: the vector field (PSD) refers to "
                << "a non existant vector...." << endl;
  }

  // create the psd curve
  if (!_w->_kstFFTOptions->checkValues()) {
    return false;
  } else {
    p->readLock();
    KstPSDPtr psd = new KstPSD(tag_name, p,
                            _w->_kstFFTOptions->SampRate->text().toDouble(),
                            _w->_kstFFTOptions->Interleaved->isChecked(),
                            _w->_kstFFTOptions->FFTLen->text().toInt(),
                            _w->_kstFFTOptions->Apodize->isChecked(),
                            _w->_kstFFTOptions->RemoveMean->isChecked(),
                            _w->_kstFFTOptions->VectorUnits->text(),
                            _w->_kstFFTOptions->RateUnits->text(),
                            ApodizeFunction(_w->_kstFFTOptions->ApodizeFxn->currentItem()),
                            _w->_kstFFTOptions->Sigma->value(),
                            PSDType(_w->_kstFFTOptions->Output->currentItem()));
    psd->setInterpolateHoles(_w->_kstFFTOptions->InterpolateHoles->isChecked());
    p->unlock();

    KstVCurvePtr vc = new KstVCurve(KST::suggestCurveName(psd->tag(),true), psd->vX(), psd->vY(), 0L, 0L, 0L, 0L, _w->_curveAppearance->color());
    vc->setHasPoints(_w->_curveAppearance->showPoints());
    vc->setHasLines(_w->_curveAppearance->showLines());
    vc->setHasBars(_w->_curveAppearance->showBars());
    vc->pointType = _w->_curveAppearance->pointType();
    vc->setLineWidth(_w->_curveAppearance->lineWidth());
    vc->setLineStyle(_w->_curveAppearance->lineStyle());
    vc->setBarStyle(_w->_curveAppearance->barStyle());
    vc->setPointDensity(_w->_curveAppearance->pointDensity());

    QString legend_text = _legendText->text();
    if (legend_text == defaultTag) {
      vc->setLegendText(QString::null);
    } else {
      vc->setLegendText(legend_text);
    }

    Kst2DPlotPtr plot;
    KstViewWindow *w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(_w->_curvePlacement->_plotWindow->currentText()));
    if (!w) {
      QString n = KstApp::inst()->newWindow(KST::suggestWinName());
      w = static_cast<KstViewWindow*>(KstApp::inst()->findWindow(n));
    }
    if (w) {
      if (_w->_curvePlacement->existingPlot()) {
        // assign curve to plot
        plot = kst_cast<Kst2DPlot>(w->view()->findChild(_w->_curvePlacement->plotName()));
        if (plot) {
          plot->addCurve(vc.data());
        }
      }

      if (_w->_curvePlacement->newPlot()) {
        // assign curve to plot
        QString name = w->createObject<Kst2DPlot>(KST::suggestPlotName());
        if (_w->_curvePlacement->reGrid()) {
          w->view()->cleanup(_w->_curvePlacement->columns());
        }
        plot = kst_cast<Kst2DPlot>(w->view()->findChild(name));
        if (plot) {
          plot->setXAxisInterpretation(false, KstAxisInterpretation(), KstAxisDisplay());
          plot->setYAxisInterpretation(false, KstAxisInterpretation(), KstAxisDisplay());
          _w->_curvePlacement->update();
          _w->_curvePlacement->setCurrentPlot(plot->tagName());
          plot->addCurve(vc.data());
          plot->generateDefaultLabels();
        }
      }
    }
    KST::dataObjectList.lock().writeLock();
    KST::dataObjectList.append(psd.data());
    KST::dataObjectList.append(vc.data());
    KST::dataObjectList.lock().unlock();
    psd = 0L;
    vc = 0L;
    emit modified();
  }
  return true;
}