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

Last change on this file since 4668 was 4668, checked in by mervart, 12 years ago
File size: 17.3 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 if (_numSatTim.size() > 0) {
235 _numSatTim << _numSatTim.last();
236 _numSat << numSat;
237 }
238 _numSatTim << _currEpo->tt.mjddec() * 24.0;
239 _numSat << numSat;
240 numSat = 0;
241 }
242
243 // Loop over all satellites
244 // ------------------------
245 for (unsigned iObs = 0; iObs < _currEpo->rnxSat.size(); iObs++) {
246 const t_rnxObsFile::t_rnxSat& rnxSat = _currEpo->rnxSat[iObs];
247 t_obs obs;
248 t_postProcessing::setObsFromRnx(obsFile, _currEpo, rnxSat, obs);
249
250 if (obs.satSys == 'R') {
251 // TODO: set channel number
252 }
253
254 QString prn = QString("%1%2").arg(obs.satSys)
255 .arg(obs.satNum, 2, 10, QChar('0'));
256
257 _allObsMap[prn].addObs(obs);
258 }
259
260 } // while (_currEpo)
261 }
262 catch (QString str) {
263 if (_log) {
264 *_log << "Exception " << str << endl;
265 }
266 else {
267 qDebug() << str;
268 }
269 return;
270 }
271
272 // Analyze the Multipath
273 // ---------------------
274 QVector<t_polarPoint*>* dataMP1 = new QVector<t_polarPoint*>;
275 QVector<t_polarPoint*>* dataMP2 = new QVector<t_polarPoint*>;
276 QVector<t_polarPoint*>* dataSNR1 = new QVector<t_polarPoint*>;
277 QVector<t_polarPoint*>* dataSNR2 = new QVector<t_polarPoint*>;
278
279 QMutableMapIterator<QString, t_allObs> it(_allObsMap);
280 while (it.hasNext()) {
281 it.next();
282 QString prn = it.key();
283 preparePlotData(prn, xyz, obsFile->interval(),
284 dataMP1, dataMP2, dataSNR1, dataSNR2);
285 }
286
287 emit dspSkyPlot(obsFile->fileName(), "MP1", dataMP1, "MP2", dataMP2,
288 "Meters", 2.0);
289
290 emit dspSkyPlot(obsFile->fileName(), "SNR1", dataSNR1, "SNR2", dataSNR2,
291 "", 9.0);
292
293 QFileInfo fileInfo(obsFile->fileName());
294 QByteArray title = fileInfo.fileName().toAscii();
295
296 emit dspAvailPlot(obsFile->fileName(), title);
297
298 if (_log) {
299 _log->flush();
300 }
301}
302
303//
304////////////////////////////////////////////////////////////////////////////
305void t_reqcAnalyze::t_allObs::addObs(const t_obs& obs) {
306
307 t_oneObs* newObs = new t_oneObs(obs.GPSWeek, obs.GPSWeeks);
308 bool okFlag = false;
309
310 // Availability and Slip Flags
311 // ---------------------------
312 double L1 = obs.measdata("L1", 3.0);
313 if (L1 != 0) {
314 newObs->_hasL1 = true;
315 }
316 double L2 = obs.measdata("L2", 3.0);
317 if (L2 != 0) {
318 newObs->_hasL2 = true;
319 }
320 if (obs.slipL1) {
321 newObs->_slipL1 = true;
322 }
323 if (obs.slipL2) {
324 newObs->_slipL2 = true;
325 }
326
327 // Compute the Multipath
328 // ----------------------
329 if (L1 != 0.0 && L2 != 0.0) {
330 double f1 = t_CST::f1(obs.satSys, obs.slotNum);
331 double f2 = t_CST::f2(obs.satSys, obs.slotNum);
332
333 L1 = L1 * t_CST::c / f1;
334 L2 = L2 * t_CST::c / f2;
335
336 double P1 = obs.measdata("C1", 3.0);
337 if (P1 != 0.0) {
338 newObs->_MP1 = P1 - L1 - 2.0*f2*f2/(f1*f1-f2*f2) * (L1 - L2);
339 okFlag = true;
340 }
341 double P2 = obs.measdata("C2", 3.0);
342 if (P2 != 0.0) {
343 newObs->_MP2 = P2 - L2 - 2.0*f1*f1/(f1*f1-f2*f2) * (L1 - L2);
344 okFlag = true;
345 }
346 }
347
348 // Signal-to-Noise
349 // ---------------
350 double S1 = obs.measdata("S1", 3.0);
351 if (S1 != 0.0) {
352 newObs->_SNR1 = floor(S1/6);
353 if (newObs->_SNR1 > 9.0) {
354 newObs->_SNR1 = 9.0;
355 }
356 if (newObs->_SNR1 < 1.0) {
357 newObs->_SNR1 = 1.0;
358 }
359 okFlag = true;
360 }
361 else {
362 if (obs.snrL1 > 0) {
363 newObs->_SNR1 = obs.snrL1;
364 okFlag = true;
365 }
366 }
367 double S2 = obs.measdata("S2", 3.0);
368 if (S2 != 0.0) {
369 newObs->_SNR2 = floor(S2/6);
370 if (newObs->_SNR2 > 9.0) {
371 newObs->_SNR2 = 9.0;
372 }
373 if (newObs->_SNR2 < 1.0) {
374 newObs->_SNR2 = 1.0;
375 }
376 okFlag = true;
377 }
378 else {
379 if (obs.snrL2 > 0) {
380 newObs->_SNR2 = obs.snrL2;
381 okFlag = true;
382 }
383 }
384
385 // Remember the Observation
386 // ------------------------
387 if (okFlag) {
388 _oneObsVec << newObs;
389 }
390 else {
391 delete newObs;
392 }
393}
394
395//
396////////////////////////////////////////////////////////////////////////////
397void t_reqcAnalyze::preparePlotData(const QString& prn, const ColumnVector& xyz,
398 double obsInterval,
399 QVector<t_polarPoint*>* dataMP1,
400 QVector<t_polarPoint*>* dataMP2,
401 QVector<t_polarPoint*>* dataSNR1,
402 QVector<t_polarPoint*>* dataSNR2) {
403
404 const int chunkStep = int( 30.0 / obsInterval); // chunk step (30 sec)
405 const int numEpo = int(600.0 / obsInterval); // # epochs in one chunk (10 min)
406
407 t_allObs& allObs = _allObsMap[prn];
408
409 // Loop over all Chunks of Data
410 // ----------------------------
411 for (int chunkStart = 0; chunkStart + numEpo < allObs._oneObsVec.size();
412 chunkStart += chunkStep) {
413
414 // Chunk-Speicific Variables
415 // -------------------------
416 bncTime currTime;
417 bncTime prevTime;
418 bncTime chunkStartTime;
419 bool availL1 = false;
420 bool availL2 = false;
421 bool gapL1 = false;
422 bool gapL2 = false;
423 bool slipL1 = false;
424 bool slipL2 = false;
425 bool slipMP = false;
426 double meanMP1 = 0.0;
427 double meanMP2 = 0.0;
428 double minSNR1 = 0.0;
429 double minSNR2 = 0.0;
430 double aziDeg = 0.0;
431 double zenDeg = 0.0;
432 bool zenFlag = false;
433
434 // Loop over all Epochs within one Chunk of Data
435 // ---------------------------------------------
436 for (int ii = 0; ii < numEpo; ii++) {
437 int iEpo = chunkStart + ii;
438 const t_oneObs* oneObs = allObs._oneObsVec[iEpo];
439
440 currTime.set(oneObs->_GPSWeek, oneObs->_GPSWeeks);
441
442 // Compute the Azimuth and Zenith Distance
443 // ---------------------------------------
444 if (ii == 0) {
445 chunkStartTime = currTime;
446
447 if (xyz.size()) {
448 t_eph* eph = 0;
449 for (int ie = 0; ie < _ephs.size(); ie++) {
450 if (_ephs[ie]->prn() == prn) {
451 eph = _ephs[ie];
452 break;
453 }
454 }
455
456 if (eph) {
457 double xSat, ySat, zSat, clkSat;
458 eph->position(oneObs->_GPSWeek, oneObs->_GPSWeeks,
459 xSat, ySat, zSat, clkSat);
460
461 double rho, eleSat, azSat;
462 topos(xyz(1), xyz(2), xyz(3), xSat, ySat, zSat, rho, eleSat, azSat);
463
464 aziDeg = azSat * 180.0/M_PI;
465 zenDeg = 90.0 - eleSat * 180.0/M_PI;
466 zenFlag = true;
467 }
468 }
469 }
470
471 // Check Interval
472 // --------------
473 if (prevTime.valid()) {
474 double dt = currTime - prevTime;
475 if (dt != obsInterval) {
476 gapL1 = true;
477 gapL2 = true;
478 }
479 }
480 prevTime = currTime;
481
482 // Check L1 and L2 availability
483 // ----------------------------
484 if (oneObs->_hasL1) {
485 availL1 = true;
486 }
487 else {
488 gapL1 = true;
489 }
490 if (oneObs->_hasL2) {
491 availL2 = true;
492 }
493 else {
494 gapL2 = true;
495 }
496
497 // Check Minimal Signal-to-Noise Ratio
498 // -----------------------------------
499 if ( oneObs->_SNR1 > 0 && (minSNR1 == 0 || minSNR1 > oneObs->_SNR1) ) {
500 minSNR1 = oneObs->_SNR1;
501 }
502 if ( oneObs->_SNR2 > 0 && (minSNR2 == 0 || minSNR2 > oneObs->_SNR2) ) {
503 minSNR2 = oneObs->_SNR2;
504 }
505
506 // Check Slip Flags
507 // ----------------
508 if (oneObs->_slipL1) {
509 slipL1 = true;
510 }
511 if (oneObs->_slipL2) {
512 slipL2 = true;
513 }
514
515 // Check Slip Threshold
516 // --------------------
517 if (ii > 0) {
518 double diff1 = oneObs->_MP1 - allObs._oneObsVec[iEpo-1]->_MP1;
519 double diff2 = oneObs->_MP2 - allObs._oneObsVec[iEpo-1]->_MP2;
520 if (fabs(diff1) > SLIPTRESH || fabs(diff2) > SLIPTRESH) {
521 slipMP = true;
522 }
523 }
524
525 meanMP1 += oneObs->_MP1;
526 meanMP2 += oneObs->_MP2;
527 }
528
529 // Availability Plot Data
530 // ----------------------
531 double mjdX24 = chunkStartTime.mjddec() * 24.0;
532 if (availL1) {
533 if (slipL1) {
534 _availDataMap[prn]._L1slip << mjdX24;
535 }
536 else if (gapL1) {
537 _availDataMap[prn]._L1gap << mjdX24;
538 }
539 else {
540 _availDataMap[prn]._L1ok << mjdX24;
541 }
542 }
543 if (availL2) {
544 if (slipL2) {
545 _availDataMap[prn]._L2slip << mjdX24;
546 }
547 else if (gapL2) {
548 _availDataMap[prn]._L2gap << mjdX24;
549 }
550 else {
551 _availDataMap[prn]._L2ok << mjdX24;
552 }
553 }
554 if (zenFlag) {
555 _availDataMap[prn]._eleTim << mjdX24;
556 _availDataMap[prn]._eleDeg << 90.0 - zenDeg;
557 }
558
559 // Signal-to-Noise Ration Plot Data
560 // --------------------------------
561 (*dataSNR1) << (new t_polarPoint(aziDeg, zenDeg, minSNR1));
562 (*dataSNR2) << (new t_polarPoint(aziDeg, zenDeg, minSNR2));
563
564 // Compute the Multipath
565 // ---------------------
566 if (!slipMP) {
567 meanMP1 /= numEpo;
568 meanMP2 /= numEpo;
569 double MP1 = 0.0;
570 double MP2 = 0.0;
571 for (int ii = 0; ii < numEpo; ii++) {
572 int iEpo = chunkStart + ii;
573 const t_oneObs* oneObs = allObs._oneObsVec[iEpo];
574 double diff1 = oneObs->_MP1 - meanMP1;
575 double diff2 = oneObs->_MP2 - meanMP2;
576 MP1 += diff1 * diff1;
577 MP2 += diff2 * diff2;
578 }
579 MP1 = sqrt(MP1 / (numEpo-1));
580 MP2 = sqrt(MP2 / (numEpo-1));
581 (*dataMP1) << (new t_polarPoint(aziDeg, zenDeg, MP1));
582 (*dataMP2) << (new t_polarPoint(aziDeg, zenDeg, MP2));
583 }
584 }
585}
586
587//
588////////////////////////////////////////////////////////////////////////////
589void t_reqcAnalyze::slotDspAvailPlot(const QString& fileName,
590 const QByteArray& title) {
591
592 if (dynamic_cast<bncApp*>(qApp)->GUIenabled()) {
593
594 t_availPlot* plotA = new t_availPlot(0, &_availDataMap);
595 plotA->setNumSat(_numSatTim, _numSat);
596 plotA->setTitle(title);
597
598 t_elePlot* plotZ = new t_elePlot(0, &_availDataMap);
599 plotZ->setTitle(title);
600
601 QVector<QWidget*> plots;
602 plots << plotA << plotZ;
603 t_graphWin* graphWin = new t_graphWin(0, fileName, plots, 0, 0);
604
605 int ww = QFontMetrics(graphWin->font()).width('w');
606 graphWin->setMinimumSize(120*ww, 40*ww);
607
608 graphWin->show();
609
610 bncSettings settings;
611 QString dirName = settings.value("reqcPlotDir").toString();
612 if (!dirName.isEmpty()) {
613 QByteArray ext = "_A.png";
614 graphWin->savePNG(dirName, ext);
615 }
616 }
617}
Note: See TracBrowser for help on using the repository browser.