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

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