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

Last change on this file since 4571 was 4571, checked in by mervart, 12 years ago
File size: 13.8 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(displayGraph(const QString&,
71 const QByteArray&,
72 QVector<t_polarPoint*>*,
73 const QByteArray&,
74 QVector<t_polarPoint*>*,
75 const QByteArray&, double)),
76 this, SLOT(slotDisplayGraph(const QString&,
77 const QByteArray&,
78 QVector<t_polarPoint*>*,
79 const QByteArray&,
80 QVector<t_polarPoint*>*,
81 const QByteArray&, double)));
82}
83
84// Destructor
85////////////////////////////////////////////////////////////////////////////
86t_reqcAnalyze::~t_reqcAnalyze() {
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;
95 bncApp* app = (bncApp*) qApp;
96 if ( app->mode() != bncApp::interactive) {
97 app->exit(0);
98 }
99}
100
101//
102////////////////////////////////////////////////////////////////////////////
103void t_reqcAnalyze::slotDisplayGraph(const QString& fileName,
104 const QByteArray& title1,
105 QVector<t_polarPoint*>* data1,
106 const QByteArray& title2,
107 QVector<t_polarPoint*>* data2,
108 const QByteArray& scaleTitle,
109 double maxValue) {
110
111 bncApp* app = dynamic_cast<bncApp*>(qApp);
112 if (app->GUIenabled()) {
113
114 if (maxValue == 0.0) {
115 if (data1) {
116 for (int ii = 0; ii < data1->size(); ii++) {
117 double val = data1->at(ii)->_value;
118 if (maxValue < val) {
119 maxValue = val;
120 }
121 }
122 }
123 if (data2) {
124 for (int ii = 0; ii < data2->size(); ii++) {
125 double val = data2->at(ii)->_value;
126 if (maxValue < val) {
127 maxValue = val;
128 }
129 }
130 }
131 }
132
133 QwtInterval scaleInterval(0.0, maxValue);
134
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 }
142 if (data2) {
143 t_polarPlot* plot2 = new t_polarPlot(QwtText(title2), scaleInterval,
144 app->mainWindow());
145 plot2->addCurve(data2);
146 plots << plot2;
147 }
148
149 t_graphWin* graphWin = new t_graphWin(0, fileName, plots,
150 scaleTitle, scaleInterval);
151
152 graphWin->show();
153
154 bncSettings settings;
155 QString dirName = settings.value("reqcPlotDir").toString();
156 if (!dirName.isEmpty()) {
157 QByteArray ext = scaleTitle.isEmpty() ? "_SNR.png" : "_MP.png";
158 graphWin->savePNG(dirName, ext);
159 }
160 }
161}
162
163//
164////////////////////////////////////////////////////////////////////////////
165void t_reqcAnalyze::run() {
166
167 // Open Log File
168 // -------------
169 _logFile = new QFile(_logFileName);
170 if (_logFile->open(QIODevice::WriteOnly | QIODevice::Text)) {
171 _log = new QTextStream();
172 _log->setDevice(_logFile);
173 }
174
175 // Initialize RINEX Observation Files
176 // ----------------------------------
177 t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles, _log);
178
179 // Read Ephemerides
180 // ----------------
181 t_reqcEdit::readEphemerides(_navFileNames, _ephs);
182
183 // Loop over all RINEX Files
184 // -------------------------
185 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
186 analyzeFile(_rnxObsFiles[ii]);
187 }
188
189 // Exit
190 // ----
191 emit finished();
192 deleteLater();
193}
194
195//
196////////////////////////////////////////////////////////////////////////////
197void t_reqcAnalyze::analyzeFile(t_rnxObsFile* obsFile) {
198
199 if (_log) {
200 *_log << "\nAnalyze File\n"
201 << "------------\n"
202 << obsFile->fileName().toAscii().data() << endl << endl;
203 }
204
205 _satStat.clear();
206
207 // A priori Coordinates
208 // --------------------
209 ColumnVector xyz = obsFile->xyz();
210
211 // Loop over all Epochs
212 // --------------------
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);
233 }
234
235 } // while (_currEpo)
236 }
237 catch (QString str) {
238 if (_log) {
239 *_log << "Exception " << str << endl;
240 }
241 else {
242 qDebug() << str;
243 }
244 return;
245 }
246
247 // Analyze the Multipath
248 // ---------------------
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*>;
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();
259 analyzeMultipathAndSNR(prn, satStat, xyz, obsFile->interval(),
260 dataMP1, dataMP2, dataSNR1, dataSNR2);
261 }
262
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);
267
268 if (_log) {
269 _log->flush();
270 }
271}
272
273//
274////////////////////////////////////////////////////////////////////////////
275void t_reqcAnalyze::t_satStat::addObs(const t_obs& obs) {
276
277 t_anaObs* newObs = new t_anaObs(obs.GPSWeek, obs.GPSWeeks);
278 bool okFlag = false;
279
280 // Compute the Multipath
281 // ----------------------
282 double L1 = obs.measdata("L1", 3.0);
283 if (L1 != 0) {
284 newObs->_hasL1 = true;
285 }
286 double L2 = obs.measdata("L2", 3.0);
287 if (L2 != 0) {
288 newObs->_hasL2 = true;
289 }
290 if (L1 != 0.0 && L2 != 0.0) {
291 double f1 = t_CST::f1(obs.satSys, obs.slotNum);
292 double f2 = t_CST::f2(obs.satSys, obs.slotNum);
293
294 L1 = L1 * t_CST::c / f1;
295 L2 = L2 * t_CST::c / f2;
296
297 double P1 = obs.measdata("C1", 3.0);
298 if (P1 != 0.0) {
299 newObs->_MP1 = P1 - L1 - 2.0*f2*f2/(f1*f1-f2*f2) * (L1 - L2);
300 okFlag = true;
301 }
302 double P2 = obs.measdata("C2", 3.0);
303 if (P2 != 0.0) {
304 newObs->_MP2 = P2 - L2 - 2.0*f1*f1/(f1*f1-f2*f2) * (L1 - L2);
305 okFlag = true;
306 }
307 }
308
309 // Signal-to-Noise
310 // ---------------
311 double S1 = obs.measdata("S1", 3.0);
312 if (S1 != 0.0) {
313 newObs->_SNR1 = floor(S1/6);
314 if (newObs->_SNR1 > 9.0) {
315 newObs->_SNR1 = 9.0;
316 }
317 if (newObs->_SNR1 < 1.0) {
318 newObs->_SNR1 = 1.0;
319 }
320 okFlag = true;
321 }
322 else {
323 if (obs.snrL1 > 0) {
324 newObs->_SNR1 = obs.snrL1;
325 okFlag = true;
326 }
327 }
328 double S2 = obs.measdata("S2", 3.0);
329 if (S2 != 0.0) {
330 newObs->_SNR2 = floor(S2/6);
331 if (newObs->_SNR2 > 9.0) {
332 newObs->_SNR2 = 9.0;
333 }
334 if (newObs->_SNR2 < 1.0) {
335 newObs->_SNR2 = 1.0;
336 }
337 okFlag = true;
338 }
339 else {
340 if (obs.snrL2 > 0) {
341 newObs->_SNR2 = obs.snrL2;
342 okFlag = true;
343 }
344 }
345
346 // Remember the Observation
347 // ------------------------
348 if (okFlag) {
349 anaObs << newObs;
350 }
351 else {
352 delete newObs;
353 }
354}
355
356//
357////////////////////////////////////////////////////////////////////////////
358void t_reqcAnalyze::analyzeMultipathAndSNR(const QString& prn,
359 const t_satStat& satStat,
360 const ColumnVector& xyz,
361 double obsInterval,
362 QVector<t_polarPoint*>* dataMP1,
363 QVector<t_polarPoint*>* dataMP2,
364 QVector<t_polarPoint*>* dataSNR1,
365 QVector<t_polarPoint*>* dataSNR2) {
366
367 const int chunkStep = int( 30.0 / obsInterval); // chunk step (30 sec)
368 const int numEpo = int(600.0 / obsInterval); // # epochs in one chunk (10 min)
369
370 for (int chunkStart = 0; chunkStart + numEpo < satStat.anaObs.size();
371 chunkStart += chunkStep) {
372
373 // Compute Mean
374 // ------------
375 bool slipFlag = false;
376 double mean1 = 0.0;
377 double mean2 = 0.0;
378 double SNR1 = 0.0;
379 double SNR2 = 0.0;
380
381
382 for (int ii = 0; ii < numEpo; ii++) {
383 int iEpo = chunkStart + ii;
384 const t_anaObs* anaObs = satStat.anaObs[iEpo];
385 mean1 += anaObs->_MP1;
386 mean2 += anaObs->_MP2;
387
388 if ( anaObs->_SNR1 > 0 && (SNR1 == 0 || SNR1 > anaObs->_SNR1) ) {
389 SNR1 = anaObs->_SNR1;
390 }
391 if ( anaObs->_SNR2 > 0 && (SNR2 == 0 || SNR2 > anaObs->_SNR2) ) {
392 SNR2 = anaObs->_SNR2;
393 }
394
395 // Check Slip
396 // ----------
397 if (ii > 0) {
398 double diff1 = anaObs->_MP1 - satStat.anaObs[iEpo-1]->_MP1;
399 double diff2 = anaObs->_MP2 - satStat.anaObs[iEpo-1]->_MP2;
400 if (fabs(diff1) > SLIPTRESH || fabs(diff2) > SLIPTRESH) {
401 slipFlag = true;
402 break;
403 }
404 }
405 }
406
407 if (slipFlag) {
408 continue;
409 }
410
411 mean1 /= numEpo;
412 mean2 /= numEpo;
413
414 // Compute Standard Deviation
415 // --------------------------
416 double stddev1 = 0.0;
417 double stddev2 = 0.0;
418 for (int ii = 0; ii < numEpo; ii++) {
419 int iEpo = chunkStart + ii;
420 const t_anaObs* anaObs = satStat.anaObs[iEpo];
421 double diff1 = anaObs->_MP1 - mean1;
422 double diff2 = anaObs->_MP2 - mean2;
423 stddev1 += diff1 * diff1;
424 stddev2 += diff2 * diff2;
425 }
426 double MP1 = sqrt(stddev1 / (numEpo-1));
427 double MP2 = sqrt(stddev2 / (numEpo-1));
428
429 const t_anaObs* anaObs0 = satStat.anaObs[chunkStart];
430
431 // Compute the Azimuth and Zenith Distance
432 // ---------------------------------------
433 double az = 0.0;
434 double zen = 0.0;
435 if (xyz.size()) {
436 t_eph* eph = 0;
437 for (int ie = 0; ie < _ephs.size(); ie++) {
438 if (_ephs[ie]->prn() == prn) {
439 eph = _ephs[ie];
440 break;
441 }
442 }
443
444 if (eph) {
445 double xSat, ySat, zSat, clkSat;
446 eph->position(anaObs0->_GPSWeek, anaObs0->_GPSWeeks,
447 xSat, ySat, zSat, clkSat);
448
449 double rho, eleSat, azSat;
450 topos(xyz(1), xyz(2), xyz(3), xSat, ySat, zSat, rho, eleSat, azSat);
451
452 az = azSat * 180.0/M_PI;
453 zen = 90.0 - eleSat * 180.0/M_PI;
454 }
455 }
456
457 // Add new Point
458 // -------------
459 (*dataMP1) << (new t_polarPoint(az, zen, MP1));
460 (*dataMP2) << (new t_polarPoint(az, zen, MP2));
461 (*dataSNR1) << (new t_polarPoint(az, zen, SNR1));
462 (*dataSNR2) << (new t_polarPoint(az, zen, SNR2));
463
464 if (_log) {
465 _log->setRealNumberNotation(QTextStream::FixedNotation);
466
467 _log->setRealNumberPrecision(2);
468 *_log << "MP1 " << prn << " " << az << " " << zen << " ";
469 _log->setRealNumberPrecision(3);
470 *_log << MP1 << endl;
471
472 _log->setRealNumberPrecision(2);
473 *_log << "MP2 " << prn << " " << az << " " << zen << " ";
474 _log->setRealNumberPrecision(3);
475 *_log << MP2 << endl;
476
477 _log->flush();
478 }
479 }
480}
Note: See TracBrowser for help on using the repository browser.