source: ntrip/trunk/BNC/src/rinex/reqcanalyze.cpp@ 4676

Last change on this file since 4676 was 4676, checked in by mervart, 12 years ago
File size: 17.4 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: t_reqcAnalyze
30 *
31 * Purpose: Analyze RINEX Files
32 *
33 * Author: L. Mervart
34 *
35 * Created: 11-Apr-2012
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42#include <iomanip>
43#include <qwt_plot_renderer.h>
44
45#include "reqcanalyze.h"
46#include "bncapp.h"
47#include "bncsettings.h"
48#include "reqcedit.h"
49#include "bncutils.h"
50#include "bncpostprocess.h"
51#include "graphwin.h"
52#include "polarplot.h"
53#include "availplot.h"
54#include "eleplot.h"
55#include "dopplot.h"
56
57using namespace std;
58
59const double SLIPTRESH = 5.0; // cycle-slip threshold (meters)
60
61// Constructor
62////////////////////////////////////////////////////////////////////////////
63t_reqcAnalyze::t_reqcAnalyze(QObject* parent) : QThread(parent) {
64
65 bncSettings settings;
66
67 _logFileName = settings.value("reqcOutLogFile").toString(); expandEnvVar(_logFileName);
68 _logFile = 0;
69 _log = 0;
70 _obsFileNames = settings.value("reqcObsFile").toString().split(",", QString::SkipEmptyParts);
71 _navFileNames = settings.value("reqcNavFile").toString().split(",", QString::SkipEmptyParts);
72
73 _currEpo = 0;
74
75 connect(this, SIGNAL(dspSkyPlot(const QString&,
76 const QByteArray&,
77 QVector<t_polarPoint*>*,
78 const QByteArray&,
79 QVector<t_polarPoint*>*,
80 const QByteArray&, double)),
81 this, SLOT(slotDspSkyPlot(const QString&,
82 const QByteArray&,
83 QVector<t_polarPoint*>*,
84 const QByteArray&,
85 QVector<t_polarPoint*>*,
86 const QByteArray&, double)));
87
88 connect(this, SIGNAL(dspAvailPlot(const QString&, const QByteArray&)),
89 this, SLOT(slotDspAvailPlot(const QString&, const QByteArray&)));
90}
91
92// Destructor
93////////////////////////////////////////////////////////////////////////////
94t_reqcAnalyze::~t_reqcAnalyze() {
95 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
96 delete _rnxObsFiles[ii];
97 }
98 for (int ii = 0; ii < _ephs.size(); ii++) {
99 delete _ephs[ii];
100 }
101 delete _log; _log = 0;
102 delete _logFile; _logFile = 0;
103 bncApp* app = (bncApp*) qApp;
104 if ( app->mode() != bncApp::interactive) {
105 app->exit(0);
106 }
107}
108
109//
110////////////////////////////////////////////////////////////////////////////
111void t_reqcAnalyze::slotDspSkyPlot(const QString& fileName,
112 const QByteArray& title1,
113 QVector<t_polarPoint*>* data1,
114 const QByteArray& title2,
115 QVector<t_polarPoint*>* data2,
116 const QByteArray& scaleTitle,
117 double maxValue) {
118
119 bncApp* app = dynamic_cast<bncApp*>(qApp);
120 if (app->GUIenabled()) {
121
122 if (maxValue == 0.0) {
123 if (data1) {
124 for (int ii = 0; ii < data1->size(); ii++) {
125 double val = data1->at(ii)->_value;
126 if (maxValue < val) {
127 maxValue = val;
128 }
129 }
130 }
131 if (data2) {
132 for (int ii = 0; ii < data2->size(); ii++) {
133 double val = data2->at(ii)->_value;
134 if (maxValue < val) {
135 maxValue = val;
136 }
137 }
138 }
139 }
140
141 QwtInterval scaleInterval(0.0, maxValue);
142
143 QVector<QWidget*> plots;
144 if (data1) {
145 t_polarPlot* plot1 = new t_polarPlot(QwtText(title1), scaleInterval,
146 app->mainWindow());
147 plot1->addCurve(data1);
148 plots << plot1;
149 }
150 if (data2) {
151 t_polarPlot* plot2 = new t_polarPlot(QwtText(title2), scaleInterval,
152 app->mainWindow());
153 plot2->addCurve(data2);
154 plots << plot2;
155 }
156
157 t_graphWin* graphWin = new t_graphWin(0, fileName, plots,
158 &scaleTitle, &scaleInterval);
159
160 graphWin->show();
161
162 bncSettings settings;
163 QString dirName = settings.value("reqcPlotDir").toString();
164 if (!dirName.isEmpty()) {
165 QByteArray ext = scaleTitle.isEmpty() ? "_S.png" : "_M.png";
166 graphWin->savePNG(dirName, ext);
167 }
168 }
169}
170
171//
172////////////////////////////////////////////////////////////////////////////
173void t_reqcAnalyze::run() {
174
175 // Open Log File
176 // -------------
177 _logFile = new QFile(_logFileName);
178 if (_logFile->open(QIODevice::WriteOnly | QIODevice::Text)) {
179 _log = new QTextStream();
180 _log->setDevice(_logFile);
181 }
182
183 // Initialize RINEX Observation Files
184 // ----------------------------------
185 t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles, _log);
186
187 // Read Ephemerides
188 // ----------------
189 t_reqcEdit::readEphemerides(_navFileNames, _ephs);
190
191 // Loop over all RINEX Files
192 // -------------------------
193 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
194 analyzeFile(_rnxObsFiles[ii]);
195 }
196
197 // Exit
198 // ----
199 emit finished();
200 deleteLater();
201}
202
203//
204////////////////////////////////////////////////////////////////////////////
205void t_reqcAnalyze::analyzeFile(t_rnxObsFile* obsFile) {
206
207 if (_log) {
208 *_log << "\nAnalyze File\n"
209 << "------------\n"
210 << obsFile->fileName().toAscii().data() << endl << endl;
211 }
212
213 _allObsMap.clear();
214 _availDataMap.clear();
215
216 // A priori Coordinates
217 // --------------------
218 ColumnVector xyz = obsFile->xyz();
219
220 // Loop over all Epochs
221 // --------------------
222 try {
223 unsigned iEpo = 0;
224 while ( (_currEpo = obsFile->nextEpoch()) != 0) {
225
226 // Loop over all satellites
227 // ------------------------
228 for (unsigned iObs = 0; iObs < _currEpo->rnxSat.size(); iObs++) {
229 const t_rnxObsFile::t_rnxSat& rnxSat = _currEpo->rnxSat[iObs];
230 t_obs obs;
231 t_postProcessing::setObsFromRnx(obsFile, _currEpo, rnxSat, obs);
232
233 if (obs.satSys == 'R') {
234 // TODO: set channel number
235 }
236
237 QString prn = QString("%1%2").arg(obs.satSys)
238 .arg(obs.satNum, 2, 10, QChar('0'));
239
240 _allObsMap[prn].addObs(obs);
241
242 prepareObsStat(iEpo, obsFile->interval());
243 iEpo++;
244 }
245
246 } // while (_currEpo)
247 }
248 catch (QString str) {
249 if (_log) {
250 *_log << "Exception " << str << endl;
251 }
252 else {
253 qDebug() << str;
254 }
255 return;
256 }
257
258 // Analyze the Multipath
259 // ---------------------
260 QVector<t_polarPoint*>* dataMP1 = new QVector<t_polarPoint*>;
261 QVector<t_polarPoint*>* dataMP2 = new QVector<t_polarPoint*>;
262 QVector<t_polarPoint*>* dataSNR1 = new QVector<t_polarPoint*>;
263 QVector<t_polarPoint*>* dataSNR2 = new QVector<t_polarPoint*>;
264
265 QMutableMapIterator<QString, t_allObs> it(_allObsMap);
266 while (it.hasNext()) {
267 it.next();
268 QString prn = it.key();
269 preparePlotData(prn, xyz, obsFile->interval(),
270 dataMP1, dataMP2, dataSNR1, dataSNR2);
271 }
272
273 emit dspSkyPlot(obsFile->fileName(), "MP1", dataMP1, "MP2", dataMP2,
274 "Meters", 2.0);
275
276 emit dspSkyPlot(obsFile->fileName(), "SNR1", dataSNR1, "SNR2", dataSNR2,
277 "", 9.0);
278
279 QFileInfo fileInfo(obsFile->fileName());
280 QByteArray title = fileInfo.fileName().toAscii();
281
282 emit dspAvailPlot(obsFile->fileName(), title);
283
284 if (_log) {
285 _log->flush();
286 }
287}
288
289//
290////////////////////////////////////////////////////////////////////////////
291void t_reqcAnalyze::t_allObs::addObs(const t_obs& obs) {
292
293 t_oneObs* newObs = new t_oneObs(obs.GPSWeek, obs.GPSWeeks);
294 bool okFlag = false;
295
296 // Availability and Slip Flags
297 // ---------------------------
298 double L1 = obs.measdata("L1", 3.0);
299 if (L1 != 0) {
300 newObs->_hasL1 = true;
301 }
302 double L2 = obs.measdata("L2", 3.0);
303 if (L2 != 0) {
304 newObs->_hasL2 = true;
305 }
306 if (obs.slipL1) {
307 newObs->_slipL1 = true;
308 }
309 if (obs.slipL2) {
310 newObs->_slipL2 = true;
311 }
312
313 // Compute the Multipath
314 // ----------------------
315 if (L1 != 0.0 && L2 != 0.0) {
316 double f1 = t_CST::f1(obs.satSys, obs.slotNum);
317 double f2 = t_CST::f2(obs.satSys, obs.slotNum);
318
319 L1 = L1 * t_CST::c / f1;
320 L2 = L2 * t_CST::c / f2;
321
322 double P1 = obs.measdata("C1", 3.0);
323 if (P1 != 0.0) {
324 newObs->_MP1 = P1 - L1 - 2.0*f2*f2/(f1*f1-f2*f2) * (L1 - L2);
325 okFlag = true;
326 }
327 double P2 = obs.measdata("C2", 3.0);
328 if (P2 != 0.0) {
329 newObs->_MP2 = P2 - L2 - 2.0*f1*f1/(f1*f1-f2*f2) * (L1 - L2);
330 okFlag = true;
331 }
332 }
333
334 // Signal-to-Noise
335 // ---------------
336 double S1 = obs.measdata("S1", 3.0);
337 if (S1 != 0.0) {
338 newObs->_SNR1 = floor(S1/6);
339 if (newObs->_SNR1 > 9.0) {
340 newObs->_SNR1 = 9.0;
341 }
342 if (newObs->_SNR1 < 1.0) {
343 newObs->_SNR1 = 1.0;
344 }
345 okFlag = true;
346 }
347 else {
348 if (obs.snrL1 > 0) {
349 newObs->_SNR1 = obs.snrL1;
350 okFlag = true;
351 }
352 }
353 double S2 = obs.measdata("S2", 3.0);
354 if (S2 != 0.0) {
355 newObs->_SNR2 = floor(S2/6);
356 if (newObs->_SNR2 > 9.0) {
357 newObs->_SNR2 = 9.0;
358 }
359 if (newObs->_SNR2 < 1.0) {
360 newObs->_SNR2 = 1.0;
361 }
362 okFlag = true;
363 }
364 else {
365 if (obs.snrL2 > 0) {
366 newObs->_SNR2 = obs.snrL2;
367 okFlag = true;
368 }
369 }
370
371 // Remember the Observation
372 // ------------------------
373 if (okFlag) {
374 _oneObsVec << newObs;
375 }
376 else {
377 delete newObs;
378 }
379}
380
381//
382////////////////////////////////////////////////////////////////////////////
383void t_reqcAnalyze::prepareObsStat(unsigned iEpo, double obsInterval) {
384 const int numEpo = int(600.0 / obsInterval); // # epochs in one chunk (10 min)
385 if (iEpo % numEpo == 0) {
386 double mjdX24 = _currEpo->tt.mjddec() * 24.0;
387 if (iEpo != 0) {
388 _obsStat._mjdX24 << mjdX24;
389 _obsStat._numSat << _obsStat._numSat.last();
390 }
391 _obsStat._mjdX24 << mjdX24;
392 _obsStat._numSat << _currEpo->rnxSat.size();
393 }
394}
395
396//
397////////////////////////////////////////////////////////////////////////////
398void t_reqcAnalyze::preparePlotData(const QString& prn, const ColumnVector& xyz,
399 double obsInterval,
400 QVector<t_polarPoint*>* dataMP1,
401 QVector<t_polarPoint*>* dataMP2,
402 QVector<t_polarPoint*>* dataSNR1,
403 QVector<t_polarPoint*>* dataSNR2) {
404
405 const int chunkStep = int( 30.0 / obsInterval); // chunk step (30 sec)
406 const int numEpo = int(600.0 / obsInterval); // # epochs in one chunk (10 min)
407
408 t_allObs& allObs = _allObsMap[prn];
409
410 // Loop over all Chunks of Data
411 // ----------------------------
412 for (int chunkStart = 0; chunkStart + numEpo < allObs._oneObsVec.size();
413 chunkStart += chunkStep) {
414
415 // Chunk-Specific Variables
416 // ------------------------
417 bncTime currTime;
418 bncTime prevTime;
419 bncTime chunkStartTime;
420 double mjdX24 = 0.0;
421 bool availL1 = false;
422 bool availL2 = false;
423 bool gapL1 = false;
424 bool gapL2 = false;
425 bool slipL1 = false;
426 bool slipL2 = false;
427 bool slipMP = false;
428 double meanMP1 = 0.0;
429 double meanMP2 = 0.0;
430 double minSNR1 = 0.0;
431 double minSNR2 = 0.0;
432 double aziDeg = 0.0;
433 double zenDeg = 0.0;
434 bool zenFlag = false;
435
436 // Loop over all Epochs within one Chunk of Data
437 // ---------------------------------------------
438 for (int ii = 0; ii < numEpo; ii++) {
439 int iEpo = chunkStart + ii;
440 const t_oneObs* oneObs = allObs._oneObsVec[iEpo];
441
442 currTime.set(oneObs->_GPSWeek, oneObs->_GPSWeeks);
443
444 // Compute the Azimuth and Zenith Distance
445 // ---------------------------------------
446 if (ii == 0) {
447 chunkStartTime = currTime;
448 mjdX24 = chunkStartTime.mjddec() * 24.0;
449
450 if (xyz.size()) {
451 t_eph* eph = 0;
452 for (int ie = 0; ie < _ephs.size(); ie++) {
453 if (_ephs[ie]->prn() == prn) {
454 eph = _ephs[ie];
455 break;
456 }
457 }
458
459 if (eph) {
460 double xSat, ySat, zSat, clkSat;
461 eph->position(oneObs->_GPSWeek, oneObs->_GPSWeeks,
462 xSat, ySat, zSat, clkSat);
463
464 double rho, eleSat, azSat;
465 topos(xyz(1), xyz(2), xyz(3), xSat, ySat, zSat, rho, eleSat, azSat);
466
467 aziDeg = azSat * 180.0/M_PI;
468 zenDeg = 90.0 - eleSat * 180.0/M_PI;
469 zenFlag = true;
470 }
471 }
472 }
473
474 // Check Interval
475 // --------------
476 if (prevTime.valid()) {
477 double dt = currTime - prevTime;
478 if (dt != obsInterval) {
479 gapL1 = true;
480 gapL2 = true;
481 }
482 }
483 prevTime = currTime;
484
485 // Check L1 and L2 availability
486 // ----------------------------
487 if (oneObs->_hasL1) {
488 availL1 = true;
489 }
490 else {
491 gapL1 = true;
492 }
493 if (oneObs->_hasL2) {
494 availL2 = true;
495 }
496 else {
497 gapL2 = true;
498 }
499
500 // Check Minimal Signal-to-Noise Ratio
501 // -----------------------------------
502 if ( oneObs->_SNR1 > 0 && (minSNR1 == 0 || minSNR1 > oneObs->_SNR1) ) {
503 minSNR1 = oneObs->_SNR1;
504 }
505 if ( oneObs->_SNR2 > 0 && (minSNR2 == 0 || minSNR2 > oneObs->_SNR2) ) {
506 minSNR2 = oneObs->_SNR2;
507 }
508
509 // Check Slip Flags
510 // ----------------
511 if (oneObs->_slipL1) {
512 slipL1 = true;
513 }
514 if (oneObs->_slipL2) {
515 slipL2 = true;
516 }
517
518 // Check Slip Threshold
519 // --------------------
520 if (ii > 0) {
521 double diff1 = oneObs->_MP1 - allObs._oneObsVec[iEpo-1]->_MP1;
522 double diff2 = oneObs->_MP2 - allObs._oneObsVec[iEpo-1]->_MP2;
523 if (fabs(diff1) > SLIPTRESH || fabs(diff2) > SLIPTRESH) {
524 slipMP = true;
525 }
526 }
527
528 meanMP1 += oneObs->_MP1;
529 meanMP2 += oneObs->_MP2;
530 }
531
532 // Availability Plot Data
533 // ----------------------
534 if (availL1) {
535 if (slipL1) {
536 _availDataMap[prn]._L1slip << mjdX24;
537 }
538 else if (gapL1) {
539 _availDataMap[prn]._L1gap << mjdX24;
540 }
541 else {
542 _availDataMap[prn]._L1ok << mjdX24;
543 }
544 }
545 if (availL2) {
546 if (slipL2) {
547 _availDataMap[prn]._L2slip << mjdX24;
548 }
549 else if (gapL2) {
550 _availDataMap[prn]._L2gap << mjdX24;
551 }
552 else {
553 _availDataMap[prn]._L2ok << mjdX24;
554 }
555 }
556 if (zenFlag) {
557 _availDataMap[prn]._eleTim << mjdX24;
558 _availDataMap[prn]._eleDeg << 90.0 - zenDeg;
559 }
560
561 // Signal-to-Noise Ration Plot Data
562 // --------------------------------
563 (*dataSNR1) << (new t_polarPoint(aziDeg, zenDeg, minSNR1));
564 (*dataSNR2) << (new t_polarPoint(aziDeg, zenDeg, minSNR2));
565
566 // Compute the Multipath
567 // ---------------------
568 if (!slipMP) {
569 meanMP1 /= numEpo;
570 meanMP2 /= numEpo;
571 double MP1 = 0.0;
572 double MP2 = 0.0;
573 for (int ii = 0; ii < numEpo; ii++) {
574 int iEpo = chunkStart + ii;
575 const t_oneObs* oneObs = allObs._oneObsVec[iEpo];
576 double diff1 = oneObs->_MP1 - meanMP1;
577 double diff2 = oneObs->_MP2 - meanMP2;
578 MP1 += diff1 * diff1;
579 MP2 += diff2 * diff2;
580 }
581 MP1 = sqrt(MP1 / (numEpo-1));
582 MP2 = sqrt(MP2 / (numEpo-1));
583 (*dataMP1) << (new t_polarPoint(aziDeg, zenDeg, MP1));
584 (*dataMP2) << (new t_polarPoint(aziDeg, zenDeg, MP2));
585 }
586 }
587}
588
589//
590////////////////////////////////////////////////////////////////////////////
591void t_reqcAnalyze::slotDspAvailPlot(const QString& fileName,
592 const QByteArray& title) {
593
594 if (dynamic_cast<bncApp*>(qApp)->GUIenabled()) {
595
596 t_availPlot* plotA = new t_availPlot(0, &_availDataMap);
597 plotA->setTitle(title);
598
599 t_elePlot* plotZ = new t_elePlot(0, &_availDataMap);
600
601 t_dopPlot* plotD = new t_dopPlot(0, &_obsStat);
602
603 QVector<QWidget*> plots;
604 plots << plotA << plotZ << plotD;
605 t_graphWin* graphWin = new t_graphWin(0, fileName, plots, 0, 0);
606
607 int ww = QFontMetrics(graphWin->font()).width('w');
608 graphWin->setMinimumSize(120*ww, 40*ww);
609
610 graphWin->show();
611
612 bncSettings settings;
613 QString dirName = settings.value("reqcPlotDir").toString();
614 if (!dirName.isEmpty()) {
615 QByteArray ext = "_A.png";
616 graphWin->savePNG(dirName, ext);
617 }
618 }
619}
Note: See TracBrowser for help on using the repository browser.