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

Last change on this file since 4564 was 4564, checked in by mervart, 12 years ago
File size: 13.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(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 mp = data1->at(ii)->_value;
118 if (maxValue < mp) {
119 maxValue = mp;
120 }
121 }
122 }
123 if (data2) {
124 for (int ii = 0; ii < data2->size(); ii++) {
125 double mp = data2->at(ii)->_value;
126 if (maxValue < mp) {
127 maxValue = mp;
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 graphWin->savePNG(dirName);
158 }
159 }
160}
161
162//
163////////////////////////////////////////////////////////////////////////////
164void t_reqcAnalyze::run() {
165
166 // Open Log File
167 // -------------
168 _logFile = new QFile(_logFileName);
169 if (_logFile->open(QIODevice::WriteOnly | QIODevice::Text)) {
170 _log = new QTextStream();
171 _log->setDevice(_logFile);
172 }
173
174 // Initialize RINEX Observation Files
175 // ----------------------------------
176 t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles, _log);
177
178 // Read Ephemerides
179 // ----------------
180 t_reqcEdit::readEphemerides(_navFileNames, _ephs);
181
182 // Loop over all RINEX Files
183 // -------------------------
184 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
185 analyzeFile(_rnxObsFiles[ii]);
186 }
187
188 // Exit
189 // ----
190 emit finished();
191 deleteLater();
192}
193
194//
195////////////////////////////////////////////////////////////////////////////
196void t_reqcAnalyze::analyzeFile(t_rnxObsFile* obsFile) {
197
198 if (_log) {
199 *_log << "\nAnalyze File\n"
200 << "------------\n"
201 << obsFile->fileName().toAscii().data() << endl << endl;
202 }
203
204 _satStat.clear();
205
206 // A priori Coordinates
207 // --------------------
208 ColumnVector xyz = obsFile->xyz();
209
210 // Loop over all Epochs
211 // --------------------
212 try {
213 while ( (_currEpo = obsFile->nextEpoch()) != 0) {
214
215 // Loop over all satellites
216 // ------------------------
217 for (unsigned iObs = 0; iObs < _currEpo->rnxSat.size(); iObs++) {
218 const t_rnxObsFile::t_rnxSat& rnxSat = _currEpo->rnxSat[iObs];
219 t_obs obs;
220 t_postProcessing::setObsFromRnx(obsFile, _currEpo, rnxSat, obs);
221
222 if (obs.satSys == 'R') {
223 continue; // TODO: set channel number
224 }
225
226 QString prn = QString("%1%2").arg(obs.satSys)
227 .arg(obs.satNum, 2, 10, QChar('0'));
228
229 t_satStat& satStat = _satStat[prn];
230
231 satStat.addObs(obs);
232 }
233
234 } // while (_currEpo)
235 }
236 catch (QString str) {
237 if (_log) {
238 *_log << "Exception " << str << endl;
239 }
240 else {
241 qDebug() << str;
242 }
243 return;
244 }
245
246 // Analyze the Multipath
247 // ---------------------
248 QVector<t_polarPoint*>* dataMP1 = new QVector<t_polarPoint*>;
249 QVector<t_polarPoint*>* dataMP2 = new QVector<t_polarPoint*>;
250 QVector<t_polarPoint*>* dataSNR1 = new QVector<t_polarPoint*>;
251 QVector<t_polarPoint*>* dataSNR2 = new QVector<t_polarPoint*>;
252
253 QMapIterator<QString, t_satStat> it(_satStat);
254 while (it.hasNext()) {
255 it.next();
256 QString prn = it.key();
257 const t_satStat& satStat = it.value();
258 analyzeMultipathAndSNR(prn, satStat, xyz, obsFile->interval(),
259 dataMP1, dataMP2, dataSNR1, dataSNR2);
260 }
261
262 emit displayGraph(obsFile->fileName(), "MP1", dataMP1, "MP2", dataMP2,
263 "Meters", 2.0);
264 emit displayGraph(obsFile->fileName(), "SNR1", dataSNR1, "SNR2", dataSNR2,
265 "", 9.0);
266
267 if (_log) {
268 _log->flush();
269 }
270}
271
272//
273////////////////////////////////////////////////////////////////////////////
274void t_reqcAnalyze::t_satStat::addObs(const t_obs& obs) {
275
276 t_anaObs* newObs = new t_anaObs(obs.GPSWeek, obs.GPSWeeks);
277 bool okFlag = false;
278
279 // Compute the Multipath
280 // ----------------------
281 double L1 = obs.measdata("L1", 3.0);
282 double L2 = obs.measdata("L2", 3.0);
283 if (L1 != 0.0 && L2 != 0.0) {
284 double f1 = t_CST::f1(obs.satSys, obs.slotNum);
285 double f2 = t_CST::f2(obs.satSys, obs.slotNum);
286
287 L1 = L1 * t_CST::c / f1;
288 L2 = L2 * t_CST::c / f2;
289
290 double P1 = obs.measdata("C1", 3.0);
291 if (P1 != 0.0) {
292 newObs->_MP1 = P1 - L1 - 2.0*f2*f2/(f1*f1-f2*f2) * (L1 - L2);
293 okFlag = true;
294 }
295 double P2 = obs.measdata("C2", 3.0);
296 if (P2 != 0.0) {
297 newObs->_MP2 = P2 - L2 - 2.0*f1*f1/(f1*f1-f2*f2) * (L1 - L2);
298 okFlag = true;
299 }
300 }
301
302 // Signal-to-Noise
303 // ---------------
304 double S1 = obs.measdata("S1", 3.0);
305 if (S1 != 0.0) {
306 newObs->_SNR1 = floor(S1/6);
307 if (newObs->_SNR1 > 9.0) {
308 newObs->_SNR1 = 9.0;
309 }
310 if (newObs->_SNR1 < 1.0) {
311 newObs->_SNR1 = 1.0;
312 }
313 okFlag = true;
314 }
315 else {
316 if (obs.snrL1 > 0) {
317 newObs->_SNR1 = obs.snrL1;
318 okFlag = true;
319 }
320 }
321 double S2 = obs.measdata("S2", 3.0);
322 if (S2 != 0.0) {
323 newObs->_SNR2 = floor(S2/6);
324 if (newObs->_SNR2 > 9.0) {
325 newObs->_SNR2 = 9.0;
326 }
327 if (newObs->_SNR2 < 1.0) {
328 newObs->_SNR2 = 1.0;
329 }
330 okFlag = true;
331 }
332 else {
333 if (obs.snrL2 > 0) {
334 newObs->_SNR2 = obs.snrL2;
335 okFlag = true;
336 }
337 }
338
339 // Remember the Observation
340 // ------------------------
341 if (okFlag) {
342 anaObs << newObs;
343 }
344 else {
345 delete newObs;
346 }
347}
348
349//
350////////////////////////////////////////////////////////////////////////////
351void t_reqcAnalyze::analyzeMultipathAndSNR(const QString& prn,
352 const t_satStat& satStat,
353 const ColumnVector& xyz,
354 double obsInterval,
355 QVector<t_polarPoint*>* dataMP1,
356 QVector<t_polarPoint*>* dataMP2,
357 QVector<t_polarPoint*>* dataSNR1,
358 QVector<t_polarPoint*>* dataSNR2) {
359
360 const int chunkStep = int( 30.0 / obsInterval); // chunk step (30 sec)
361 const int numEpo = int(600.0 / obsInterval); // # epochs in one chunk (10 min)
362
363 for (int chunkStart = 0; chunkStart + numEpo < satStat.anaObs.size();
364 chunkStart += chunkStep) {
365
366 // Compute Mean
367 // ------------
368 bool slipFlag = false;
369 double mean1 = 0.0;
370 double mean2 = 0.0;
371 double SNR1 = 0.0;
372 double SNR2 = 0.0;
373
374
375 for (int ii = 0; ii < numEpo; ii++) {
376 int iEpo = chunkStart + ii;
377 const t_anaObs* anaObs = satStat.anaObs[iEpo];
378 mean1 += anaObs->_MP1;
379 mean2 += anaObs->_MP2;
380
381 SNR1 = anaObs->_SNR1;
382 SNR2 = anaObs->_SNR2;
383
384 // Check Slip
385 // ----------
386 if (ii > 0) {
387 double diff1 = anaObs->_MP1 - satStat.anaObs[iEpo-1]->_MP1;
388 double diff2 = anaObs->_MP2 - satStat.anaObs[iEpo-1]->_MP2;
389 if (fabs(diff1) > SLIPTRESH || fabs(diff2) > SLIPTRESH) {
390 slipFlag = true;
391 break;
392 }
393 }
394 }
395
396 if (slipFlag) {
397 continue;
398 }
399
400 mean1 /= numEpo;
401 mean2 /= numEpo;
402
403 // Compute Standard Deviation
404 // --------------------------
405 double stddev1 = 0.0;
406 double stddev2 = 0.0;
407 for (int ii = 0; ii < numEpo; ii++) {
408 int iEpo = chunkStart + ii;
409 const t_anaObs* anaObs = satStat.anaObs[iEpo];
410 double diff1 = anaObs->_MP1 - mean1;
411 double diff2 = anaObs->_MP2 - mean2;
412 stddev1 += diff1 * diff1;
413 stddev2 += diff2 * diff2;
414 }
415 double MP1 = sqrt(stddev1 / (numEpo-1));
416 double MP2 = sqrt(stddev2 / (numEpo-1));
417
418 const t_anaObs* anaObs0 = satStat.anaObs[chunkStart];
419
420 // Compute the Azimuth and Zenith Distance
421 // ---------------------------------------
422 double az = 0.0;
423 double zen = 0.0;
424 if (xyz.size()) {
425 t_eph* eph = 0;
426 for (int ie = 0; ie < _ephs.size(); ie++) {
427 if (_ephs[ie]->prn() == prn) {
428 eph = _ephs[ie];
429 break;
430 }
431 }
432
433 if (eph) {
434 double xSat, ySat, zSat, clkSat;
435 eph->position(anaObs0->_GPSWeek, anaObs0->_GPSWeeks,
436 xSat, ySat, zSat, clkSat);
437
438 double rho, eleSat, azSat;
439 topos(xyz(1), xyz(2), xyz(3), xSat, ySat, zSat, rho, eleSat, azSat);
440
441 az = azSat * 180.0/M_PI;
442 zen = 90.0 - eleSat * 180.0/M_PI;
443 }
444 }
445
446 // Add new Point
447 // -------------
448 (*dataMP1) << (new t_polarPoint(az, zen, MP1));
449 (*dataMP2) << (new t_polarPoint(az, zen, MP2));
450 (*dataSNR1) << (new t_polarPoint(az, zen, SNR1));
451 (*dataSNR2) << (new t_polarPoint(az, zen, SNR2));
452
453 if (_log) {
454 _log->setRealNumberNotation(QTextStream::FixedNotation);
455
456 _log->setRealNumberPrecision(2);
457 *_log << "MP1 " << prn << " " << az << " " << zen << " ";
458 _log->setRealNumberPrecision(3);
459 *_log << MP1 << endl;
460
461 _log->setRealNumberPrecision(2);
462 *_log << "MP2 " << prn << " " << az << " " << zen << " ";
463 _log->setRealNumberPrecision(3);
464 *_log << MP2 << endl;
465
466 _log->flush();
467 }
468 }
469}
Note: See TracBrowser for help on using the repository browser.