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

Last change on this file since 4579 was 4579, checked in by mervart, 12 years ago
File size: 15.2 KB
RevLine 
[3899]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>
[4361]42#include <iomanip>
[4579]43#include <qwt_plot_renderer.h>
[4574]44
[3899]45#include "reqcanalyze.h"
[3973]46#include "bncapp.h"
[3899]47#include "bncsettings.h"
[4254]48#include "reqcedit.h"
[4255]49#include "bncutils.h"
[4262]50#include "bncpostprocess.h"
[4300]51#include "graphwin.h"
[4307]52#include "polarplot.h"
[4577]53#include "availplot.h"
[3899]54
55using namespace std;
56
[4357]57const double SLIPTRESH = 5.0; // cycle-slip threshold (meters)
58
[3899]59// Constructor
60////////////////////////////////////////////////////////////////////////////
61t_reqcAnalyze::t_reqcAnalyze(QObject* parent) : QThread(parent) {
62
63 bncSettings settings;
[4254]64
[4257]65 _logFileName = settings.value("reqcOutLogFile").toString(); expandEnvVar(_logFileName);
66 _logFile = 0;
67 _log = 0;
[4254]68 _obsFileNames = settings.value("reqcObsFile").toString().split(",", QString::SkipEmptyParts);
[4257]69 _navFileNames = settings.value("reqcNavFile").toString().split(",", QString::SkipEmptyParts);
[4266]70
71 _currEpo = 0;
[4300]72
[4572]73 connect(this, SIGNAL(dspSkyPlot(const QString&,
74 const QByteArray&,
75 QVector<t_polarPoint*>*,
76 const QByteArray&,
77 QVector<t_polarPoint*>*,
78 const QByteArray&, double)),
79 this, SLOT(slotDspSkyPlot(const QString&,
[4556]80 const QByteArray&,
81 QVector<t_polarPoint*>*,
82 const QByteArray&,
83 QVector<t_polarPoint*>*,
[4572]84 const QByteArray&, double)));
85
86 connect(this, SIGNAL(dspAvailPlot(const QString&,
87 const QByteArray&,
88 QMap<QString, QVector<int> >*)),
89 this, SLOT(slotDspAvailPlot(const QString&,
[4556]90 const QByteArray&,
[4572]91 QMap<QString, QVector<int> >*)));
92
[3899]93}
94
95// Destructor
96////////////////////////////////////////////////////////////////////////////
97t_reqcAnalyze::~t_reqcAnalyze() {
[4255]98 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
99 delete _rnxObsFiles[ii];
100 }
101 for (int ii = 0; ii < _ephs.size(); ii++) {
102 delete _ephs[ii];
103 }
104 delete _log; _log = 0;
105 delete _logFile; _logFile = 0;
[4452]106 bncApp* app = (bncApp*) qApp;
107 if ( app->mode() != bncApp::interactive) {
108 app->exit(0);
109 }
[3899]110}
111
112//
113////////////////////////////////////////////////////////////////////////////
[4572]114void t_reqcAnalyze::slotDspSkyPlot(const QString& fileName,
115 const QByteArray& title1,
116 QVector<t_polarPoint*>* data1,
117 const QByteArray& title2,
118 QVector<t_polarPoint*>* data2,
119 const QByteArray& scaleTitle,
120 double maxValue) {
[4342]121
[4346]122 bncApp* app = dynamic_cast<bncApp*>(qApp);
[4448]123 if (app->GUIenabled()) {
[4334]124
[4556]125 if (maxValue == 0.0) {
126 if (data1) {
127 for (int ii = 0; ii < data1->size(); ii++) {
[4566]128 double val = data1->at(ii)->_value;
129 if (maxValue < val) {
130 maxValue = val;
[4556]131 }
132 }
[4356]133 }
[4557]134 if (data2) {
[4556]135 for (int ii = 0; ii < data2->size(); ii++) {
[4566]136 double val = data2->at(ii)->_value;
137 if (maxValue < val) {
138 maxValue = val;
[4556]139 }
140 }
[4356]141 }
142 }
[4357]143
[4556]144 QwtInterval scaleInterval(0.0, maxValue);
[4356]145
[4556]146 QVector<QWidget*> plots;
147 if (data1) {
148 t_polarPlot* plot1 = new t_polarPlot(QwtText(title1), scaleInterval,
149 app->mainWindow());
150 plot1->addCurve(data1);
151 plots << plot1;
152 }
[4557]153 if (data2) {
[4556]154 t_polarPlot* plot2 = new t_polarPlot(QwtText(title2), scaleInterval,
[4356]155 app->mainWindow());
[4556]156 plot2->addCurve(data2);
157 plots << plot2;
158 }
[4334]159
[4564]160 t_graphWin* graphWin = new t_graphWin(0, fileName, plots,
[4573]161 &scaleTitle, &scaleInterval);
[4334]162
[4445]163 graphWin->show();
164
[4451]165 bncSettings settings;
166 QString dirName = settings.value("reqcPlotDir").toString();
167 if (!dirName.isEmpty()) {
[4565]168 QByteArray ext = scaleTitle.isEmpty() ? "_SNR.png" : "_MP.png";
[4579]169 graphWin->savePNG(dirName, ext);
[4451]170 }
[4308]171 }
[4300]172}
173
174//
175////////////////////////////////////////////////////////////////////////////
[3899]176void t_reqcAnalyze::run() {
177
[4255]178 // Open Log File
179 // -------------
180 _logFile = new QFile(_logFileName);
[4517]181 if (_logFile->open(QIODevice::WriteOnly | QIODevice::Text)) {
182 _log = new QTextStream();
183 _log->setDevice(_logFile);
184 }
[4255]185
186 // Initialize RINEX Observation Files
187 // ----------------------------------
[4525]188 t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles, _log);
[3899]189
[4257]190 // Read Ephemerides
191 // ----------------
192 t_reqcEdit::readEphemerides(_navFileNames, _ephs);
193
[4255]194 // Loop over all RINEX Files
195 // -------------------------
[4254]196 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
197 analyzeFile(_rnxObsFiles[ii]);
198 }
199
[4255]200 // Exit
201 // ----
[4452]202 emit finished();
203 deleteLater();
[3899]204}
[4254]205
206//
207////////////////////////////////////////////////////////////////////////////
[4260]208void t_reqcAnalyze::analyzeFile(t_rnxObsFile* obsFile) {
[4259]209
[4517]210 if (_log) {
211 *_log << "\nAnalyze File\n"
212 << "------------\n"
213 << obsFile->fileName().toAscii().data() << endl << endl;
214 }
[4260]215
[4343]216 _satStat.clear();
217
[4342]218 // A priori Coordinates
219 // --------------------
220 ColumnVector xyz = obsFile->xyz();
221
[4262]222 // Loop over all Epochs
223 // --------------------
[4541]224 try {
225 while ( (_currEpo = obsFile->nextEpoch()) != 0) {
226
227 // Loop over all satellites
228 // ------------------------
229 for (unsigned iObs = 0; iObs < _currEpo->rnxSat.size(); iObs++) {
230 const t_rnxObsFile::t_rnxSat& rnxSat = _currEpo->rnxSat[iObs];
231 t_obs obs;
232 t_postProcessing::setObsFromRnx(obsFile, _currEpo, rnxSat, obs);
233
234 if (obs.satSys == 'R') {
235 continue; // TODO: set channel number
236 }
237
238 QString prn = QString("%1%2").arg(obs.satSys)
239 .arg(obs.satNum, 2, 10, QChar('0'));
240
241 t_satStat& satStat = _satStat[prn];
242
243 satStat.addObs(obs);
[4262]244 }
[4541]245
246 } // while (_currEpo)
247 }
248 catch (QString str) {
249 if (_log) {
250 *_log << "Exception " << str << endl;
[4262]251 }
[4541]252 else {
253 qDebug() << str;
254 }
255 return;
256 }
[4262]257
[4268]258 // Analyze the Multipath
259 // ---------------------
[4572]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 QMap<QString, QVector<int> >* availL1 = new QMap<QString, QVector<int> >;
[4268]265
[4572]266
[4268]267 QMapIterator<QString, t_satStat> it(_satStat);
268 while (it.hasNext()) {
269 it.next();
270 QString prn = it.key();
271 const t_satStat& satStat = it.value();
[4572]272 QVector<int>& dataL1 = (*availL1)[prn];
273 preparePlotData(prn, satStat, xyz, obsFile->interval(),
274 dataMP1, dataMP2, dataSNR1, dataSNR2, dataL1);
[4268]275 }
276
[4572]277 emit dspSkyPlot(obsFile->fileName(), "MP1", dataMP1, "MP2", dataMP2,
278 "Meters", 2.0);
[4300]279
[4572]280 emit dspSkyPlot(obsFile->fileName(), "SNR1", dataSNR1, "SNR2", dataSNR2,
281 "", 9.0);
282
[4576]283 emit dspAvailPlot(obsFile->fileName(), "Availability L1", availL1);
[4572]284
[4517]285 if (_log) {
286 _log->flush();
287 }
[4254]288}
[4263]289
290//
291////////////////////////////////////////////////////////////////////////////
[4355]292void t_reqcAnalyze::t_satStat::addObs(const t_obs& obs) {
[4265]293
[4355]294 t_anaObs* newObs = new t_anaObs(obs.GPSWeek, obs.GPSWeeks);
[4354]295 bool okFlag = false;
[4338]296
[4268]297 // Compute the Multipath
298 // ----------------------
[4424]299 double L1 = obs.measdata("L1", 3.0);
[4571]300 if (L1 != 0) {
301 newObs->_hasL1 = true;
302 }
[4424]303 double L2 = obs.measdata("L2", 3.0);
[4571]304 if (L2 != 0) {
305 newObs->_hasL2 = true;
306 }
[4391]307 if (L1 != 0.0 && L2 != 0.0) {
[4266]308 double f1 = t_CST::f1(obs.satSys, obs.slotNum);
309 double f2 = t_CST::f2(obs.satSys, obs.slotNum);
310
[4391]311 L1 = L1 * t_CST::c / f1;
312 L2 = L2 * t_CST::c / f2;
[4266]313
[4424]314 double P1 = obs.measdata("C1", 3.0);
[4391]315 if (P1 != 0.0) {
316 newObs->_MP1 = P1 - L1 - 2.0*f2*f2/(f1*f1-f2*f2) * (L1 - L2);
[4354]317 okFlag = true;
[4268]318 }
[4424]319 double P2 = obs.measdata("C2", 3.0);
[4391]320 if (P2 != 0.0) {
321 newObs->_MP2 = P2 - L2 - 2.0*f1*f1/(f1*f1-f2*f2) * (L1 - L2);
[4354]322 okFlag = true;
[4268]323 }
[4265]324 }
[4338]325
[4559]326 // Signal-to-Noise
327 // ---------------
328 double S1 = obs.measdata("S1", 3.0);
329 if (S1 != 0.0) {
[4562]330 newObs->_SNR1 = floor(S1/6);
331 if (newObs->_SNR1 > 9.0) {
332 newObs->_SNR1 = 9.0;
333 }
334 if (newObs->_SNR1 < 1.0) {
335 newObs->_SNR1 = 1.0;
336 }
[4559]337 okFlag = true;
338 }
[4562]339 else {
340 if (obs.snrL1 > 0) {
341 newObs->_SNR1 = obs.snrL1;
342 okFlag = true;
343 }
344 }
[4559]345 double S2 = obs.measdata("S2", 3.0);
346 if (S2 != 0.0) {
[4562]347 newObs->_SNR2 = floor(S2/6);
348 if (newObs->_SNR2 > 9.0) {
349 newObs->_SNR2 = 9.0;
350 }
351 if (newObs->_SNR2 < 1.0) {
352 newObs->_SNR2 = 1.0;
353 }
[4559]354 okFlag = true;
355 }
[4562]356 else {
357 if (obs.snrL2 > 0) {
358 newObs->_SNR2 = obs.snrL2;
359 okFlag = true;
360 }
361 }
[4559]362
[4354]363 // Remember the Observation
364 // ------------------------
365 if (okFlag) {
366 anaObs << newObs;
367 }
368 else {
369 delete newObs;
370 }
[4263]371}
[4350]372
373//
374////////////////////////////////////////////////////////////////////////////
[4572]375void t_reqcAnalyze::preparePlotData(const QString& prn,
376 const t_satStat& satStat,
377 const ColumnVector& xyz,
378 double obsInterval,
379 QVector<t_polarPoint*>* dataMP1,
380 QVector<t_polarPoint*>* dataMP2,
381 QVector<t_polarPoint*>* dataSNR1,
382 QVector<t_polarPoint*>* dataSNR2,
383 QVector<int>& dataL1) {
[4350]384
[4544]385 const int chunkStep = int( 30.0 / obsInterval); // chunk step (30 sec)
386 const int numEpo = int(600.0 / obsInterval); // # epochs in one chunk (10 min)
[4350]387
[4361]388 for (int chunkStart = 0; chunkStart + numEpo < satStat.anaObs.size();
389 chunkStart += chunkStep) {
[4351]390
[4572]391 bncTime firstEpoch;
392
[4351]393 // Compute Mean
394 // ------------
[4353]395 bool slipFlag = false;
396 double mean1 = 0.0;
397 double mean2 = 0.0;
[4563]398 double SNR1 = 0.0;
399 double SNR2 = 0.0;
[4353]400
[4361]401 for (int ii = 0; ii < numEpo; ii++) {
[4351]402 int iEpo = chunkStart + ii;
403 const t_anaObs* anaObs = satStat.anaObs[iEpo];
[4572]404
405 if (ii == 0) {
406 firstEpoch.set(anaObs->_GPSWeek, anaObs->_GPSWeeks);
407 }
408
[4355]409 mean1 += anaObs->_MP1;
410 mean2 += anaObs->_MP2;
[4563]411
[4566]412 if ( anaObs->_SNR1 > 0 && (SNR1 == 0 || SNR1 > anaObs->_SNR1) ) {
413 SNR1 = anaObs->_SNR1;
414 }
415 if ( anaObs->_SNR2 > 0 && (SNR2 == 0 || SNR2 > anaObs->_SNR2) ) {
416 SNR2 = anaObs->_SNR2;
417 }
[4353]418
419 // Check Slip
420 // ----------
421 if (ii > 0) {
[4355]422 double diff1 = anaObs->_MP1 - satStat.anaObs[iEpo-1]->_MP1;
423 double diff2 = anaObs->_MP2 - satStat.anaObs[iEpo-1]->_MP2;
[4357]424 if (fabs(diff1) > SLIPTRESH || fabs(diff2) > SLIPTRESH) {
[4353]425 slipFlag = true;
426 break;
427 }
428 }
[4351]429 }
[4353]430
[4573]431 dataL1 << int(firstEpoch.gpssec());
432
[4353]433 if (slipFlag) {
434 continue;
435 }
436
[4361]437 mean1 /= numEpo;
438 mean2 /= numEpo;
[4351]439
440 // Compute Standard Deviation
441 // --------------------------
442 double stddev1 = 0.0;
443 double stddev2 = 0.0;
[4361]444 for (int ii = 0; ii < numEpo; ii++) {
[4351]445 int iEpo = chunkStart + ii;
446 const t_anaObs* anaObs = satStat.anaObs[iEpo];
[4355]447 double diff1 = anaObs->_MP1 - mean1;
448 double diff2 = anaObs->_MP2 - mean2;
[4351]449 stddev1 += diff1 * diff1;
450 stddev2 += diff2 * diff2;
451 }
[4361]452 double MP1 = sqrt(stddev1 / (numEpo-1));
453 double MP2 = sqrt(stddev2 / (numEpo-1));
[4351]454
[4355]455 const t_anaObs* anaObs0 = satStat.anaObs[chunkStart];
456
457 // Compute the Azimuth and Zenith Distance
458 // ---------------------------------------
459 double az = 0.0;
460 double zen = 0.0;
461 if (xyz.size()) {
462 t_eph* eph = 0;
463 for (int ie = 0; ie < _ephs.size(); ie++) {
464 if (_ephs[ie]->prn() == prn) {
465 eph = _ephs[ie];
466 break;
467 }
468 }
469
470 if (eph) {
471 double xSat, ySat, zSat, clkSat;
472 eph->position(anaObs0->_GPSWeek, anaObs0->_GPSWeeks,
473 xSat, ySat, zSat, clkSat);
474
475 double rho, eleSat, azSat;
476 topos(xyz(1), xyz(2), xyz(3), xSat, ySat, zSat, rho, eleSat, azSat);
477
478 az = azSat * 180.0/M_PI;
479 zen = 90.0 - eleSat * 180.0/M_PI;
480 }
481 }
482
[4353]483 // Add new Point
484 // -------------
[4563]485 (*dataMP1) << (new t_polarPoint(az, zen, MP1));
486 (*dataMP2) << (new t_polarPoint(az, zen, MP2));
487 (*dataSNR1) << (new t_polarPoint(az, zen, SNR1));
488 (*dataSNR2) << (new t_polarPoint(az, zen, SNR2));
[4351]489
[4517]490 if (_log) {
491 _log->setRealNumberNotation(QTextStream::FixedNotation);
[4353]492
[4517]493 _log->setRealNumberPrecision(2);
494 *_log << "MP1 " << prn << " " << az << " " << zen << " ";
495 _log->setRealNumberPrecision(3);
496 *_log << MP1 << endl;
[4353]497
[4517]498 _log->setRealNumberPrecision(2);
499 *_log << "MP2 " << prn << " " << az << " " << zen << " ";
500 _log->setRealNumberPrecision(3);
501 *_log << MP2 << endl;
502
503 _log->flush();
504 }
[4350]505 }
506}
[4572]507
508//
509////////////////////////////////////////////////////////////////////////////
510void t_reqcAnalyze::slotDspAvailPlot(const QString& fileName,
511 const QByteArray& title,
512 QMap<QString, QVector<int> >* prnAvail){
513
[4574]514 if (dynamic_cast<bncApp*>(qApp)->GUIenabled()) {
[4573]515
[4577]516 t_availPlot* plot = new t_availPlot(0, prnAvail);
[4573]517
518 QVector<QWidget*> plots;
[4574]519 plots << plot;
[4573]520 t_graphWin* graphWin = new t_graphWin(0, fileName, plots, 0, 0);
521 graphWin->show();
522
523 bncSettings settings;
524 QString dirName = settings.value("reqcPlotDir").toString();
525 if (!dirName.isEmpty()) {
526 QByteArray ext = "_AVAIL.png";
[4579]527 graphWin->savePNG(dirName, ext);
[4573]528 }
529 }
[4572]530}
Note: See TracBrowser for help on using the repository browser.