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

Last change on this file since 9797 was 9797, checked in by stuerze, 2 years ago

minor changes

File size: 35.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 <qwt_plot_renderer.h>
44
45#include "reqcanalyze.h"
46#include "bnccore.h"
47#include "bncsettings.h"
48#include "reqcedit.h"
49#include "bncutils.h"
50#include "graphwin.h"
51#include "availplot.h"
52#include "eleplot.h"
53#include "dopplot.h"
54#include "bncephuser.h"
55
56using namespace std;
57
58// Constructor
59////////////////////////////////////////////////////////////////////////////
60t_reqcAnalyze::t_reqcAnalyze(QObject* parent) : QThread(parent) {
61
62 bncSettings settings;
63
64 _logFileName = settings.value("reqcOutLogFile").toString(); expandEnvVar(_logFileName);
65 _logFile = 0;
66 _log = 0;
67 _currEpo = 0;
68 _obsFileNames = settings.value("reqcObsFile").toString().split(",", QString::SkipEmptyParts);
69 _navFileNames = settings.value("reqcNavFile").toString().split(",", QString::SkipEmptyParts);
70 _reqcPlotSignals = settings.value("reqcSkyPlotSignals").toString();
71 _defaultSignalTypes << "G:1&2&5" << "R:1&2&3" << "J:1&2" << "E:1&5" << "S:1&5" << "C:2&7" << "I:5&9";
72 if (_reqcPlotSignals.isEmpty()) {
73 _reqcPlotSignals = _defaultSignalTypes.join(" ");
74 }
75 analyzePlotSignals();
76
77 qRegisterMetaType< QVector<t_skyPlotData> >("QVector<t_skyPlotData>");
78
79 connect(this, SIGNAL(dspSkyPlot(const QString&, QVector<t_skyPlotData>,
80 const QByteArray&, double)),
81 this, SLOT(slotDspSkyPlot(const QString&, QVector<t_skyPlotData>,
82 const QByteArray&, double)));
83
84 connect(this, SIGNAL(dspAvailPlot(const QString&, const QByteArray&)),
85 this, SLOT(slotDspAvailPlot(const QString&, const QByteArray&)));
86}
87
88// Destructor
89////////////////////////////////////////////////////////////////////////////
90t_reqcAnalyze::~t_reqcAnalyze() {
91 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
92 delete _rnxObsFiles[ii];
93 }
94 for (int ii = 0; ii < _ephs.size(); ii++) {
95 delete _ephs[ii];
96 }
97 delete _log; _log = 0;
98 delete _logFile; _logFile = 0;
99 if (BNC_CORE->mode() != t_bncCore::interactive) {
100 qApp->exit(0);
101 msleep(100); //sleep 0.1 sec
102 }
103}
104
105//
106////////////////////////////////////////////////////////////////////////////
107void t_reqcAnalyze::run() {
108
109 static const double QC_FORMAT_VERSION = 1.1;
110
111 // Open Log File
112 // -------------
113 if (!_logFileName.isEmpty()) {
114 _logFile = new QFile(_logFileName);
115 if (_logFile->open(QIODevice::WriteOnly | QIODevice::Text)) {
116 _log = new QTextStream();
117 _log->setDevice(_logFile);
118 }
119 }
120
121 if (_log) {
122 *_log << "QC Format Version : " << QString("%1").arg(QC_FORMAT_VERSION,3,'f',1) << '\n' << '\n';
123 }
124
125 // Check Ephemerides
126 // -----------------
127 checkEphemerides();
128
129 // Initialize RINEX Observation Files
130 // ----------------------------------
131 t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles, _log);
132
133 // Read Ephemerides
134 // ----------------
135 t_reqcEdit::readEphemerides(_navFileNames, _ephs);
136
137 // Loop over all RINEX Files
138 // -------------------------
139 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
140 analyzeFile(_rnxObsFiles[ii]);
141 }
142
143 // Exit
144 // ----
145 emit finished();
146 deleteLater();
147}
148
149//
150////////////////////////////////////////////////////////////////////////////
151void t_reqcAnalyze::analyzePlotSignals() {
152
153 QStringList signalsOpt = _reqcPlotSignals.split(" ", QString::SkipEmptyParts);
154
155 for (int ii = 0; ii < signalsOpt.size(); ii++) {
156 QStringList input = signalsOpt.at(ii).split(QRegExp("[:&]"), QString::SkipEmptyParts);
157 if (input.size() > 1 && input[0].length() == 1) {
158 char system = input[0].toLatin1().constData()[0];
159 QStringList sysValid = _defaultSignalTypes.filter(QString(system));
160 if (!sysValid.isEmpty()) {
161 for (int iSig = 1; iSig < input.size(); iSig++) {
162 if (input[iSig].length() == 1 && input[iSig][0].isDigit()) {
163 _signalTypes[system].append(input[iSig][0].toLatin1());
164 }
165 }
166 }
167 }
168 }
169}
170
171//
172////////////////////////////////////////////////////////////////////////////
173void t_reqcAnalyze::analyzeFile(t_rnxObsFile* obsFile) {
174
175 _qcFile.clear();
176
177 // A priori Coordinates
178 // --------------------
179 ColumnVector xyzSta = obsFile->xyz();
180
181 // Loop over all Epochs
182 // --------------------
183 try {
184 QMap<QString, bncTime> lastObsTime;
185 bool firstEpo = true;
186 while ( (_currEpo = obsFile->nextEpoch()) != 0) {
187 if (firstEpo) {
188 firstEpo = false;
189 _qcFile._startTime = _currEpo->tt;
190 _qcFile._antennaName = obsFile->antennaName();
191 _qcFile._markerName = obsFile->markerName();
192 _qcFile._receiverType = obsFile->receiverType();
193 _qcFile._interval = obsFile->interval();
194 }
195 _qcFile._endTime = _currEpo->tt;
196
197 t_qcEpo qcEpo;
198 qcEpo._epoTime = _currEpo->tt;
199 qcEpo._PDOP = cmpDOP(xyzSta);
200
201 // Loop over all satellites
202 // ------------------------
203 for (unsigned iObs = 0; iObs < _currEpo->rnxSat.size(); iObs++) {
204 const t_rnxObsFile::t_rnxSat& rnxSat = _currEpo->rnxSat[iObs];
205 if (_navFileNames.size() && _numExpObs.find(rnxSat.prn) == _numExpObs.end()) {
206 _numExpObs[rnxSat.prn] = 0;
207 }
208 if (_signalTypes.find(rnxSat.prn.system()) == _signalTypes.end()) {
209 continue;
210 }
211 t_satObs satObs;
212 t_rnxObsFile::setObsFromRnx(obsFile, _currEpo, rnxSat, satObs);
213 t_qcSat& qcSat = qcEpo._qcSat[satObs._prn];
214 setQcObs(qcEpo._epoTime, xyzSta, satObs, lastObsTime, qcSat);
215 updateQcSat(qcSat, _qcFile._qcSatSum[satObs._prn]);
216 }
217 _qcFile._qcEpo.push_back(qcEpo);
218 }
219
220 analyzeMultipath();
221
222 if (_navFileNames.size()) {
223 setExpectedObs(_qcFile._startTime, _qcFile._endTime, _qcFile._interval, xyzSta);
224 }
225
226 preparePlotData(obsFile);
227
228 printReport(obsFile);
229 }
230 catch (QString str) {
231 if (_log) {
232 *_log << "Exception " << str << '\n';
233 }
234 else {
235 qDebug() << str;
236 }
237 }
238}
239
240// Compute Dilution of Precision
241////////////////////////////////////////////////////////////////////////////
242double t_reqcAnalyze::cmpDOP(const ColumnVector& xyzSta) const {
243
244 if ( xyzSta.size() != 3 || (xyzSta[0] == 0.0 && xyzSta[1] == 0.0 && xyzSta[2] == 0.0) ) {
245 return 0.0;
246 }
247
248 unsigned nSat = _currEpo->rnxSat.size();
249
250 if (nSat < 4) {
251 return 0.0;
252 }
253
254 Matrix AA(nSat, 4);
255
256 unsigned nSatUsed = 0;
257 for (unsigned iSat = 0; iSat < nSat; iSat++) {
258
259 const t_rnxObsFile::t_rnxSat& rnxSat = _currEpo->rnxSat[iSat];
260 const t_prn& prn = rnxSat.prn;
261
262 if (_signalTypes.find(prn.system()) == _signalTypes.end()) {
263 continue;
264 }
265
266 t_eph* eph = 0;
267 for (int ie = 0; ie < _ephs.size(); ie++) {
268 if (_ephs[ie]->prn() == prn) {
269 eph = _ephs[ie];
270 break;
271 }
272 }
273 if (eph) {
274 ColumnVector xSat(6);
275 ColumnVector vv(3);
276 if (eph->getCrd(_currEpo->tt, xSat, vv, false) == success) {
277 ++nSatUsed;
278 ColumnVector dx = xSat.Rows(1,3) - xyzSta;
279 double rho = dx.NormFrobenius();
280 AA(nSatUsed,1) = dx(1) / rho;
281 AA(nSatUsed,2) = dx(2) / rho;
282 AA(nSatUsed,3) = dx(3) / rho;
283 AA(nSatUsed,4) = 1.0;
284 }
285 }
286 }
287
288 if (nSatUsed < 4) {
289 return 0.0;
290 }
291
292 AA = AA.Rows(1, nSatUsed);
293
294 SymmetricMatrix QQ;
295 QQ << AA.t() * AA;
296 QQ = QQ.i();
297
298 return sqrt(QQ.trace());
299}
300
301//
302////////////////////////////////////////////////////////////////////////////
303void t_reqcAnalyze::updateQcSat(const t_qcSat& qcSat, t_qcSatSum& qcSatSum) {
304
305 for (int ii = 0; ii < qcSat._qcFrq.size(); ii++) {
306 const t_qcFrq& qcFrq = qcSat._qcFrq[ii];
307 t_qcFrqSum& qcFrqSum = qcSatSum._qcFrqSum[qcFrq._rnxType2ch];
308 qcFrqSum._numObs += 1;
309 if (qcFrq._slip) {
310 qcFrqSum._numSlipsFlagged += 1;
311 }
312 if (qcFrq._gap) {
313 qcFrqSum._numGaps += 1;
314 }
315 if (qcFrq._SNR > 0.0) {
316 qcFrqSum._numSNR += 1;
317 qcFrqSum._sumSNR += qcFrq._SNR;
318 }
319 }
320}
321
322//
323////////////////////////////////////////////////////////////////////////////
324void t_reqcAnalyze::setQcObs(const bncTime& epoTime, const ColumnVector& xyzSta,
325 const t_satObs& satObs, QMap<QString, bncTime>& lastObsTime,
326 t_qcSat& qcSat) {
327
328 t_eph* eph = 0;
329 for (int ie = 0; ie < _ephs.size(); ie++) {
330 if (_ephs[ie]->prn().system() == satObs._prn.system() &&
331 _ephs[ie]->prn().number() == satObs._prn.number()) {
332 eph = _ephs[ie];
333 break;
334 }
335 }
336 if (eph) {
337 ColumnVector xc(6);
338 ColumnVector vv(3);
339 if ( xyzSta.size() == 3 && (xyzSta[0] != 0.0 || xyzSta[1] != 0.0 || xyzSta[2] != 0.0) &&
340 eph->getCrd(epoTime, xc, vv, false) == success) {
341 double rho, eleSat, azSat;
342 topos(xyzSta(1), xyzSta(2), xyzSta(3), xc(1), xc(2), xc(3), rho, eleSat, azSat);
343 if (round(eleSat * 180.0/M_PI) >= 0.0) {
344 qcSat._eleSet = true;
345 qcSat._azDeg = azSat * 180.0/M_PI;
346 qcSat._eleDeg = eleSat * 180.0/M_PI;
347 }
348 }
349 if (satObs._prn.system() == 'R') {
350 qcSat._slotSet = true;
351 qcSat._slotNum = eph->slotNum();
352 }
353 }
354
355 // Availability and Slip Flags
356 // ---------------------------
357 for (unsigned ii = 0; ii < satObs._obs.size(); ii++) {
358 const t_frqObs* frqObs = satObs._obs[ii];
359
360 qcSat._qcFrq.push_back(t_qcFrq());
361 t_qcFrq& qcFrq = qcSat._qcFrq.back();
362
363 qcFrq._rnxType2ch = QString(frqObs->_rnxType2ch.c_str());
364 qcFrq._SNR = frqObs->_snr;
365 qcFrq._slip = frqObs->_slip;
366 qcFrq._phaseValid = frqObs->_phaseValid;
367 qcFrq._codeValid = frqObs->_codeValid;
368 // Check Gaps
369 // ----------
370 QString key = QString(satObs._prn.toString().c_str()) + qcFrq._rnxType2ch;
371 if (lastObsTime[key].valid()) {
372 double dt = epoTime - lastObsTime[key];
373 if (dt > 1.5 * _qcFile._interval) {
374 qcFrq._gap = true;
375 }
376 }
377 lastObsTime[key] = epoTime;
378
379 // Compute the Multipath Linear Combination
380 // ----------------------------------------
381 if (frqObs->_codeValid) {
382 t_frequency::type fA = t_frequency::dummy;
383 t_frequency::type fB = t_frequency::dummy;
384 char sys = satObs._prn.system();
385 if (_signalTypes.find(sys) != _signalTypes.end()) {
386 for (int iSig = 0; iSig < _signalTypes[sys].size(); iSig++) {
387 if (frqObs->_rnxType2ch[0] == _signalTypes[sys][iSig]) {
388 string frqType; frqType.push_back(sys); frqType.push_back(_signalTypes[sys][iSig]);
389 fA = t_frequency::toInt(frqType);
390 break;
391 }
392 }
393 if (fA != t_frequency::dummy) {
394 for (int iSig = 0; iSig < _signalTypes[sys].size(); iSig++) {
395 string frqType; frqType.push_back(sys); frqType.push_back(_signalTypes[sys][iSig]);
396 t_frequency::type fHlp = t_frequency::toInt(frqType);
397 if (fA != fHlp) {
398 fB = fHlp;
399 break;
400 }
401 }
402 }
403 if (fA != t_frequency::dummy && fB != t_frequency::dummy) {
404
405 double f_a = t_CST::freq(fA, qcSat._slotNum);
406 double f_b = t_CST::freq(fB, qcSat._slotNum);
407 double C_a = frqObs->_code;
408
409 bool foundA = false;
410 double L_a = 0.0;
411 bool foundB = false;
412 double L_b = 0.0;
413 for (unsigned jj = 0; jj < satObs._obs.size(); jj++) {
414 const t_frqObs* frqObsHlp = satObs._obs[jj];
415 if (frqObsHlp->_rnxType2ch[0] == t_frequency::toString(fA)[1] && frqObsHlp->_phaseValid) {
416 foundA = true;
417 L_a = frqObsHlp->_phase * t_CST::c / f_a;
418 }
419 else if (frqObsHlp->_rnxType2ch[0] == t_frequency::toString(fB)[1] && frqObsHlp->_phaseValid) {
420 foundB = true;
421 L_b = frqObsHlp->_phase * t_CST::c / f_b;
422 }
423 }
424 if (foundA && foundB && C_a) {
425 qcFrq._setMP = true;
426 qcFrq._rawMP = C_a - L_a - 2.0*f_b*f_b/(f_a*f_a-f_b*f_b) * (L_a - L_b);
427 }
428 }
429 }
430 }
431 } // satObs loop
432}
433
434//
435////////////////////////////////////////////////////////////////////////////
436void t_reqcAnalyze::analyzeMultipath() {
437
438 const double SLIPTRESH = 10.0; // cycle-slip threshold (meters)
439 const double chunkStep = 600.0; // 10 minutes
440
441 // Loop over all satellites available
442 // ----------------------------------
443 QMutableMapIterator<t_prn, t_qcSatSum> itSat(_qcFile._qcSatSum);
444 while (itSat.hasNext()) {
445 itSat.next();
446 const t_prn& prn = itSat.key();
447 t_qcSatSum& qcSatSum = itSat.value();
448
449 // Loop over all frequencies available
450 // -----------------------------------
451 QMutableMapIterator<QString, t_qcFrqSum> itFrq(qcSatSum._qcFrqSum);
452 while (itFrq.hasNext()) {
453 itFrq.next();
454 const QString& frqType = itFrq.key();
455 t_qcFrqSum& qcFrqSum = itFrq.value();
456
457 // Loop over all Chunks of Data
458 // ----------------------------
459 for (bncTime chunkStart = _qcFile._startTime;
460 chunkStart < _qcFile._endTime; chunkStart += chunkStep) {
461
462 bncTime chunkEnd = chunkStart + chunkStep;
463
464 QVector<t_qcFrq*> frqVec;
465 QVector<double> MP;
466
467 // Loop over all Epochs within one Chunk of Data
468 // ---------------------------------------------
469 for (int iEpo = 0; iEpo < _qcFile._qcEpo.size(); iEpo++) {
470 t_qcEpo& qcEpo = _qcFile._qcEpo[iEpo];
471 if (chunkStart <= qcEpo._epoTime && qcEpo._epoTime < chunkEnd) {
472 if (qcEpo._qcSat.contains(prn)) {
473 t_qcSat& qcSat = qcEpo._qcSat[prn];
474 for (int iFrq = 0; iFrq < qcSat._qcFrq.size(); iFrq++) {
475 t_qcFrq& qcFrq = qcSat._qcFrq[iFrq];
476 if (qcFrq._rnxType2ch == frqType) {
477 frqVec << &qcFrq;
478 if (qcFrq._setMP) {
479 MP << qcFrq._rawMP;
480 }
481 }
482 }
483 }
484 }
485 }
486
487 // Compute the multipath mean and standard deviation
488 // -------------------------------------------------
489 if (MP.size() > 1) {
490 double meanMP = 0.0;
491 for (int ii = 0; ii < MP.size(); ii++) {
492 meanMP += MP[ii];
493 }
494 meanMP /= MP.size();
495
496 bool slipMP = false;
497
498 double stdMP = 0.0;
499 for (int ii = 0; ii < MP.size(); ii++) {
500 double diff = MP[ii] - meanMP;
501 if (fabs(diff) > SLIPTRESH) {
502 slipMP = true;
503 break;
504 }
505 stdMP += diff * diff;
506 }
507
508 if (slipMP) {
509 stdMP = 0.0;
510 stdMP = 0.0;
511 qcFrqSum._numSlipsFound += 1;
512 }
513 else {
514 stdMP = sqrt(stdMP / (MP.size()-1));
515 qcFrqSum._numMP += 1;
516 qcFrqSum._sumMP += stdMP;
517 }
518
519 for (int ii = 0; ii < frqVec.size(); ii++) {
520 t_qcFrq* qcFrq = frqVec[ii];
521 if (slipMP) {
522 qcFrq->_slip = true;
523 }
524 else {
525 qcFrq->_stdMP = stdMP;
526 }
527 }
528 }
529 } // chunk loop
530 } // frq loop
531 } // sat loop
532}
533
534// Auxiliary Function for sorting MP data
535////////////////////////////////////////////////////////////////////////////
536bool t_reqcAnalyze::mpLessThan(const t_polarPoint* p1, const t_polarPoint* p2) {
537 return p1->_value < p2->_value;
538}
539
540//
541////////////////////////////////////////////////////////////////////////////
542void t_reqcAnalyze::preparePlotData(const t_rnxObsFile* obsFile) {
543
544 if (!BNC_CORE->GUIenabled()) {
545 return ;
546 }
547
548 QVector<t_skyPlotData> skyPlotDataMP;
549 QVector<t_skyPlotData> skyPlotDataSN;
550
551 for(QMap<char, QVector<char> >::iterator it1 = _signalTypes.begin();
552 it1 != _signalTypes.end(); it1++) {
553
554 char sys = it1.key();
555
556 for (int ii = 0; ii < it1.value().size(); ii++) {
557
558 skyPlotDataMP.append(t_skyPlotData(sys)); t_skyPlotData& dataMP = skyPlotDataMP.last();
559 skyPlotDataSN.append(t_skyPlotData(sys)); t_skyPlotData& dataSN = skyPlotDataSN.last();
560
561 dataMP._title = "Multipath\n" + QString(it1.key()) + ":" + it1.value()[ii] + " ";
562 dataSN._title = "Signal-to-Noise Ratio\n" + QString(it1.key()) + ":" + it1.value()[ii] + " ";
563
564 // Loop over all observations
565 // --------------------------
566 for (int iEpo = 0; iEpo < _qcFile._qcEpo.size(); iEpo++) {
567 t_qcEpo& qcEpo = _qcFile._qcEpo[iEpo];
568 QMapIterator<t_prn, t_qcSat> it2(qcEpo._qcSat);
569 while (it2.hasNext()) {
570 it2.next();
571 const t_qcSat& qcSat = it2.value();
572 if (qcSat._eleSet && it2.key().system() == sys) {
573 for (int iFrq = 0; iFrq < qcSat._qcFrq.size(); iFrq++) {
574 const t_qcFrq& qcFrq = qcSat._qcFrq[iFrq];
575 if (QString(it1.value()[ii]) == qcFrq._rnxType2ch.left(1)) {
576 (*dataMP._data) << (new t_polarPoint(qcSat._azDeg, 90.0 - qcSat._eleDeg, qcFrq._stdMP));
577 (*dataSN._data) << (new t_polarPoint(qcSat._azDeg, 90.0 - qcSat._eleDeg, qcFrq._SNR));
578 }
579 }
580 }
581 }
582 }
583
584 // Sort MP data (make the largest values always visible)
585 // -----------------------------------------------------
586 qStableSort(dataMP._data->begin(), dataMP._data->end(), mpLessThan);
587 }
588 }
589
590 // Show the plots
591 // --------------
592 QFileInfo fileInfo(obsFile->fileName());
593 QByteArray title = fileInfo.fileName().toLatin1();
594 emit dspSkyPlot(obsFile->fileName(), skyPlotDataMP, "Meters", 1.0);
595 emit dspSkyPlot(obsFile->fileName(), skyPlotDataSN, "dbHz", 54.0);
596 emit dspAvailPlot(obsFile->fileName(), title);
597}
598
599//
600////////////////////////////////////////////////////////////////////////////
601void t_reqcAnalyze::slotDspSkyPlot(const QString& fileName,
602 QVector<t_skyPlotData> skyPlotData,
603 const QByteArray& scaleTitle, double maxValue) {
604
605 if (BNC_CORE->GUIenabled()) {
606
607 if (maxValue == 0.0) {
608 QVectorIterator<t_skyPlotData> it(skyPlotData);
609 while (it.hasNext()) {
610 const t_skyPlotData& plotData = it.next();
611 const QVector<t_polarPoint*>* data = plotData._data;
612 for (int ii = 0; ii < data->size(); ii++) {
613 double val = data->at(ii)->_value;
614 if (maxValue < val) {
615 maxValue = val;
616 }
617 }
618 }
619 }
620
621 QwtInterval scaleInterval(0.0, maxValue);
622
623 QVector<QWidget*> plots;
624 QVector<int> rows;
625 QMutableVectorIterator<t_skyPlotData> it(skyPlotData);
626 int iRow = 0;
627 char sys = ' ';
628 while (it.hasNext()) {
629 t_skyPlotData& plotData = it.next();
630 QVector<t_polarPoint*>* data = plotData._data;
631 QwtText title(plotData._title);
632 QFont font = title.font(); font.setPointSize(font.pointSize()-1); title.setFont(font);
633 t_polarPlot* plot = new t_polarPlot(title, scaleInterval, BNC_CORE->mainWindow());
634 plot->addCurve(data);
635 plots << plot;
636 if (sys != ' ' && sys != plotData._sys) {
637 iRow += 1;
638 }
639 sys = plotData._sys;
640 rows << iRow;
641 }
642
643 t_graphWin* graphWin = new t_graphWin(0, fileName, plots, false,
644 &scaleTitle, &scaleInterval, &rows);
645
646 graphWin->show();
647
648 bncSettings settings;
649 QString dirName = settings.value("reqcPlotDir").toString();
650 if (!dirName.isEmpty()) {
651 QByteArray ext = (scaleTitle == "Meters") ? "_M.png" : "_S.png";
652 graphWin->savePNG(dirName, ext);
653 }
654 }
655}
656
657//
658////////////////////////////////////////////////////////////////////////////
659void t_reqcAnalyze::slotDspAvailPlot(const QString& fileName, const QByteArray& title) {
660
661 t_plotData plotData;
662 QMap<t_prn, t_plotData> plotDataMap;
663
664 for (int ii = 0; ii < _qcFile._qcEpo.size(); ii++) {
665 const t_qcEpo& qcEpo = _qcFile._qcEpo[ii];
666 double mjdX24 = qcEpo._epoTime.mjddec() * 24.0;
667
668 plotData._mjdX24 << mjdX24;
669 plotData._PDOP << qcEpo._PDOP;
670 plotData._numSat << qcEpo._qcSat.size();
671
672 QMapIterator<t_prn, t_qcSat> it(qcEpo._qcSat);
673 while (it.hasNext()) {
674 it.next();
675 const t_prn& prn = it.key();
676 const t_qcSat& qcSat = it.value();
677
678 t_plotData& data = plotDataMap[prn];
679
680 if (qcSat._eleSet) {
681 data._mjdX24 << mjdX24;
682 data._eleDeg << qcSat._eleDeg;
683 }
684
685 for (int iSig = 0; iSig < _signalTypes[prn.system()].size(); iSig++) {
686 char frqChar = _signalTypes[prn.system()][iSig];
687 QString frqType;
688 for (int iFrq = 0; iFrq < qcSat._qcFrq.size(); iFrq++) {
689 const t_qcFrq& qcFrq = qcSat._qcFrq[iFrq];
690 if (qcFrq._rnxType2ch[0] == frqChar && frqType.isEmpty()) {
691 frqType = qcFrq._rnxType2ch;
692 }
693 if (qcFrq._rnxType2ch == frqType) {
694 t_plotData::t_hlpStatus& status = data._status[frqChar];
695 if (qcFrq._slip) {
696 status._slip << mjdX24;
697 }
698 else if (qcFrq._gap) {
699 status._gap << mjdX24;
700 }
701 else {
702 status._ok << mjdX24;
703 }
704 }
705 }
706 }
707 }
708 }
709
710 if (BNC_CORE->GUIenabled()) {
711 t_availPlot* plotA = new t_availPlot(0, plotDataMap);
712 plotA->setTitle(title);
713
714 t_elePlot* plotZ = new t_elePlot(0, plotDataMap);
715
716 t_dopPlot* plotD = new t_dopPlot(0, plotData);
717
718 QVector<QWidget*> plots;
719 plots << plotA << plotZ << plotD;
720 t_graphWin* graphWin = new t_graphWin(0, fileName, plots, true);
721
722 int ww = QFontMetrics(graphWin->font()).width('w');
723 graphWin->setMinimumSize(120*ww, 40*ww);
724
725 graphWin->show();
726
727 bncSettings settings;
728 QString dirName = settings.value("reqcPlotDir").toString();
729 if (!dirName.isEmpty()) {
730 QByteArray ext = "_A.png";
731 graphWin->savePNG(dirName, ext);
732 }
733 }
734}
735
736// Finish the report
737////////////////////////////////////////////////////////////////////////////
738void t_reqcAnalyze::printReport(const t_rnxObsFile* obsFile) {
739
740 if (!_log) {
741 return;
742 }
743
744 QFileInfo obsFi(obsFile->fileName());
745 QString obsFileName = obsFi.fileName();
746
747 // Summary
748 // -------
749 *_log << "Observation File : " << obsFileName << '\n'
750 << "RINEX Version : " << QString("%1").arg(obsFile->version(),4,'f',2) << '\n'
751 << "Marker Name : " << _qcFile._markerName << '\n'
752 << "Marker Number : " << obsFile->markerNumber() << '\n'
753 << "Receiver : " << _qcFile._receiverType << '\n'
754 << "Antenna : " << _qcFile._antennaName << '\n'
755 << "Position XYZ : " << QString("%1 %2 %3").arg(obsFile->xyz()(1), 14, 'f', 4)
756 .arg(obsFile->xyz()(2), 14, 'f', 4)
757 .arg(obsFile->xyz()(3), 14, 'f', 4) << '\n'
758 << "Antenna dH/dE/dN : " << QString("%1 %2 %3").arg(obsFile->antNEU()(3), 8, 'f', 4)
759 .arg(obsFile->antNEU()(2), 8, 'f', 4)
760 .arg(obsFile->antNEU()(1), 8, 'f', 4) << '\n'
761 << "Start Time : " << _qcFile._startTime.datestr().c_str() << ' '
762 << _qcFile._startTime.timestr(1,'.').c_str() << '\n'
763 << "End Time : " << _qcFile._endTime.datestr().c_str() << ' '
764 << _qcFile._endTime.timestr(1,'.').c_str() << '\n'
765 << "Interval : " << _qcFile._interval << " sec" << '\n';
766
767 // Number of systems
768 // -----------------
769 QMap<QChar, QVector<const t_qcSatSum*> > systemMap;
770 QMapIterator<t_prn, t_qcSatSum> itSat(_qcFile._qcSatSum);
771 while (itSat.hasNext()) {
772 itSat.next();
773 const t_prn& prn = itSat.key();
774 const t_qcSatSum& qcSatSum = itSat.value();
775 systemMap[prn.system()].push_back(&qcSatSum);
776 }
777 *_log << "Navigation Systems : " << systemMap.size() << " ";
778
779 QMapIterator<QChar, QVector<const t_qcSatSum*> > itSys(systemMap);
780 while (itSys.hasNext()) {
781 itSys.next();
782 *_log << ' ' << itSys.key();
783 }
784 *_log << '\n';
785
786 // Observation types per system
787 // -----------------------------
788 for (int iSys = 0; iSys < obsFile->numSys(); iSys++) {
789 char sys = obsFile->system(iSys);
790 if (sys != ' ') {
791 *_log << "Observation Types " << sys << ":";
792 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
793 QString type = obsFile->obsType(sys, iType);
794 *_log << " " << type;
795 }
796 *_log << '\n';
797 }
798 }
799
800 // System specific summary
801 // -----------------------
802 itSys.toFront();
803 while (itSys.hasNext()) {
804 itSys.next();
805 const QChar& sys = itSys.key();
806 const QVector<const t_qcSatSum*>& qcSatVec = itSys.value();
807 int numExpectedObs = 0;
808 for(QMap<t_prn, int>::iterator it = _numExpObs.begin(); it != _numExpObs.end(); it++) {
809 if (sys == it.key().system()) {
810 numExpectedObs += it.value();
811 }
812 }
813 QString prefixSys = QString(" ") + sys + QString(": ");
814 QMap<QString, QVector<const t_qcFrqSum*> > frqMap;
815 for (int ii = 0; ii < qcSatVec.size(); ii++) {
816 const t_qcSatSum* qcSatSum = qcSatVec[ii];
817 QMapIterator<QString, t_qcFrqSum> itFrq(qcSatSum->_qcFrqSum);
818 while (itFrq.hasNext()) {
819 itFrq.next();
820 QString frqType = itFrq.key(); if (frqType.length() < 2) frqType += '?';
821 const t_qcFrqSum& qcFrqSum = itFrq.value();
822 frqMap[frqType].push_back(&qcFrqSum);
823 }
824 }
825 *_log << '\n'
826 << prefixSys << "Satellites: " << qcSatVec.size() << '\n'
827 << prefixSys << "Signals : " << frqMap.size() << " ";
828 QMapIterator<QString, QVector<const t_qcFrqSum*> > itFrq(frqMap);
829 while (itFrq.hasNext()) {
830 itFrq.next();
831 QString frqType = itFrq.key(); if (frqType.length() < 2) frqType += '?';
832 *_log << ' ' << frqType;
833 }
834 *_log << '\n';
835 QString prefixSys2 = " " + prefixSys;
836 itFrq.toFront();
837 while (itFrq.hasNext()) {
838 itFrq.next();
839 QString frqType = itFrq.key(); if (frqType.length() < 2) frqType += '?';
840 const QVector<const t_qcFrqSum*> qcFrqVec = itFrq.value();
841 QString prefixFrq = QString(" ") + frqType + QString(": ");
842 int numObs = 0;
843 int numSlipsFlagged = 0;
844 int numSlipsFound = 0;
845 int numGaps = 0;
846 int numSNR = 0;
847 int numMP = 0;
848 double sumSNR = 0.0;
849 double sumMP = 0.0;
850 for (int ii = 0; ii < qcFrqVec.size(); ii++) {
851 const t_qcFrqSum* qcFrqSum = qcFrqVec[ii];
852 numObs += qcFrqSum->_numObs ;
853 numSlipsFlagged += qcFrqSum->_numSlipsFlagged;
854 numSlipsFound += qcFrqSum->_numSlipsFound ;
855 numGaps += qcFrqSum->_numGaps ;
856 numSNR += qcFrqSum->_numSNR;
857 numMP += qcFrqSum->_numMP;
858 sumSNR += qcFrqSum->_sumSNR;
859 sumMP += qcFrqSum->_sumMP;
860 }
861 if (numSNR > 0) {
862 sumSNR /= numSNR;
863 }
864 if (numMP > 0) {
865 sumMP /= numMP;
866 }
867
868 double ratio = (double(numObs) / double(numExpectedObs)) * 100.0;
869
870 *_log << '\n'
871 << prefixSys2 << prefixFrq << "Observations : ";
872 if(_navFileNames.isEmpty() || numExpectedObs == 0.0 || _navFileIncomplete.contains(sys.toLatin1())) {
873 *_log << QString("%1\n").arg(numObs, 6);
874 }
875 else {
876 *_log << QString("%1 (%2) %3 \%\n").arg(numObs, 6).arg(numExpectedObs, 8).arg(ratio, 8, 'f', 2);
877 }
878 *_log << prefixSys2 << prefixFrq << "Slips (file+found): " << QString("%1 +").arg(numSlipsFlagged, 8)
879 << QString("%1\n").arg(numSlipsFound, 8)
880 << prefixSys2 << prefixFrq << "Gaps : " << QString("%1\n").arg(numGaps, 8)
881 << prefixSys2 << prefixFrq << "Mean SNR : " << QString("%1\n").arg(sumSNR, 8, 'f', 1)
882 << prefixSys2 << prefixFrq << "Mean Multipath : " << QString("%1\n").arg(sumMP, 8, 'f', 2);
883 }
884 }
885
886 // Epoch-Specific Output
887 // ---------------------
888 bncSettings settings;
889 if (Qt::CheckState(settings.value("reqcLogSummaryOnly").toInt()) == Qt::Checked) {
890 return;
891 }
892 *_log << '\n';
893 for (int iEpo = 0; iEpo < _qcFile._qcEpo.size(); iEpo++) {
894 const t_qcEpo& qcEpo = _qcFile._qcEpo[iEpo];
895
896 unsigned year, month, day, hour, min;
897 double sec;
898 qcEpo._epoTime.civil_date(year, month, day);
899 qcEpo._epoTime.civil_time(hour, min, sec);
900
901 QString dateStr;
902 QTextStream(&dateStr) << QString("> %1 %2 %3 %4 %5%6")
903 .arg(year, 4)
904 .arg(month, 2, 10, QChar('0'))
905 .arg(day, 2, 10, QChar('0'))
906 .arg(hour, 2, 10, QChar('0'))
907 .arg(min, 2, 10, QChar('0'))
908 .arg(sec, 11, 'f', 7);
909
910 *_log << dateStr << QString(" %1").arg(qcEpo._qcSat.size(), 2)
911 << QString(" %1").arg(qcEpo._PDOP, 4, 'f', 1)
912 << '\n';
913
914 QMapIterator<t_prn, t_qcSat> itSat(qcEpo._qcSat);
915 while (itSat.hasNext()) {
916 itSat.next();
917 const t_prn& prn = itSat.key();
918 const t_qcSat& qcSat = itSat.value();
919
920 *_log << prn.toString().c_str()
921 << QString(" %1 %2").arg(qcSat._eleDeg, 6, 'f', 2).arg(qcSat._azDeg, 7, 'f', 2);
922
923 int numObsTypes = 0;
924 for (int iFrq = 0; iFrq < qcSat._qcFrq.size(); iFrq++) {
925 const t_qcFrq& qcFrq = qcSat._qcFrq[iFrq];
926 if (qcFrq._phaseValid) {
927 numObsTypes += 1;
928 }
929 if (qcFrq._codeValid) {
930 numObsTypes += 1;
931 }
932 }
933 *_log << QString(" %1").arg(numObsTypes, 2);
934
935 for (int iFrq = 0; iFrq < qcSat._qcFrq.size(); iFrq++) {
936 const t_qcFrq& qcFrq = qcSat._qcFrq[iFrq];
937 if (qcFrq._phaseValid) {
938 *_log << " L" << qcFrq._rnxType2ch << ' ';
939 if (qcFrq._slip) {
940 *_log << 's';
941 }
942 else {
943 *_log << '.';
944 }
945 if (qcFrq._gap) {
946 *_log << 'g';
947 }
948 else {
949 *_log << '.';
950 }
951 *_log << QString(" %1").arg(qcFrq._SNR, 4, 'f', 1);
952 }
953 if (qcFrq._codeValid) {
954 *_log << " C" << qcFrq._rnxType2ch << ' ';
955 if (qcFrq._gap) {
956 *_log << " g";
957 }
958 else {
959 *_log << " .";
960 }
961 *_log << QString(" %1").arg(qcFrq._stdMP, 3, 'f', 2);
962 }
963 }
964 *_log << '\n';
965 }
966 }
967 _log->flush();
968}
969
970//
971////////////////////////////////////////////////////////////////////////////
972void t_reqcAnalyze::checkEphemerides() {
973
974 QString navFileName;
975 QStringListIterator namIt(_navFileNames);
976 bool firstName = true;
977 while (namIt.hasNext()) {
978 QFileInfo navFi(namIt.next());
979 if (firstName) {
980 firstName = false;
981 navFileName += navFi.fileName();
982 }
983 else {
984 navFileName += ", " + navFi.fileName();
985 }
986 }
987 if (_log) {
988 *_log << "Navigation File(s) : " << navFileName << '\n';
989 }
990 QStringListIterator it(_navFileNames);
991 while (it.hasNext()) {
992 const QString& fileName = it.next();
993 unsigned numOK = 0;
994 unsigned numBad = 0;
995 unsigned numUnhealthy = 0;
996 bncEphUser ephUser(false);
997 t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
998 for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
999 t_eph* eph = rnxNavFile.ephs()[ii];
1000 ephUser.putNewEph(eph, false);
1001 if (eph->checkState() == t_eph::bad) {
1002 ++numBad;
1003 }
1004 else if (eph->checkState() == t_eph::unhealthy) {
1005 ++numUnhealthy;
1006 }
1007 else {
1008 ++numOK;
1009 }
1010 }
1011 if (_log) {
1012 *_log << "Ephemeris : " << numOK << " OK "
1013 << numUnhealthy << " UNHEALTHY "
1014 << numBad << " WRONG\n";
1015 }
1016 if (numBad > 0 || numUnhealthy > 0) {
1017 for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
1018 t_eph* eph = rnxNavFile.ephs()[ii];
1019 QFileInfo navFi(fileName);
1020 if (_log) {
1021#ifdef BNC_DEBUG_BCEP
1022 if (eph->checkState() == t_eph::unhealthy) {
1023 *_log << " "
1024 << navFi.fileName() << ' ' << QString(": UNHEALTHY %2:%3\n")
1025 .arg(eph->navTypeString(eph->navType(), eph->prn(), 99.0))
1026 .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1();
1027 }
1028#endif
1029 if (eph->checkState() == t_eph::bad) {
1030 *_log << " "
1031 << navFi.fileName() << ' ' << QString(": WRONG %2:%3\n")
1032 .arg(eph->navTypeString(eph->navType(), eph->prn(), 99.0))
1033 .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1();
1034 }
1035 }
1036 }
1037 }
1038 }
1039 if (_log) {
1040 *_log << '\n';
1041 }
1042}
1043
1044void t_reqcAnalyze::setExpectedObs(const bncTime& startTime, const bncTime& endTime,
1045 double interval, const ColumnVector& xyzSta) {
1046
1047
1048 for(QMap<t_prn, int>::iterator it = _numExpObs.begin(); it != _numExpObs.end(); it++) {
1049 t_eph* eph = 0;
1050 for (int ie = 0; ie < _ephs.size(); ie++) {
1051 if (_ephs[ie]->prn().system() == it.key().system() &&
1052 _ephs[ie]->prn().number() == it.key().number()) {
1053 eph = _ephs[ie];
1054 break;
1055 }
1056 }
1057 if (eph) {
1058 int numExpObs = 0;
1059 bncTime epoTime;
1060 for (epoTime = startTime - interval; epoTime < endTime; epoTime = epoTime + interval) {
1061 ColumnVector xc(6);
1062 ColumnVector vv(3);
1063 if ( xyzSta.size() == 3 && (xyzSta[0] != 0.0 || xyzSta[1] != 0.0 || xyzSta[2] != 0.0) &&
1064 eph->getCrd(epoTime, xc, vv, false) == success) {
1065 double rho, eleSat, azSat;
1066 topos(xyzSta(1), xyzSta(2), xyzSta(3), xc(1), xc(2), xc(3), rho, eleSat, azSat);
1067 if (round(eleSat * 180.0/M_PI) >= 0.0) {
1068 numExpObs++;
1069 }
1070 }
1071 }
1072 it.value() = numExpObs;
1073 }
1074 else {
1075 if (!_navFileIncomplete.contains(it.key().system())) {
1076 _navFileIncomplete.append(it.key().system());
1077 }
1078 }
1079 }
1080}
Note: See TracBrowser for help on using the repository browser.