##// END OF EJS Templates
Adds unit test of spectrogram with holes at the beginning and the end
Alexandre Leroux -
r986:7598132c69c6
parent child
Show More
@@ -0,0 +1,62
1 # -----------
2 # AMDA INFO :
3 # -----------
4 # AMDA_ABOUT : Created by CDPP/AMDA(c)
5 # AMDA_VERSION : 3.5.0
6 # AMDA_ACKNOWLEDGEMENT : CDPP/AMDA Team
7 #
8 # --------------
9 # REQUEST INFO :
10 # --------------
11 # REQUEST_STRUCTURE : one-file-per-parameter-per-interval
12 # REQUEST_TIME_FORMAT : ISO 8601
13 # REQUEST_OUTPUT_PARAMS : tha_ion_sp
14 #
15 # -----------------
16 # BASE PARAMETERS :
17 # -----------------
18 #
19 # MISSION_ID : NONE
20 #
21 # INSTRUMENT_ID : NONE
22 #
23 # DATASET_ID : tha-esa-l2i
24 # DATASET_NAME : ion full mode
25 # DATASET_SOURCE : CDPP/DDServer
26 # DATASET_GLOBAL_START : 2007-03-07T18:53:59.134
27 # DATASET_GLOBAL_STOP : 2017-11-04T18:35:25.907
28 # DATASET_MIN_SAMPLING : 96
29 # DATASET_MAX_SAMPLING : 240
30 #
31 # PARAMETER_ID : tha_ion_sp
32 # PARAMETER_NAME : tha_ion_sp
33 # PARAMETER_SHORT_NAME : spectra
34 # PARAMETER_UNITS : eV/(cm^2-s-sr-eV)
35 # PARAMETER_TENSOR_ORDER : 0
36 # PARAMETER_TABLE[0] : energy
37 # PARAMETER_TABLE_UNITS[0] : eV
38 # PARAMETER_TABLE_MIN_VALUES[0] : 14234.4,18737.3
39 # PARAMETER_TABLE_MAX_VALUES[0] : 18737.3,23254.9
40 # PARAMETER_FILL_VALUE : nan
41 # PARAMETER_UCD : phys.flux.density;phys.energy;phys.atmol.ionStage
42 #
43 #
44 # ---------------
45 # INTERVAL INFO :
46 # ---------------
47 # INTERVAL_START : 2011-12-10T12:00:00.000
48 # INTERVAL_STOP : 2011-12-10T13:00:00.000
49 #
50 # ------
51 # DATA :
52 # ------
53 # DATA_COLUMNS : AMDA_TIME, tha_ion_sp[0], tha_ion_sp[1]
54 #
55 2011-12-10T12:10:54.000 2577578.000 2336016.000
56 2011-12-10T12:17:23.000 2314121.500 1712093.125
57 2011-12-10T12:23:51.000 2063608.750 1614491.625
58 2011-12-10T12:30:19.000 2234525.500 1764516.500
59 2011-12-10T12:35:04.000 1670215.250 1688078.500
60 2011-12-10T12:36:41.000 1689243.250 1743183.500
61 2011-12-10T12:38:18.000 1654617.125 1733603.250
62 2011-12-10T12:39:55.000 1504983.750 1708356.500 No newline at end of file
@@ -1,506 +1,580
1 1 #include "AmdaResultParser.h"
2 2
3 3 #include <Data/ScalarSeries.h>
4 4 #include <Data/SpectrogramSeries.h>
5 5 #include <Data/VectorSeries.h>
6 6
7 7 #include <QObject>
8 8 #include <QtTest>
9 9
10 10 namespace {
11 11
12 12 /// Path for the tests
13 13 const auto TESTS_RESOURCES_PATH
14 14 = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaResultParser"}.absoluteFilePath();
15 15
16 16 QDateTime dateTime(int year, int month, int day, int hours, int minutes, int seconds)
17 17 {
18 18 return QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC};
19 19 }
20 20
21 21 QString inputFilePath(const QString &inputFileName)
22 22 {
23 23 return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath();
24 24 }
25 25
26 26 template <typename T>
27 27 struct ExpectedResults {
28 28
29 29 ExpectedResults &setParsingOK(bool parsingOK)
30 30 {
31 31 m_ParsingOK = parsingOK;
32 32 return *this;
33 33 }
34 34
35 35 ExpectedResults &setXAxisUnit(Unit xAxisUnit)
36 36 {
37 37 m_XAxisUnit = std::move(xAxisUnit);
38 38 return *this;
39 39 }
40 40
41 41 ExpectedResults &setXAxisData(const QVector<QDateTime> &xAxisData)
42 42 {
43 43 m_XAxisData.clear();
44 44
45 45 // Converts QVector<QDateTime> to QVector<double>
46 46 std::transform(xAxisData.cbegin(), xAxisData.cend(), std::back_inserter(m_XAxisData),
47 47 [](const auto &dateTime) { return dateTime.toMSecsSinceEpoch() / 1000.; });
48 48
49 49 return *this;
50 50 }
51 51
52 52 ExpectedResults &setValuesUnit(Unit valuesUnit)
53 53 {
54 54 m_ValuesUnit = std::move(valuesUnit);
55 55 return *this;
56 56 }
57 57
58 58 ExpectedResults &setValuesData(QVector<double> valuesData)
59 59 {
60 60 m_ValuesData.clear();
61 61 m_ValuesData.push_back(std::move(valuesData));
62 62 return *this;
63 63 }
64 64
65 65 ExpectedResults &setValuesData(QVector<QVector<double> > valuesData)
66 66 {
67 67 m_ValuesData = std::move(valuesData);
68 68 return *this;
69 69 }
70 70
71 71 ExpectedResults &setYAxisEnabled(bool yAxisEnabled)
72 72 {
73 73 m_YAxisEnabled = yAxisEnabled;
74 74 return *this;
75 75 }
76 76
77 77 ExpectedResults &setYAxisUnit(Unit yAxisUnit)
78 78 {
79 79 m_YAxisUnit = std::move(yAxisUnit);
80 80 return *this;
81 81 }
82 82
83 83 ExpectedResults &setYAxisData(QVector<double> yAxisData)
84 84 {
85 85 m_YAxisData = std::move(yAxisData);
86 86 return *this;
87 87 }
88 88
89 89 /**
90 90 * Validates a DataSeries compared to the expected results
91 91 * @param results the DataSeries to validate
92 92 */
93 93 void validate(std::shared_ptr<IDataSeries> results)
94 94 {
95 95 if (m_ParsingOK) {
96 96 auto dataSeries = dynamic_cast<T *>(results.get());
97 97 if (dataSeries == nullptr) {
98 98
99 99 // No unit detected, parsink ok but data is nullptr
100 100 // TODO, improve the test to verify that the data is null
101 101 return;
102 102 }
103 103
104 104 // Checks units
105 105 QVERIFY(dataSeries->xAxisUnit() == m_XAxisUnit);
106 106 QVERIFY(dataSeries->valuesUnit() == m_ValuesUnit);
107 107
108 108 auto verifyRange = [dataSeries](const auto &expectedData, const auto &equalFun) {
109 109 QVERIFY(std::equal(dataSeries->cbegin(), dataSeries->cend(), expectedData.cbegin(),
110 110 expectedData.cend(),
111 111 [&equalFun](const auto &dataSeriesIt, const auto &expectedX) {
112 112 return equalFun(dataSeriesIt, expectedX);
113 113 }));
114 114 };
115 115
116 116 // Checks x-axis data
117 117 verifyRange(m_XAxisData, [](const auto &seriesIt, const auto &value) {
118 118 return seriesIt.x() == value;
119 119 });
120 120
121 121 // Checks values data of each component
122 122 for (auto i = 0; i < m_ValuesData.size(); ++i) {
123 123 verifyRange(m_ValuesData.at(i), [i](const auto &seriesIt, const auto &value) {
124 124 auto itValue = seriesIt.value(i);
125 125 return (std::isnan(itValue) && std::isnan(value)) || seriesIt.value(i) == value;
126 126 });
127 127 }
128 128
129 129 // Checks y-axis (if defined)
130 130 auto yAxis = dataSeries->yAxis();
131 131 QCOMPARE(yAxis.isDefined(), m_YAxisEnabled);
132 132
133 133 if (m_YAxisEnabled) {
134 134 // Unit
135 135 QCOMPARE(yAxis.unit(), m_YAxisUnit);
136 136
137 137 // Data
138 138 auto yAxisSize = yAxis.size();
139 139 QCOMPARE(yAxisSize, m_YAxisData.size());
140 140 for (auto i = 0; i < yAxisSize; ++i) {
141 141 QCOMPARE(yAxis.at(i), m_YAxisData.at(i));
142 142 }
143 143 }
144 144 }
145 145 else {
146 146 QVERIFY(results == nullptr);
147 147 }
148 148 }
149 149
150 150 // Parsing was successfully completed
151 151 bool m_ParsingOK{false};
152 152 // Expected x-axis unit
153 153 Unit m_XAxisUnit{};
154 154 // Expected x-axis data
155 155 QVector<double> m_XAxisData{};
156 156 // Expected values unit
157 157 Unit m_ValuesUnit{};
158 158 // Expected values data
159 159 QVector<QVector<double> > m_ValuesData{};
160 160 // Expected data series has y-axis
161 161 bool m_YAxisEnabled{false};
162 162 // Expected y-axis unit (if axis defined)
163 163 Unit m_YAxisUnit{};
164 164 // Expected y-axis data (if axis defined)
165 165 QVector<double> m_YAxisData{};
166 166 };
167 167
168 168 } // namespace
169 169
170 170 Q_DECLARE_METATYPE(ExpectedResults<ScalarSeries>)
171 171 Q_DECLARE_METATYPE(ExpectedResults<SpectrogramSeries>)
172 172 Q_DECLARE_METATYPE(ExpectedResults<VectorSeries>)
173 173
174 174 class TestAmdaResultParser : public QObject {
175 175 Q_OBJECT
176 176 private:
177 177 template <typename T>
178 178 void testReadDataStructure()
179 179 {
180 180 // ////////////// //
181 181 // Test structure //
182 182 // ////////////// //
183 183
184 184 // Name of TXT file to read
185 185 QTest::addColumn<QString>("inputFileName");
186 186 // Expected results
187 187 QTest::addColumn<ExpectedResults<T> >("expectedResults");
188 188 }
189 189
190 190 template <typename T>
191 191 void testRead(AmdaResultParser::ValueType valueType)
192 192 {
193 193 QFETCH(QString, inputFileName);
194 194 QFETCH(ExpectedResults<T>, expectedResults);
195 195
196 196 // Parses file
197 197 auto filePath = inputFilePath(inputFileName);
198 198 auto results = AmdaResultParser::readTxt(filePath, valueType);
199 199
200 200 // ///////////////// //
201 201 // Validates results //
202 202 // ///////////////// //
203 203 expectedResults.validate(results);
204 204 }
205 205
206 206 private slots:
207 207 /// Input test data
208 208 /// @sa testReadScalarTxt()
209 209 void testReadScalarTxt_data();
210 210
211 211 /// Tests parsing scalar series of a TXT file
212 212 void testReadScalarTxt();
213 213
214 214 /// Input test data
215 215 /// @sa testReadSpectrogramTxt()
216 216 void testReadSpectrogramTxt_data();
217 217
218 218 /// Tests parsing spectrogram series of a TXT file
219 219 void testReadSpectrogramTxt();
220 220
221 221 /// Input test data
222 222 /// @sa testReadVectorTxt()
223 223 void testReadVectorTxt_data();
224 224
225 225 /// Tests parsing vector series of a TXT file
226 226 void testReadVectorTxt();
227 227 };
228 228
229 229 void TestAmdaResultParser::testReadScalarTxt_data()
230 230 {
231 231 testReadDataStructure<ScalarSeries>();
232 232
233 233 // ////////// //
234 234 // Test cases //
235 235 // ////////// //
236 236
237 237 // Valid files
238 238 QTest::newRow("Valid file")
239 239 << QStringLiteral("ValidScalar1.txt")
240 240 << ExpectedResults<ScalarSeries>{}
241 241 .setParsingOK(true)
242 242 .setXAxisUnit(Unit{"nT", true})
243 243 .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30),
244 244 dateTime(2013, 9, 23, 9, 2, 30), dateTime(2013, 9, 23, 9, 3, 30),
245 245 dateTime(2013, 9, 23, 9, 4, 30), dateTime(2013, 9, 23, 9, 5, 30),
246 246 dateTime(2013, 9, 23, 9, 6, 30), dateTime(2013, 9, 23, 9, 7, 30),
247 247 dateTime(2013, 9, 23, 9, 8, 30), dateTime(2013, 9, 23, 9, 9, 30)})
248 248 .setValuesData({-2.83950, -2.71850, -2.52150, -2.57633, -2.58050, -2.48325, -2.63025,
249 249 -2.55800, -2.43250, -2.42200});
250 250
251 251 QTest::newRow("Valid file (value of first line is invalid but it is converted to NaN")
252 252 << QStringLiteral("WrongValue.txt")
253 253 << ExpectedResults<ScalarSeries>{}
254 254 .setParsingOK(true)
255 255 .setXAxisUnit(Unit{"nT", true})
256 256 .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30),
257 257 dateTime(2013, 9, 23, 9, 2, 30)})
258 258 .setValuesData({std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150});
259 259
260 260 QTest::newRow("Valid file that contains NaN values")
261 261 << QStringLiteral("NaNValue.txt")
262 262 << ExpectedResults<ScalarSeries>{}
263 263 .setParsingOK(true)
264 264 .setXAxisUnit(Unit{("nT"), true})
265 265 .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30),
266 266 dateTime(2013, 9, 23, 9, 2, 30)})
267 267 .setValuesData({std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150});
268 268
269 269 // Valid files but with some invalid lines (wrong unit, wrong values, etc.)
270 270 QTest::newRow("No unit file")
271 271 << QStringLiteral("NoUnit.txt")
272 272 << ExpectedResults<ScalarSeries>{}.setParsingOK(true).setXAxisUnit(Unit{"", true});
273 273
274 274 QTest::newRow("Wrong unit file")
275 275 << QStringLiteral("WrongUnit.txt")
276 276 << ExpectedResults<ScalarSeries>{}
277 277 .setParsingOK(true)
278 278 .setXAxisUnit(Unit{"", true})
279 279 .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30),
280 280 dateTime(2013, 9, 23, 9, 2, 30)})
281 281 .setValuesData({-2.83950, -2.71850, -2.52150});
282 282
283 283 QTest::newRow("Wrong results file (date of first line is invalid")
284 284 << QStringLiteral("WrongDate.txt")
285 285 << ExpectedResults<ScalarSeries>{}
286 286 .setParsingOK(true)
287 287 .setXAxisUnit(Unit{"nT", true})
288 288 .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)})
289 289 .setValuesData({-2.71850, -2.52150});
290 290
291 291 QTest::newRow("Wrong results file (too many values for first line")
292 292 << QStringLiteral("TooManyValues.txt")
293 293 << ExpectedResults<ScalarSeries>{}
294 294 .setParsingOK(true)
295 295 .setXAxisUnit(Unit{"nT", true})
296 296 .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)})
297 297 .setValuesData({-2.71850, -2.52150});
298 298
299 299 QTest::newRow("Wrong results file (x of first line is NaN")
300 300 << QStringLiteral("NaNX.txt")
301 301 << ExpectedResults<ScalarSeries>{}
302 302 .setParsingOK(true)
303 303 .setXAxisUnit(Unit{"nT", true})
304 304 .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)})
305 305 .setValuesData({-2.71850, -2.52150});
306 306
307 307 QTest::newRow("Invalid file type (vector)")
308 308 << QStringLiteral("ValidVector1.txt")
309 309 << ExpectedResults<ScalarSeries>{}.setParsingOK(true).setXAxisUnit(Unit{"nT", true});
310 310
311 311 // Invalid files
312 312 QTest::newRow("Invalid file (unexisting file)")
313 313 << QStringLiteral("UnexistingFile.txt")
314 314 << ExpectedResults<ScalarSeries>{}.setParsingOK(false);
315 315
316 316 QTest::newRow("Invalid file (file not found on server)")
317 317 << QStringLiteral("FileNotFound.txt")
318 318 << ExpectedResults<ScalarSeries>{}.setParsingOK(false);
319 319 }
320 320
321 321 void TestAmdaResultParser::testReadScalarTxt()
322 322 {
323 323 testRead<ScalarSeries>(AmdaResultParser::ValueType::SCALAR);
324 324 }
325 325
326 326 void TestAmdaResultParser::testReadSpectrogramTxt_data()
327 327 {
328 328 testReadDataStructure<SpectrogramSeries>();
329 329
330 330 // ////////// //
331 331 // Test cases //
332 332 // ////////// //
333 333
334 334 // Valid files
335 335 QTest::newRow("Valid file (three bands)")
336 336 << QStringLiteral("spectro/ValidSpectrogram1.txt")
337 337 << ExpectedResults<SpectrogramSeries>{}
338 338 .setParsingOK(true)
339 339 .setXAxisUnit(Unit{"t", true})
340 340 .setXAxisData({dateTime(2012, 11, 6, 9, 14, 35), dateTime(2012, 11, 6, 9, 16, 10),
341 341 dateTime(2012, 11, 6, 9, 17, 45), dateTime(2012, 11, 6, 9, 19, 20),
342 342 dateTime(2012, 11, 6, 9, 20, 55)})
343 343 .setYAxisEnabled(true)
344 344 .setYAxisUnit(Unit{"eV"})
345 345 .setYAxisData({5.75, 7.6, 10.05}) // middle of the intervals of each band
346 346 .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"})
347 347 .setValuesData(QVector<QVector<double> >{
348 348 {16313.780, 12631.465, 8223.368, 27595.301, 12820.613},
349 349 {15405.838, 11957.925, 15026.249, 25617.533, 11179.109},
350 350 {8946.475, 18133.158, 10875.621, 24051.619, 19283.221}});
351 351
352 352 auto fourBandsResult
353 353 = ExpectedResults<SpectrogramSeries>{}
354 354 .setParsingOK(true)
355 355 .setXAxisUnit(Unit{"t", true})
356 356 .setXAxisData({dateTime(2012, 11, 6, 9, 14, 35), dateTime(2012, 11, 6, 9, 16, 10),
357 357 dateTime(2012, 11, 6, 9, 17, 45), dateTime(2012, 11, 6, 9, 19, 20),
358 358 dateTime(2012, 11, 6, 9, 20, 55)})
359 359 .setYAxisEnabled(true)
360 360 .setYAxisUnit(Unit{"eV"})
361 361 .setYAxisData({5.75, 7.6, 10.05, 13.}) // middle of the intervals of each band
362 362 .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"})
363 363 .setValuesData(QVector<QVector<double> >{
364 364 {16313.780, 12631.465, 8223.368, 27595.301, 12820.613},
365 365 {15405.838, 11957.925, 15026.249, 25617.533, 11179.109},
366 366 {8946.475, 18133.158, 10875.621, 24051.619, 19283.221},
367 367 {20907.664, 32076.725, 13008.381, 13142.759, 23226.998}});
368 368
369 369 QTest::newRow("Valid file (four bands)")
370 370 << QStringLiteral("spectro/ValidSpectrogram2.txt") << fourBandsResult;
371 371 QTest::newRow("Valid file (four unsorted bands)")
372 372 << QStringLiteral("spectro/ValidSpectrogram3.txt")
373 373 << fourBandsResult; // Bands and values are sorted
374 374
375 375 auto nan = std::numeric_limits<double>::quiet_NaN();
376 376
377 377 auto nanValuesResult
378 378 = ExpectedResults<SpectrogramSeries>{}
379 379 .setParsingOK(true)
380 380 .setXAxisUnit(Unit{"t", true})
381 381 .setXAxisData({dateTime(2012, 11, 6, 9, 14, 35), dateTime(2012, 11, 6, 9, 16, 10),
382 382 dateTime(2012, 11, 6, 9, 17, 45), dateTime(2012, 11, 6, 9, 19, 20),
383 383 dateTime(2012, 11, 6, 9, 20, 55)})
384 384 .setYAxisEnabled(true)
385 385 .setYAxisUnit(Unit{"eV"})
386 386 .setYAxisData({5.75, 7.6, 10.05, 13.}) // middle of the intervals of each band
387 387 .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"})
388 388 .setValuesData(
389 389 QVector<QVector<double> >{{nan, 12631.465, 8223.368, 27595.301, 12820.613},
390 390 {15405.838, nan, nan, 25617.533, 11179.109},
391 391 {8946.475, 18133.158, 10875.621, 24051.619, 19283.221},
392 392 {nan, nan, nan, nan, nan}});
393 393
394 394 QTest::newRow("Valid file (containing NaN values)")
395 395 << QStringLiteral("spectro/ValidSpectrogramNaNValues.txt") << nanValuesResult;
396 396 QTest::newRow("Valid file (containing fill values)")
397 397 << QStringLiteral("spectro/ValidSpectrogramFillValues.txt")
398 398 << nanValuesResult; // Fill values are replaced by NaN values in the data series
399 399
400 400 QTest::newRow("Valid file (containing data holes, resolution = 3 minutes)")
401 401 << QStringLiteral("spectro/ValidSpectrogramDataHoles.txt")
402 402 << ExpectedResults<SpectrogramSeries>{}
403 403 .setParsingOK(true)
404 404 .setXAxisUnit(Unit{"t", true})
405 405 .setXAxisData({dateTime(2011, 12, 10, 12, 10, 54), //
406 406 dateTime(2011, 12, 10, 12, 13, 54), // Data hole
407 407 dateTime(2011, 12, 10, 12, 16, 54), // Data hole
408 408 dateTime(2011, 12, 10, 12, 17, 23), //
409 409 dateTime(2011, 12, 10, 12, 20, 23), // Data hole
410 410 dateTime(2011, 12, 10, 12, 23, 23), // Data hole
411 411 dateTime(2011, 12, 10, 12, 23, 51), //
412 412 dateTime(2011, 12, 10, 12, 26, 51), // Data hole
413 413 dateTime(2011, 12, 10, 12, 29, 51), // Data hole
414 414 dateTime(2011, 12, 10, 12, 30, 19), //
415 415 dateTime(2011, 12, 10, 12, 33, 19), // Data hole
416 416 dateTime(2011, 12, 10, 12, 35, 04), //
417 417 dateTime(2011, 12, 10, 12, 36, 41), //
418 418 dateTime(2011, 12, 10, 12, 38, 18), //
419 419 dateTime(2011, 12, 10, 12, 39, 55)})
420 420 .setYAxisEnabled(true)
421 421 .setYAxisUnit(Unit{"eV"})
422 422 .setYAxisData({16485.85, 20996.1}) // middle of the intervals of each band
423 423 .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"})
424 424 .setValuesData(QVector<QVector<double> >{{2577578.000, //
425 425 nan, // Data hole
426 426 nan, // Data hole
427 427 2314121.500, //
428 428 nan, // Data hole
429 429 nan, // Data hole
430 430 2063608.750, //
431 431 nan, // Data hole
432 432 nan, // Data hole
433 433 2234525.500, //
434 434 nan, // Data hole
435 435 1670215.250, //
436 436 1689243.250, //
437 437 1654617.125, //
438 438 1504983.750},
439 439 {2336016.000, //
440 440 nan, // Data hole
441 441 nan, // Data hole
442 442 1712093.125, //
443 443 nan, // Data hole
444 444 nan, // Data hole
445 445 1614491.625, //
446 446 nan, // Data hole
447 447 nan, // Data hole
448 448 1764516.500, //
449 449 nan, // Data hole
450 450 1688078.500, //
451 451 1743183.500, //
452 452 1733603.250, //
453 453 1708356.500}});
454 454
455 QTest::newRow(
456 "Valid file (containing data holes at the beginning and the end, resolution = 4 minutes)")
457 << QStringLiteral("spectro/ValidSpectrogramDataHoles2.txt")
458 << ExpectedResults<SpectrogramSeries>{}
459 .setParsingOK(true)
460 .setXAxisUnit(Unit{"t", true})
461 .setXAxisData({
462 dateTime(2011, 12, 10, 12, 2, 54), // Data hole
463 dateTime(2011, 12, 10, 12, 6, 54), // Data hole
464 dateTime(2011, 12, 10, 12, 10, 54), //
465 dateTime(2011, 12, 10, 12, 14, 54), // Data hole
466 dateTime(2011, 12, 10, 12, 17, 23), //
467 dateTime(2011, 12, 10, 12, 21, 23), // Data hole
468 dateTime(2011, 12, 10, 12, 23, 51), //
469 dateTime(2011, 12, 10, 12, 27, 51), // Data hole
470 dateTime(2011, 12, 10, 12, 30, 19), //
471 dateTime(2011, 12, 10, 12, 34, 19), // Data hole
472 dateTime(2011, 12, 10, 12, 35, 04), //
473 dateTime(2011, 12, 10, 12, 36, 41), //
474 dateTime(2011, 12, 10, 12, 38, 18), //
475 dateTime(2011, 12, 10, 12, 39, 55),
476 dateTime(2011, 12, 10, 12, 43, 55), // Data hole
477 dateTime(2011, 12, 10, 12, 47, 55), // Data hole
478 dateTime(2011, 12, 10, 12, 51, 55), // Data hole
479 dateTime(2011, 12, 10, 12, 55, 55), // Data hole
480 dateTime(2011, 12, 10, 12, 59, 55) // Data hole
481 })
482 .setYAxisEnabled(true)
483 .setYAxisUnit(Unit{"eV"})
484 .setYAxisData({16485.85, 20996.1}) // middle of the intervals of each band
485 .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"})
486 .setValuesData(QVector<QVector<double> >{{
487 nan, // Data hole
488 nan, // Data hole
489 2577578.000, //
490 nan, // Data hole
491 2314121.500, //
492 nan, // Data hole
493 2063608.750, //
494 nan, // Data hole
495 2234525.500, //
496 nan, // Data hole
497 1670215.250, //
498 1689243.250, //
499 1654617.125, //
500 1504983.750, //
501 nan, // Data hole
502 nan, // Data hole
503 nan, // Data hole
504 nan, // Data hole
505 nan // Data hole
506 },
507 {
508 nan, // Data hole
509 nan, // Data hole
510 2336016.000, //
511 nan, // Data hole
512 1712093.125, //
513 nan, // Data hole
514 1614491.625, //
515 nan, // Data hole
516 1764516.500, //
517 nan, // Data hole
518 1688078.500, //
519 1743183.500, //
520 1733603.250, //
521 1708356.500, //
522 nan, // Data hole
523 nan, // Data hole
524 nan, // Data hole
525 nan, // Data hole
526 nan // Data hole
527 }});
528
455 529 // Invalid files
456 530 QTest::newRow("Invalid file (inconsistent bands)")
457 531 << QStringLiteral("spectro/InvalidSpectrogramWrongBands.txt")
458 532 << ExpectedResults<SpectrogramSeries>{}.setParsingOK(false);
459 533 }
460 534
461 535 void TestAmdaResultParser::testReadSpectrogramTxt()
462 536 {
463 537 testRead<SpectrogramSeries>(AmdaResultParser::ValueType::SPECTROGRAM);
464 538 }
465 539
466 540 void TestAmdaResultParser::testReadVectorTxt_data()
467 541 {
468 542 testReadDataStructure<VectorSeries>();
469 543
470 544 // ////////// //
471 545 // Test cases //
472 546 // ////////// //
473 547
474 548 // Valid files
475 549 QTest::newRow("Valid file")
476 550 << QStringLiteral("ValidVector1.txt")
477 551 << ExpectedResults<VectorSeries>{}
478 552 .setParsingOK(true)
479 553 .setXAxisUnit(Unit{"nT", true})
480 554 .setXAxisData({dateTime(2013, 7, 2, 9, 13, 50), dateTime(2013, 7, 2, 9, 14, 6),
481 555 dateTime(2013, 7, 2, 9, 14, 22), dateTime(2013, 7, 2, 9, 14, 38),
482 556 dateTime(2013, 7, 2, 9, 14, 54), dateTime(2013, 7, 2, 9, 15, 10),
483 557 dateTime(2013, 7, 2, 9, 15, 26), dateTime(2013, 7, 2, 9, 15, 42),
484 558 dateTime(2013, 7, 2, 9, 15, 58), dateTime(2013, 7, 2, 9, 16, 14)})
485 559 .setValuesData(
486 560 {{-0.332, -1.011, -1.457, -1.293, -1.217, -1.443, -1.278, -1.202, -1.22, -1.259},
487 561 {3.206, 2.999, 2.785, 2.736, 2.612, 2.564, 2.892, 2.862, 2.859, 2.764},
488 562 {0.058, 0.496, 1.018, 1.485, 1.662, 1.505, 1.168, 1.244, 1.15, 1.358}});
489 563
490 564 // Valid files but with some invalid lines (wrong unit, wrong values, etc.)
491 565 QTest::newRow("Invalid file type (scalar)")
492 566 << QStringLiteral("ValidScalar1.txt")
493 567 << ExpectedResults<VectorSeries>{}
494 568 .setParsingOK(true)
495 569 .setXAxisUnit(Unit{"nT", true})
496 570 .setXAxisData({})
497 571 .setValuesData(QVector<QVector<double> >{{}, {}, {}});
498 572 }
499 573
500 574 void TestAmdaResultParser::testReadVectorTxt()
501 575 {
502 576 testRead<VectorSeries>(AmdaResultParser::ValueType::VECTOR);
503 577 }
504 578
505 579 QTEST_MAIN(TestAmdaResultParser)
506 580 #include "TestAmdaResultParser.moc"
General Comments 0
You need to be logged in to leave comments. Login now