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

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