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

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