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

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