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

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