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

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