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

Last change on this file since 4565 was 4565, checked in by mervart, 12 years ago
File size: 13.5 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 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 double L2 = obs.measdata("L2", 3.0);
284 if (L1 != 0.0 && L2 != 0.0) {
285 double f1 = t_CST::f1(obs.satSys, obs.slotNum);
286 double f2 = t_CST::f2(obs.satSys, obs.slotNum);
287
288 L1 = L1 * t_CST::c / f1;
289 L2 = L2 * t_CST::c / f2;
290
291 double P1 = obs.measdata("C1", 3.0);
292 if (P1 != 0.0) {
293 newObs->_MP1 = P1 - L1 - 2.0*f2*f2/(f1*f1-f2*f2) * (L1 - L2);
294 okFlag = true;
295 }
296 double P2 = obs.measdata("C2", 3.0);
297 if (P2 != 0.0) {
298 newObs->_MP2 = P2 - L2 - 2.0*f1*f1/(f1*f1-f2*f2) * (L1 - L2);
299 okFlag = true;
300 }
301 }
302
303 // Signal-to-Noise
304 // ---------------
305 double S1 = obs.measdata("S1", 3.0);
306 if (S1 != 0.0) {
307 newObs->_SNR1 = floor(S1/6);
308 if (newObs->_SNR1 > 9.0) {
309 newObs->_SNR1 = 9.0;
310 }
311 if (newObs->_SNR1 < 1.0) {
312 newObs->_SNR1 = 1.0;
313 }
314 okFlag = true;
315 }
316 else {
317 if (obs.snrL1 > 0) {
318 newObs->_SNR1 = obs.snrL1;
319 okFlag = true;
320 }
321 }
322 double S2 = obs.measdata("S2", 3.0);
323 if (S2 != 0.0) {
324 newObs->_SNR2 = floor(S2/6);
325 if (newObs->_SNR2 > 9.0) {
326 newObs->_SNR2 = 9.0;
327 }
328 if (newObs->_SNR2 < 1.0) {
329 newObs->_SNR2 = 1.0;
330 }
331 okFlag = true;
332 }
333 else {
334 if (obs.snrL2 > 0) {
335 newObs->_SNR2 = obs.snrL2;
336 okFlag = true;
337 }
338 }
339
340 // Remember the Observation
341 // ------------------------
342 if (okFlag) {
343 anaObs << newObs;
344 }
345 else {
346 delete newObs;
347 }
348}
349
350//
351////////////////////////////////////////////////////////////////////////////
352void t_reqcAnalyze::analyzeMultipathAndSNR(const QString& prn,
353 const t_satStat& satStat,
354 const ColumnVector& xyz,
355 double obsInterval,
356 QVector<t_polarPoint*>* dataMP1,
357 QVector<t_polarPoint*>* dataMP2,
358 QVector<t_polarPoint*>* dataSNR1,
359 QVector<t_polarPoint*>* dataSNR2) {
360
361 const int chunkStep = int( 30.0 / obsInterval); // chunk step (30 sec)
362 const int numEpo = int(600.0 / obsInterval); // # epochs in one chunk (10 min)
363
364 for (int chunkStart = 0; chunkStart + numEpo < satStat.anaObs.size();
365 chunkStart += chunkStep) {
366
367 // Compute Mean
368 // ------------
369 bool slipFlag = false;
370 double mean1 = 0.0;
371 double mean2 = 0.0;
372 double SNR1 = 0.0;
373 double SNR2 = 0.0;
374
375
376 for (int ii = 0; ii < numEpo; ii++) {
377 int iEpo = chunkStart + ii;
378 const t_anaObs* anaObs = satStat.anaObs[iEpo];
379 mean1 += anaObs->_MP1;
380 mean2 += anaObs->_MP2;
381
382 SNR1 = anaObs->_SNR1;
383 SNR2 = anaObs->_SNR2;
384
385 // Check Slip
386 // ----------
387 if (ii > 0) {
388 double diff1 = anaObs->_MP1 - satStat.anaObs[iEpo-1]->_MP1;
389 double diff2 = anaObs->_MP2 - satStat.anaObs[iEpo-1]->_MP2;
390 if (fabs(diff1) > SLIPTRESH || fabs(diff2) > SLIPTRESH) {
391 slipFlag = true;
392 break;
393 }
394 }
395 }
396
397 if (slipFlag) {
398 continue;
399 }
400
401 mean1 /= numEpo;
402 mean2 /= numEpo;
403
404 // Compute Standard Deviation
405 // --------------------------
406 double stddev1 = 0.0;
407 double stddev2 = 0.0;
408 for (int ii = 0; ii < numEpo; ii++) {
409 int iEpo = chunkStart + ii;
410 const t_anaObs* anaObs = satStat.anaObs[iEpo];
411 double diff1 = anaObs->_MP1 - mean1;
412 double diff2 = anaObs->_MP2 - mean2;
413 stddev1 += diff1 * diff1;
414 stddev2 += diff2 * diff2;
415 }
416 double MP1 = sqrt(stddev1 / (numEpo-1));
417 double MP2 = sqrt(stddev2 / (numEpo-1));
418
419 const t_anaObs* anaObs0 = satStat.anaObs[chunkStart];
420
421 // Compute the Azimuth and Zenith Distance
422 // ---------------------------------------
423 double az = 0.0;
424 double zen = 0.0;
425 if (xyz.size()) {
426 t_eph* eph = 0;
427 for (int ie = 0; ie < _ephs.size(); ie++) {
428 if (_ephs[ie]->prn() == prn) {
429 eph = _ephs[ie];
430 break;
431 }
432 }
433
434 if (eph) {
435 double xSat, ySat, zSat, clkSat;
436 eph->position(anaObs0->_GPSWeek, anaObs0->_GPSWeeks,
437 xSat, ySat, zSat, clkSat);
438
439 double rho, eleSat, azSat;
440 topos(xyz(1), xyz(2), xyz(3), xSat, ySat, zSat, rho, eleSat, azSat);
441
442 az = azSat * 180.0/M_PI;
443 zen = 90.0 - eleSat * 180.0/M_PI;
444 }
445 }
446
447 // Add new Point
448 // -------------
449 (*dataMP1) << (new t_polarPoint(az, zen, MP1));
450 (*dataMP2) << (new t_polarPoint(az, zen, MP2));
451 (*dataSNR1) << (new t_polarPoint(az, zen, SNR1));
452 (*dataSNR2) << (new t_polarPoint(az, zen, SNR2));
453
454 if (_log) {
455 _log->setRealNumberNotation(QTextStream::FixedNotation);
456
457 _log->setRealNumberPrecision(2);
458 *_log << "MP1 " << prn << " " << az << " " << zen << " ";
459 _log->setRealNumberPrecision(3);
460 *_log << MP1 << endl;
461
462 _log->setRealNumberPrecision(2);
463 *_log << "MP2 " << prn << " " << az << " " << zen << " ";
464 _log->setRealNumberPrecision(3);
465 *_log << MP2 << endl;
466
467 _log->flush();
468 }
469 }
470}
Note: See TracBrowser for help on using the repository browser.