Changeset View
Changeset View
Standalone View
Standalone View
Tests/fitsviewer/testfitsdata.cpp
1 | /* KStars tests | 1 | /* KStars tests | ||
---|---|---|---|---|---|
2 | Copyright (C) 2020 | 2 | Copyright (C) 2020 | ||
3 | Eric Dejouhanet <eric.dejouhanet@gmail.com> | 3 | Eric Dejouhanet <eric.dejouhanet@gmail.com> | ||
4 | 4 | | |||
5 | This application is free software; you can redistribute it and/or | 5 | This application is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU General Public | 6 | modify it under the terms of the GNU General Public | ||
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. | ||
9 | */ | 9 | */ | ||
10 | 10 | | |||
11 | #include <QtTest> | 11 | #include <QtTest> | ||
12 | 12 | | |||
13 | #include "testfitsdata.h" | 13 | #include "testfitsdata.h" | ||
14 | 14 | | |||
15 | TestFitsData::TestFitsData(QObject *parent) : QObject(parent) | 15 | TestFitsData::TestFitsData(QObject *parent) : QObject(parent) | ||
16 | { | 16 | { | ||
17 | | ||||
18 | } | 17 | } | ||
19 | 18 | | |||
20 | void TestFitsData::initTestCase() | 19 | void TestFitsData::initTestCase() | ||
21 | { | 20 | { | ||
22 | } | 21 | } | ||
23 | 22 | | |||
24 | void TestFitsData::cleanupTestCase() | 23 | void TestFitsData::cleanupTestCase() | ||
25 | { | 24 | { | ||
26 | } | 25 | } | ||
27 | 26 | | |||
28 | | ||||
29 | void TestFitsData::init() | 27 | void TestFitsData::init() | ||
30 | { | 28 | { | ||
31 | if(!QFile::exists(m_FitsFixture)) | 29 | if(!QFile::exists(m_FitsFixture)) | ||
32 | QSKIP("Skipping load test because of missing fixture"); | 30 | QSKIP("Skipping load test because of missing fixture"); | ||
33 | 31 | | |||
34 | cleanup(); | 32 | cleanup(); | ||
35 | 33 | | |||
36 | fd = new FITSData(); | 34 | fd = new FITSData(); | ||
Show All 20 Lines | 52 | { | |||
57 | runFocusHFR(m_FocusFixture1, 11, 3.89); | 55 | runFocusHFR(m_FocusFixture1, 11, 3.89); | ||
58 | if(!QFile::exists(m_FocusFixture2)) | 56 | if(!QFile::exists(m_FocusFixture2)) | ||
59 | QSKIP("Skipping load test because of missing fixture"); | 57 | QSKIP("Skipping load test because of missing fixture"); | ||
60 | runFocusHFR(m_FocusFixture2, 17, 2.16); | 58 | runFocusHFR(m_FocusFixture2, 17, 2.16); | ||
61 | if(!QFile::exists(m_FocusFixture3)) | 59 | if(!QFile::exists(m_FocusFixture3)) | ||
62 | QSKIP("Skipping load test because of missing fixture"); | 60 | QSKIP("Skipping load test because of missing fixture"); | ||
63 | runFocusHFR(m_FocusFixture3, 100, 1.23); | 61 | runFocusHFR(m_FocusFixture3, 100, 1.23); | ||
64 | } | 62 | } | ||
63 | | ||||
65 | void TestFitsData::runFocusHFR(const QString &filename, int nstars, float hfr) | 64 | void TestFitsData::runFocusHFR(const QString &filename, int nstars, float hfr) | ||
66 | { | 65 | { | ||
67 | FITSData * d = new FITSData(); | 66 | FITSData * d = new FITSData(); | ||
68 | QVERIFY(d != nullptr); | 67 | QVERIFY(d != nullptr); | ||
69 | 68 | | |||
70 | QFuture<bool> worker = d->loadFITS(filename); | 69 | QFuture<bool> worker = d->loadFITS(filename); | ||
71 | QTRY_VERIFY_WITH_TIMEOUT(worker.isFinished(), 5000); | 70 | QTRY_VERIFY_WITH_TIMEOUT(worker.isFinished(), 5000); | ||
72 | QVERIFY(worker.result()); | 71 | QVERIFY(worker.result()); | ||
73 | 72 | | |||
74 | QCOMPARE(d->findStars(ALGORITHM_SEP), nstars); | 73 | QCOMPARE(d->findStars(ALGORITHM_SEP), nstars); | ||
75 | QCOMPARE(d->getDetectedStars(), nstars); | 74 | QCOMPARE(d->getDetectedStars(), nstars); | ||
76 | QCOMPARE(d->getStarCenters().count(), nstars); | 75 | QCOMPARE(d->getStarCenters().count(), nstars); | ||
77 | QVERIFY(abs(d->getHFR() - hfr) < 0.01); | 76 | QVERIFY(abs(d->getHFR() - hfr) < 0.01); | ||
78 | 77 | | |||
79 | delete d; | 78 | delete d; | ||
80 | d = nullptr; | 79 | d = nullptr; | ||
81 | } | 80 | } | ||
82 | 81 | | |||
82 | | ||||
83 | void TestFitsData::testBahtinovFocusHFR() | ||||
84 | { | ||||
85 | if(!QFile::exists(m_BahtinovFixture)) | ||||
86 | QSKIP("Skipping load test because of missing fixture"); | ||||
87 | | ||||
88 | FITSData * d = new FITSData(); | ||||
89 | QVERIFY(d != nullptr); | ||||
90 | | ||||
91 | QFuture<bool> worker = d->loadFITS(m_BahtinovFixture); | ||||
92 | QTRY_VERIFY_WITH_TIMEOUT(worker.isFinished(), 5000); | ||||
93 | QVERIFY(worker.result()); | ||||
94 | | ||||
95 | // The bahtinov algorithm depends on which star is selected and number of average rows - not sure how to fiddle with that yet | ||||
96 | const QRect trackingBox(204, 240, 128, 128); | ||||
97 | | ||||
98 | QCOMPARE(d->findStars(ALGORITHM_BAHTINOV, trackingBox), 1); | ||||
99 | QCOMPARE(d->getDetectedStars(), 1); | ||||
100 | QCOMPARE(d->getStarCenters().count(), 1); | ||||
101 | QVERIFY(abs(d->getHFR() - 1.544) < 0.01); | ||||
102 | | ||||
103 | delete d; | ||||
104 | d = nullptr; | ||||
105 | } | ||||
106 | | ||||
83 | void TestFitsData::testLoadFits() | 107 | void TestFitsData::testLoadFits() | ||
84 | { | 108 | { | ||
85 | // Statistics computation | 109 | // Statistics computation | ||
86 | QVERIFY(abs(fd->getADU() - 41.08) < 0.01); | 110 | QVERIFY(abs(fd->getADU() - 41.08) < 0.01); | ||
87 | QVERIFY(abs(fd->getMean() - 41.08) < 0.01); | 111 | QVERIFY(abs(fd->getMean() - 41.08) < 0.01); | ||
88 | QVERIFY(abs(fd->getStdDev() - 360.18) < 0.01); | 112 | QVERIFY(abs(fd->getStdDev() - 360.18) < 0.01); | ||
89 | QVERIFY(abs(fd->getSNR() - 0.114) < 0.001); | 113 | QVERIFY(abs(fd->getSNR() - 0.114) < 0.001); | ||
90 | 114 | | |||
91 | // Minmax | 115 | // Minmax | ||
92 | QCOMPARE(fd->getMax(), 57832); | 116 | QCOMPARE((int)fd->getMax(), 57832); | ||
93 | QCOMPARE(fd->getMin(), 21); | 117 | QCOMPARE((int)fd->getMin(), 21); | ||
94 | 118 | | |||
95 | QWARN("No median calculation in the current implementation"); | 119 | QWARN("No median calculation in the current implementation"); | ||
96 | QCOMPARE(fd->getMedian(), 0); | 120 | QCOMPARE((int)fd->getMedian(), 0); | ||
97 | 121 | | |||
98 | // Without searching for stars, there are no stars found | 122 | // Without searching for stars, there are no stars found | ||
99 | QCOMPARE(fd->getStarCenters().count(), 0); | 123 | QCOMPARE(fd->getStarCenters().count(), 0); | ||
100 | QCOMPARE(fd->getHFR(), -1.0); | 124 | QCOMPARE(fd->getHFR(), -1.0); | ||
101 | 125 | | |||
102 | // Default algorithm is centroid, 80 stars with 1.495 as HFR | 126 | // Default algorithm is centroid, 80 stars with 1.495 as HFR | ||
103 | QCOMPARE(fd->findStars(), 80); | 127 | QCOMPARE(fd->findStars(), 80); | ||
104 | QCOMPARE(fd->getDetectedStars(), 80); | 128 | QCOMPARE(fd->getDetectedStars(), 80); | ||
▲ Show 20 Lines • Show All 59 Lines • Show Last 20 Lines |