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

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