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

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