예제 #1
0
void TestPSD::testPSD() {

  Kst::VectorPtr vp = Kst::kst_cast<Kst::Vector>(_store.createObject<Kst::Vector>(Kst::ObjectTag::fromString("tempVector")));
  Q_ASSERT(vp);
  vp->resize(10);
  for (int i = 0; i < 10; i++){
    vp->value()[i] = i;
  }

  Kst::PSDPtr psd = new Kst::PSD(&_store, Kst::ObjectTag::fromString("psdTest"), vp, 0.0, false, 10, false, false, QString("vUnits"), QString("rUnits"), WindowUndefined, 0.0, PSDUndefined);
  QCOMPARE(psd->tag().tagString(), QLatin1String("psdTest"));
  QCOMPARE(psd->vTag(), QLatin1String("tempVector"));
  QCOMPARE(psd->output(), PSDUndefined);
  QVERIFY(!psd->apodize());
  QVERIFY(!psd->removeMean());
  QVERIFY(!psd->average());
  QCOMPARE(psd->freq(), 0.0);
  QCOMPARE(psd->apodizeFxn(), WindowUndefined);
  QCOMPARE(psd->gaussianSigma(), 0.0);
  Kst::VectorPtr vpVX = psd->vX();
  Kst::VectorPtr vpVY = psd->vY();

  QCOMPARE(vpVX->length(), 1);
  QVERIFY(vpVX->value()[0] != vpVX->value()[0]);
  QCOMPARE(vpVY->length(), 1);
  QVERIFY(vpVY->value()[0] != vpVY->value()[0]);

  psd->writeLock();
  QCOMPARE(psd->update(0), Kst::Object::UPDATE);
  psd->unlock();

  for(int j = 0; j < vpVX->length(); j++){
      QCOMPARE(vpVX->value()[j], 0.0);
  }

  psd->setOutput(PSDAmplitudeSpectralDensity);
  psd->setApodize(true);
  psd->setRemoveMean(true);
  psd->setAverage(true);
  psd->setFreq(0.1);
  psd->setApodizeFxn(WindowOriginal);
  psd->setGaussianSigma(0.2);

  QCOMPARE(psd->tag().tagString(), QLatin1String("psdTest"));
  QCOMPARE(psd->vTag(), QLatin1String("tempVector"));
  QCOMPARE(psd->output(), PSDAmplitudeSpectralDensity);
  QVERIFY(psd->apodize());
  QVERIFY(psd->removeMean());
  QVERIFY(psd->average());
  QCOMPARE(psd->freq(), 0.1);
  QCOMPARE(psd->apodizeFxn(), WindowOriginal);
  QCOMPARE(psd->gaussianSigma(), 0.2);

//   doTest(psd->update(0) == Kst::Object::UPDATE);
//   QString ps = "PSD: " + psd->vTag();
//   doTest(psd->propertyString() == ps);
//    doTest(!psd->curveHints().curveName() == "");
//   printf("Curve name [%s]", kstCHL[0].curveName());
//   printf("X Vector name [%s]", kstCHL[0].xVectorName());
//   printf("Y Vector name [%s]", kstCHL[0].yVectorName());

  QTemporaryFile tf;
  tf.open();
  QTextStream ts(&tf);
  psd->save(ts, "");
  QFile::remove(tf.fileName());

  QDomNode n = makeDOMElement("psdDOMPsd", "psdDOMVector").firstChild();
  QDomElement e = n.toElement();
  Kst::PSDPtr psdDOM = new Kst::PSD(&_store, e);

  QCOMPARE(psdDOM->tag().tagString(), QLatin1String("psdDOMPsd"));
  QCOMPARE(psdDOM->output(), PSDAmplitudeSpectralDensity);
  QVERIFY(psdDOM->apodize());
  QVERIFY(psdDOM->removeMean());
  QVERIFY(psdDOM->average());
  QCOMPARE(psdDOM->freq(), 128.0);
  QCOMPARE(psdDOM->apodizeFxn(), WindowOriginal);
  QCOMPARE(psdDOM->gaussianSigma(), 0.01);

//   Kst::VectorPtr vpVX = psdDOM->vX();
//   for(int j = 0; j < vpVX->length(); j++){
//       printf("[%d][%lf]", j, vpVX->value()[j]);
//   }
//   Kst::VectorPtr vpVY = psdDOM->vY();
}
예제 #2
0
void TestCSD::testCSD() {

  Kst::VectorPtr vp = Kst::kst_cast<Kst::Vector>(_store.createObject<Kst::Vector>());
  Q_ASSERT(vp);
  vp->resize(10);
  vp->setDescriptiveName("tempVector");
  for (int i = 0; i < 10; i++){
    vp->value()[i] = i;
  }

  Kst::CSDPtr csd = Kst::kst_cast<Kst::CSD>(_store.createObject<Kst::CSD>());
  csd->change(vp, 1.0, false, false, false, WindowUndefined, 0, 0, 0.0, PSDUndefined, QString::null, QString::null);

  QCOMPARE(csd->vector()->descriptiveName(), QLatin1String("tempVector"));
  QCOMPARE(csd->output(), PSDUndefined);
  QVERIFY(!csd->apodize());
  QVERIFY(!csd->removeMean());
  QVERIFY(!csd->average());
  QCOMPARE(csd->frequency(), 1.0);
  QCOMPARE(csd->apodizeFxn(), WindowUndefined);
  QCOMPARE(csd->length(), 0);
  QCOMPARE(csd->windowSize(), 0);
  QCOMPARE(csd->gaussianSigma(), 0.0);
  QVERIFY(csd->vectorUnits().isEmpty());
  QVERIFY(csd->rateUnits().isEmpty());

  csd->setOutput(PSDAmplitudeSpectralDensity);
  csd->setApodize(true);
  csd->setRemoveMean(true);
  csd->setAverage(true);
  csd->setFrequency(0.1);
  csd->setApodizeFxn(WindowOriginal);
  csd->setLength(3);
  csd->setWindowSize(50);
  csd->setGaussianSigma(0.2);

  QCOMPARE(csd->vector()->descriptiveName(), QLatin1String("tempVector"));
  QCOMPARE(csd->output(), PSDAmplitudeSpectralDensity);
  QVERIFY(csd->apodize());
  QVERIFY(csd->removeMean());
  QVERIFY(csd->average());
  QCOMPARE(csd->frequency(), 0.1);
  QCOMPARE(csd->windowSize(), 50);
  QCOMPARE(csd->apodizeFxn(), WindowOriginal);
  QCOMPARE(csd->gaussianSigma(), 0.2);

//   KTempFile tf(locateLocal("tmp", "kst-csd"), "txt");
//   QFile *qf = tf.file();
//   QTextStream ts(qf);
//   csd->save(ts, "");

// the constructor used here is no longer used in kst: use the factory instead
//   QDomNode n = makeDOMElement("csdDOMCsd", "csdDOMVector").firstChild();
//   QDomElement e = n.toElement();
//   Kst::CSDPtr csdDOM = new Kst::CSD(&_store, e);
// 
//   QCOMPARE(csdDOM->output(), PSDPowerSpectralDensity);
//   QVERIFY(csdDOM->apodize());
//   QVERIFY(csdDOM->removeMean());
//   QVERIFY(csdDOM->average());
//   QCOMPARE(csdDOM->frequency(), 1.0);
//   QCOMPARE(csdDOM->apodizeFxn(), WindowOriginal);
//   QCOMPARE(csdDOM->gaussianSigma(), 0.01);
//   QCOMPARE(csdDOM->windowSize(), 5000);

//   Kst::VectorPtr vp2 = Kst::kst_cast<Kst::Vector>(_store.createObject<Kst::Vector>());
//   Q_ASSERT(vp2);
//   vp2->resize(10);
//   for (int i = 0; i < 10; i++){
//     vp2->value()[i] = i;
//   }
//   csdDOM->setVector(vp2);
//   QCOMPARE(csdDOM->vector()->descriptiveName(), QLatin1String("tempVector2"));
//   csdDOM->setWindowSize(9);
//   Kst::MatrixPtr outMatrix = csdDOM->outputMatrix();
// 
//   QVERIFY(outMatrix->resize(3, 3, false)); // very odd thing to do?
//   QVERIFY(outMatrix->setValue(0, 0, 1.716299));
//   QVERIFY(outMatrix->setValue(0, 1, -0.485527));
//   QVERIFY(outMatrix->setValue(0, 2, -0.288690));
//   QVERIFY(outMatrix->setValue(1, 0, 1.716299));
//   QVERIFY(outMatrix->setValue(1, 1, NAN));
//   QVERIFY(outMatrix->setValue(1, 2, -0.274957));
//   QVERIFY(outMatrix->setValue(2, 0, 1.711721));
//   QVERIFY(outMatrix->setValue(2, 1, -0.485527));
//   QVERIFY(outMatrix->setValue(2, 2, -0.293267));
// 
//   QCOMPARE(outMatrix->sampleCount(), 9);
//   QCOMPARE(outMatrix->value(0, 0), 1.716299);
//   QCOMPARE(outMatrix->value(0, 1),  -0.485527);
//   QCOMPARE(outMatrix->value(0, 2), -0.288690);
//   QCOMPARE(outMatrix->value(1, 0), 1.716299);
//   QCOMPARE(outMatrix->value(1, 1), 0.0);
//   QCOMPARE(outMatrix->value(1, 2), -0.274957);
//   QCOMPARE(outMatrix->value(2, 0), 1.711721);
//   QCOMPARE(outMatrix->value(2, 1), -0.485527);
//   QCOMPARE(outMatrix->value(2, 2), -0.293267);
// 
//   csdDOM->writeLock();
//   QCOMPARE(csdDOM->update(), Kst::Object::UPDATE);
//   csdDOM->unlock();
// 
//   outMatrix = csdDOM->outputMatrix();
//   QEXPECT_FAIL("", "This has always failed", Continue);
//   QCOMPARE(outMatrix->sampleCount(), 128);
// 
//   csdDOM->setWindowSize(11);
//   QEXPECT_FAIL("", "This has always failed", Continue);
//   QCOMPARE(outMatrix->sampleCount(), 128);
// 
//   QEXPECT_FAIL("", "This has always failed", Continue);
//   QCOMPARE(outMatrix->value(0, 0), 1.716299);
//   QEXPECT_FAIL("", "This has always failed", Continue);
//   QCOMPARE(outMatrix->value(0, 1),  -0.485527);
//   QEXPECT_FAIL("", "This has always failed", Continue);
//   QCOMPARE(outMatrix->value(0, 2), -0.288690);
//   QEXPECT_FAIL("", "This has always failed", Continue);
//   QCOMPARE(outMatrix->value(1, 0), 1.716299);
//   QCOMPARE(outMatrix->value(1, 1), 0.0);
//   QEXPECT_FAIL("", "This has always failed", Continue);
//   QCOMPARE(outMatrix->value(1, 2), -0.274957);
//   QEXPECT_FAIL("", "This has always failed", Continue);
//   QCOMPARE(outMatrix->value(2, 0), 1.711721);
//   QEXPECT_FAIL("", "This has always failed", Continue);
//   QCOMPARE(outMatrix->value(2, 1), -0.485527);
//   QEXPECT_FAIL("", "This has always failed", Continue);
//   QCOMPARE(outMatrix->value(2, 2), -0.293267);

}
예제 #3
0
void TestPSD::testPSD() {

  Kst::VectorPtr vp = Kst::kst_cast<Kst::Vector>(_store.createObject<Kst::Vector>());
  Q_ASSERT(vp);
  vp->resize(10);
  vp->setDescriptiveName("tempVector");
  for (int i = 0; i < 10; i++){
    vp->value()[i] = i;
  }

  Kst::PSDPtr psd = Kst::kst_cast<Kst::PSD>(_store.createObject<Kst::PSD>());
  psd->change(vp, 0.0, false, 10, false, false, QString("vUnits"), QString("rUnits"), WindowUndefined, 0.0, PSDUndefined);
  QCOMPARE(psd->vector()->descriptiveName(), QLatin1String("tempVector"));
  QCOMPARE(psd->output(), PSDUndefined);
  QVERIFY(!psd->apodize());
  QVERIFY(!psd->removeMean());
  QVERIFY(!psd->average());
  QCOMPARE(psd->frequency(), 0.0);
  QCOMPARE(psd->apodizeFxn(), WindowUndefined);
  QCOMPARE(psd->gaussianSigma(), 0.0);
  Kst::VectorPtr vpVX = psd->vX();
  Kst::VectorPtr vpVY = psd->vY();

  QCOMPARE(vpVX->length(), 1);
  QVERIFY(vpVX->value()[0] != vpVX->value()[0]);
  QCOMPARE(vpVY->length(), 1);
  QVERIFY(vpVY->value()[0] != vpVY->value()[0]);

  for(int j = 0; j < vpVX->length(); j++){
      QCOMPARE(vpVX->value()[j], 0.0);
  }

  psd->setOutput(PSDAmplitudeSpectralDensity);
  psd->setApodize(true);
  psd->setRemoveMean(true);
  psd->setAverage(true);
  psd->setFrequency(0.1);
  psd->setApodizeFxn(WindowOriginal);
  psd->setGaussianSigma(0.2);

  QCOMPARE(psd->vector()->descriptiveName(), QLatin1String("tempVector"));
  QCOMPARE(psd->output(), PSDAmplitudeSpectralDensity);
  QVERIFY(psd->apodize());
  QVERIFY(psd->removeMean());
  QVERIFY(psd->average());
  QCOMPARE(psd->frequency(), 0.1);
  QCOMPARE(psd->apodizeFxn(), WindowOriginal);
  QCOMPARE(psd->gaussianSigma(), 0.2);

//   doTest(psd->update(0) == Kst::Object::UPDATE);
//   doTest(psd->propertyString() == ps);
//    doTest(!psd->curveHints().curveName() == "");
//   printf("Curve name [%s]", kstCHL[0].curveName());
//   printf("X Vector name [%s]", kstCHL[0].xVectorName());
//   printf("Y Vector name [%s]", kstCHL[0].yVectorName());

  QTemporaryFile tf;
  tf.open();
  QXmlStreamWriter xml;
  xml.setDevice(&tf);
  xml.setAutoFormatting(true);
  psd->save(xml);
  QFile::remove(tf.fileName());

  QDomNode n = makeDOMElement("psdDOMPsd", "psdDOMVector").firstChild();
  QDomElement e = n.toElement();

  //FIXME: should use factory, not this constructor.  This constructor is no longer
  // used anywhere in kst.
//   Kst::PSDPtr psdDOM = new Kst::PSD(&_store, e);

//   QCOMPARE(psdDOM->tag().tagString(), QLatin1String("psdDOMPsd"));
//   QCOMPARE(psdDOM->output(), PSDAmplitudeSpectralDensity);
//   QVERIFY(psdDOM->apodize());
//   QVERIFY(psdDOM->removeMean());
//   QVERIFY(psdDOM->average());
//   QCOMPARE(psdDOM->frequency(), 128.0);
//   QCOMPARE(psdDOM->apodizeFxn(), WindowOriginal);
//   QCOMPARE(psdDOM->gaussianSigma(), 0.01);

//   Kst::VectorPtr vpVX = psdDOM->vX();
//   for(int j = 0; j < vpVX->length(); j++){
//       printf("[%d][%lf]", j, vpVX->value()[j]);
//   }
//   Kst::VectorPtr vpVY = psdDOM->vY();
}