source: ntrip/trunk/BNC/src/ssrQc.cpp@ 11214

Last change on this file since 11214 was 11214, checked in by stuerze, 2 days ago

SSR QC improved

File size: 86.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_ssrQc
30 *
31 * Purpose: Quality control of decoded SSR streams
32 *
33 * Created: 05-Oct-2026
34 *
35 * Changes:
36 *
37 * -----------------------------------------------------------------------*/
38
39#include <algorithm>
40#include <cmath>
41#include <iomanip>
42
43#include "ssrQc.h"
44#include "ssrRefSig.h"
45#include "combination/bncbiassnx.h"
46#include "bnccore.h"
47#include "bncutils.h"
48#include "bncconst.h"
49#include "bncsettings.h"
50#include "combination/bnccomb.h"
51#include "bncantex.h"
52
53using namespace std;
54
55namespace {
56 const double MAX_CLK_JUMP = 0.5; // [m] clock change beyond its rate between consecutive epochs
57 const double EPH_WARMUP = 120.0; // [s] no ephemeris checks at the start
58 const double EPH_EARLY_MAX = 300.0; // [s] IOD received this much later still counted as early
59 const double EPH_IOD_REUSE = 21600.0; // [s] an outdated data set this far from the epoch: IOD reused
60 const unsigned EPH_KEPT = 30; // data sets kept per satellite
61 const double CMP_SAMPL = 30.0; // [s] sampling of the stream comparison
62 const double CMP_DELAY = 60.0; // [s] epochs compared when data this much newer arrived
63 const double HIST_LENGTH = 300.0; // [s] corrections kept for the comparison
64 const double DEV_MIN = 0.05; // [m] deviating satellites: RMS above max(DEV_MIN,
65 const double DEV_FACTOR = 3.0; // DEV_FACTOR x median RMS of the system)
66 const double ATT_ONSET = 20.0 * M_PI / 180.0; // [rad] change of the yaw difference starting a turn
67 const double ATT_STABLE = 2.0 * M_PI / 180.0; // [rad] yaw difference stable again ...
68 const double ATT_STABLE_T = 600.0; // [s] ... for this time: end of the turn
69 const double ATT_REF_FROM = 900.0; // [s] reference before the turn: samples from 15 min
70 const double ATT_REF_TO = 300.0; // to 5 min before the current epoch
71 const double ATT_MAX_GAP = 600.0; // [s] longer gaps interrupt a turn
72 const double ATT_MAX_TURN = 10800.0; // [s] a turn is closed after 3 h at the latest
73 const double ATT_MIN_PRED = 0.03; // [m] smaller predicted clock changes are not assessed
74 const double VTEC_CMP_SAMPL = 300.0; // [s] sampling of the VTEC comparison
75 const double VTEC_CMP_DELAY = 120.0; // [s] VTEC epochs compared when data this much newer arrived
76 const double VTEC_HIST = 3600.0; // [s] VTEC models kept for the comparison
77 const double VTEC_GRID_LAT = 10.0; // [deg] grid of the VTEC evaluation, latitudes -80 ... 80
78 const double VTEC_GRID_LON = 15.0; // [deg]
79 const double MW_SAMPL = 300.0; // [s] sampling of the Melbourne-Wuebbena check
80 const double MW_MAX_AGE = 900.0; // [s] phase biases older than this are not used
81 const int MW_MIN_SAT = 4; // satellites needed for the common offset
82 const double MW_OK = 0.10; // [cycles] RMS of the fractional parts: consistent below,
83 const double MW_BAD = 0.15; // not consistent above (uniform: 0.29)
84
85 double tKey(const bncTime& tt) {
86 return tt.gpsw() * 604800.0 + tt.gpssec();
87 }
88 const char* TYPE_NAME[] = {"ORBIT", "CLOCK", "CODE_BIAS", "PHASE_BIAS", "VTEC"};
89
90 double median(QVector<double> vv) {
91 if (vv.isEmpty()) {
92 return 0.0;
93 }
94 std::sort(vv.begin(), vv.end());
95 int nn = vv.size();
96 return (nn % 2) ? vv[nn/2] : 0.5 * (vv[nn/2-1] + vv[nn/2]);
97 }
98
99 bncTime currentTime() {
100 int week = 0;
101 double sec = 0.0;
102 currentGPSWeeks(week, sec);
103 return bncTime(week, sec);
104 }
105
106 // satellite list "G01 G05(12)", counts shown if not all epochs concerned
107 QString satList(const QMap<QString, unsigned>& sats, unsigned maxNum = 20) {
108 QString str;
109 unsigned num = 0;
110 QMapIterator<QString, unsigned> it(sats);
111 while (it.hasNext()) {
112 it.next();
113 if (++num > maxNum) {
114 str += QString(" ... (%1 satellites)").arg(sats.size());
115 break;
116 }
117 str += " " + it.key();
118 if (it.value() > 0) {
119 str += QString("(%1)").arg(it.value());
120 }
121 }
122 return str.isEmpty() ? " -" : str;
123 }
124}
125
126// Constructor
127////////////////////////////////////////////////////////////////////////////
128t_ssrQc::t_ssrQc(const QString& dirName, double interval, const QStringList& streams,
129 const QString& reference) : _ephUser(true, EPH_KEPT) {
130 _ephUser.useEphMounts("SSR QC");
131 _dirName = dirName;
132 _reference = reference.isEmpty() ? QString("CONSENSUS") : reference;
133 _interval = interval > 0.0 ? interval : 3600.0;
134 // "ALL" or a list of streams; streams with a leading '!' are excluded
135 // (from the reports and from the consensus)
136 bool all = false;
137 for (const QString& sta : streams) {
138 if (sta.startsWith('!')) {
139 _excluded.insert(sta.mid(1));
140 }
141 else if (sta.toUpper() == "ALL") {
142 all = true;
143 }
144 else {
145 _streams.insert(sta);
146 }
147 }
148 if (all) {
149 _streams.clear();
150 }
151
152 BNC_CORE->connectMessages(this, "ssrqc");
153 BNC_CORE->connectLogRecords(this, "ssrqc");
154 for (const QString& err : t_ssrRefSig::init()) {
155 emit newLogRecord(t_logRecord::message(t_logRecord::warning, ("SSR QC: " + err).toLatin1()), true);
156 }
157 // reference code biases from a Bias SINEX file (optional)
158 _bsxRef = 0;
159 bncSettings settings;
160 QString bsxFile = settings.value("ssrQcBiasFile").toString();
161 expandEnvVar(bsxFile);
162 if (!bsxFile.isEmpty()) {
163 _bsxRef = new bncBiasSnx(true);
164 if (_bsxRef->readFile(bsxFile) == success) {
165 _bsxName = QFileInfo(bsxFile).fileName();
166 }
167 else {
168 emit newLogRecord(t_logRecord::message(t_logRecord::warning, ("SSR QC: wrong Bias SINEX file " + bsxFile).toLatin1()), true);
169 delete _bsxRef;
170 _bsxRef = 0;
171 }
172 }
173 _antex = 0;
174 QString antexFile = settings.value("ssrQcAntexFile").toString();
175 expandEnvVar(antexFile);
176 if (!antexFile.isEmpty()) {
177 _antex = new bncAntex();
178 if (_antex->readFile(antexFile) != success || _antex->numSatPrns() == 0) {
179 emit newLogRecord(t_logRecord::message(t_logRecord::warning, ("SSR QC: wrong ANTEX file " + antexFile + " - no attitude check").toLatin1()), true);
180 delete _antex;
181 _antex = 0;
182 }
183 }
184 connect(BNC_CORE, SIGNAL(newOrbCorrections(QList<t_orbCorr>)),
185 this, SLOT(slotNewOrbCorrections(QList<t_orbCorr>)), Qt::DirectConnection);
186 connect(BNC_CORE, SIGNAL(newClkCorrections(QList<t_clkCorr>)),
187 this, SLOT(slotNewClkCorrections(QList<t_clkCorr>)), Qt::DirectConnection);
188 connect(BNC_CORE, SIGNAL(newCodeBiases(QList<t_satCodeBias>)),
189 this, SLOT(slotNewCodeBiases(QList<t_satCodeBias>)), Qt::DirectConnection);
190 connect(BNC_CORE, SIGNAL(newPhaseBiases(QList<t_satPhaseBias>)),
191 this, SLOT(slotNewPhaseBiases(QList<t_satPhaseBias>)), Qt::DirectConnection);
192 connect(BNC_CORE, SIGNAL(newTec(t_vTec)),
193 this, SLOT(slotNewTec(t_vTec)), Qt::DirectConnection);
194 // combined corrections (stream INTERNAL)
195 if (bncComb::exists()) {
196 connect(BNC_CMB, SIGNAL(newOrbCorrections(QList<t_orbCorr>)),
197 this, SLOT(slotNewOrbCorrections(QList<t_orbCorr>)), Qt::DirectConnection);
198 connect(BNC_CMB, SIGNAL(newClkCorrections(QList<t_clkCorr>)),
199 this, SLOT(slotNewClkCorrections(QList<t_clkCorr>)), Qt::DirectConnection);
200 }
201}
202
203// Stream selected for the QC
204////////////////////////////////////////////////////////////////////////////
205bool t_ssrQc::selected(const string& staID) const {
206 QString sta = QString::fromStdString(staID);
207 return !_excluded.contains(sta) && (_streams.isEmpty() || _streams.contains(sta));
208}
209
210// Analysis center of a stream: the 3 characters of the AC in mountpoints
211// like SSRA00CNE1 or OSBC00WHU1, otherwise the stream name itself
212////////////////////////////////////////////////////////////////////////////
213QString t_ssrQc::acOf(const QString& staID) {
214 static const QRegularExpression re("^(?:SSR[AC]|OSB[AC]|IONO)[0-9]{2}([A-Z0-9]{3})[0-9]$");
215 QRegularExpressionMatch mm = re.match(staID);
216 return mm.hasMatch() ? mm.captured(1) : staID;
217}
218
219// Solution of an AC: AC and the two digits of the mountpoint, e.g. GFZ00 for
220// SSRA00GFZ0/SSRC00GFZ1 and GFZ01 for SSRA01GFZ0; the streams of a solution
221// (formats, APC/CoM) have one vote in the consensus
222////////////////////////////////////////////////////////////////////////////
223QString t_ssrQc::solOf(const QString& staID) {
224 static const QRegularExpression re("^(?:SSR[AC]|OSB[AC]|IONO)([0-9]{2})([A-Z0-9]{3})[0-9]$");
225 QRegularExpressionMatch mm = re.match(staID);
226 return mm.hasMatch() ? mm.captured(2) + mm.captured(1) : staID;
227}
228
229// AC of a solution (GFZ01 -> GFZ)
230////////////////////////////////////////////////////////////////////////////
231QString t_ssrQc::acOfSol(const QString& sol) {
232 static const QRegularExpression re("^([A-Z0-9]{3})[0-9]{2}$");
233 QRegularExpressionMatch mm = re.match(sol);
234 return mm.hasMatch() ? mm.captured(1) : sol;
235}
236
237// Stream part of the consensus: not excluded, and not a combination product
238// (INTERNAL, IGS combinations), as these are derived from the other streams
239////////////////////////////////////////////////////////////////////////////
240bool t_ssrQc::votes(const QString& staID) const {
241 return !_excluded.contains(staID) && staID != "INTERNAL" && acOf(staID) != "IGS";
242}
243
244// Daily QC file of a stream: <staID>_S_<YYYYDDD>0000_01D_QC.txt
245////////////////////////////////////////////////////////////////////////////
246ofstream& t_ssrQc::streamOut(const QString& staID, const bncTime& time) {
247 unsigned year, month, day;
248 time.civil_date(year, month, day);
249 QDate date(year, month, day);
250 QString name = QDir(_dirName).filePath(QString("%1_S_%2%3%4_01D_QC.txt").arg(staID)
251 .arg(year).arg(date.dayOfYear(), 3, 10, QChar('0')).arg("0000"));
252 if (_outNames.value(staID) != name) {
253 delete _outs.value(staID, 0);
254 bool exists = QFile::exists(name);
255 ofstream* out = new ofstream(name.toLocal8Bit().data(), ios_base::out | ios_base::app);
256 if (!exists) {
257 *out << "SSR QC of stream " << staID.toStdString() << ", report interval " << _interval << " s" << endl
258 << "Checks: epochs and update intervals, gaps (interval > 2 x max(declared, median)), latency,"
259 << " completeness w.r.t. healthy broadcast ephemerides," << endl
260 << "IOD matching, code and phase bias signals, phase bias indicators, Melbourne-Wuebbena consistency"
261 << " with the other ACs, yaw angle, code biases of the reference signals,"
262 << " code biases of APC and CoM streams, clock jumps > "
263 << MAX_CLK_JUMP << " m, largest orbit corrections, VTEC models (system V)" << endl
264 << "Reference signals of the clocks: " << t_ssrRefSig::currentString().toStdString() << endl;
265 }
266 _outs[staID] = out;
267 _outNames[staID] = name;
268 }
269 return *_outs[staID];
270}
271
272// Destructor
273////////////////////////////////////////////////////////////////////////////
274t_ssrQc::~t_ssrQc() {
275 QMutexLocker locker(&_mutex);
276 writeReport(true);
277 for (ofstream* out : _outs) {
278 delete out;
279 }
280 delete _bsxRef;
281 delete _antex;
282}
283
284// Key of the epoch statistics
285////////////////////////////////////////////////////////////////////////////
286QString t_ssrQc::key(const string& staID, char sys, e_type type) {
287 return QString("%1 %2 %3").arg(staID.c_str()).arg(sys).arg(int(type));
288}
289
290// Reference signals of the clocks (as in the combination, option ssrRefSignals)
291////////////////////////////////////////////////////////////////////////////
292bool t_ssrQc::refSignals(char sys, QString& sig1, QString& sig2,
293 t_frequency::type& frq1, t_frequency::type& frq2) {
294 t_ssrRefSig::t_pair pair;
295 if (!t_ssrRefSig::get(sys, pair)) {
296 return false;
297 }
298 sig1 = QString::fromStdString(pair.sig1());
299 sig2 = QString::fromStdString(pair.sig2());
300 frq1 = pair.frq1;
301 frq2 = pair.frq2;
302 return true;
303}
304
305// Start a new report interval if the epoch is beyond the current one
306////////////////////////////////////////////////////////////////////////////
307void t_ssrQc::checkInterval(const bncTime& time) {
308 if (!_intervalStart.valid()) {
309 double sec = floor(time.gpssec() / _interval) * _interval;
310 _intervalStart = bncTime(time.gpsw(), sec);
311 }
312 // stream comparison of the epochs already complete for all streams
313 if (!_nextCmpEpoch.valid()) {
314 double sec = ceil(time.gpssec() / CMP_SAMPL) * CMP_SAMPL;
315 _nextCmpEpoch = bncTime(time.gpsw(), sec);
316 }
317 while (time - _nextCmpEpoch >= CMP_DELAY) {
318 compareEpoch(_nextCmpEpoch);
319 _nextCmpEpoch = _nextCmpEpoch + CMP_SAMPL;
320 }
321 // Melbourne-Wuebbena check of the phase biases
322 if (!_pbLast.isEmpty()) {
323 if (!_nextMwCmp.valid()) {
324 double sec = ceil(time.gpssec() / MW_SAMPL) * MW_SAMPL;
325 _nextMwCmp = bncTime(time.gpsw(), sec);
326 }
327 while (time - _nextMwCmp >= CMP_DELAY) {
328 compareMw(_nextMwCmp);
329 _nextMwCmp = _nextMwCmp + MW_SAMPL;
330 }
331 }
332 // VTEC comparison
333 if (!_vtecHist.isEmpty()) {
334 if (!_nextVtecCmp.valid()) {
335 double sec = ceil(time.gpssec() / VTEC_CMP_SAMPL) * VTEC_CMP_SAMPL;
336 _nextVtecCmp = bncTime(time.gpsw(), sec);
337 }
338 while (time - _nextVtecCmp >= VTEC_CMP_DELAY) {
339 compareVtec(_nextVtecCmp);
340 _nextVtecCmp = _nextVtecCmp + VTEC_CMP_SAMPL;
341 }
342 }
343 if (time - _intervalStart >= _interval) {
344 writeReport(false);
345 double sec = floor(time.gpssec() / _interval) * _interval;
346 _intervalStart = bncTime(time.gpsw(), sec);
347 }
348 if (!_lastTime.valid() || _lastTime < time) {
349 _lastTime = time;
350 }
351}
352
353// Epoch statistics
354////////////////////////////////////////////////////////////////////////////
355void t_ssrQc::newEpoch(const string& staID, char sys, e_type type, const bncTime& time,
356 unsigned updateInt, const QString& prn) {
357 QString sta = QString::fromStdString(staID);
358 if (!_staStart.contains(sta)) {
359 _staStart[sta] = time;
360 }
361 if (!_staLast.contains(sta) || _staLast[sta] < time) {
362 _staLast[sta] = time;
363 }
364 t_epoStat& stat = _epoStat[key(staID, sys, type)];
365 if (updateInt < unsigned(ssrUpdateInt.size())) {
366 stat.nominal = ssrUpdateInt[updateInt];
367 }
368 stat.sats.insert(prn);
369 if (!stat.last.valid() || stat.last < time) {
370 if (stat.last.valid()) {
371 stat.intervals.push_back(time - stat.last);
372 }
373 stat.last = time;
374 stat.numEpo += 1;
375 stat.latencies.push_back(currentTime() - time);
376 }
377 else if (time < stat.last) {
378 stat.numOutOfOrder += 1;
379 }
380}
381
382// Broadcast ephemeris the correction refers to
383////////////////////////////////////////////////////////////////////////////
384void t_ssrQc::checkEph(t_satStat& stat, const QString& satKey, const QString& prnInt,
385 unsigned iod, const bncTime& time, const string& staID) {
386 // not before all broadcast ephemerides may have been received
387 if (time - _staStart[QString::fromStdString(staID)] < EPH_WARMUP) {
388 return;
389 }
390 if (!_ephUser.ephLast(prnInt)) {
391 stat.noEph += 1;
392 return;
393 }
394 // any data set kept, not only the last two: Galileo has a new IODnav every
395 // 10 minutes, and ACs keep one for up to an hour
396 t_eph* eph = _ephUser.ephWithIOD(prnInt, iod);
397 // an IOD used again later (GLONASS tb every day, GPS IODE) is another data set
398 if (eph && outDatedBcep(eph, time) && fabs(time - eph->TOC()) > EPH_IOD_REUSE) {
399 eph = 0;
400 }
401 if (!eph) {
402 // received later from the ephemeris stream(s)? decided in resolvePendingIod
403 t_pendingIod& pending = _pendingIod[satKey][iod];
404 if (pending.num == 0) {
405 pending.prnInt = prnInt;
406 pending.first = currentTime();
407 }
408 pending.num += 1;
409 }
410 else if (eph->checkState() == t_eph::unhealthy || eph->checkState() == t_eph::bad) {
411 stat.ephUnhealthy += 1;
412 }
413 else if (outDatedBcep(eph, time)) {
414 stat.ephOutdated += 1;
415 }
416 if (_pendingIod.contains(satKey)) {
417 resolvePendingIod(satKey, false);
418 }
419}
420
421// Corrections referring to an IOD not received before: counted as early if
422// the ephemeris stream(s) delivered the data set later, as unknown if not
423// within EPH_EARLY_MAX (or at the end of the report interval, final)
424////////////////////////////////////////////////////////////////////////////
425void t_ssrQc::resolvePendingIod(const QString& satKey, bool final) {
426 t_satStat& stat = _satStat[satKey];
427 QMap<unsigned, t_pendingIod>& pend = _pendingIod[satKey];
428 QMutableMapIterator<unsigned, t_pendingIod> it(pend);
429 while (it.hasNext()) {
430 it.next();
431 const t_pendingIod& pending = it.value();
432 t_eph* eph = _ephUser.ephWithIOD(pending.prnInt, it.key());
433 if (eph && eph->receptDateTime().isValid()) {
434 bncTime recept(eph->receptDateTime().toString(Qt::ISODate).toStdString());
435 if (recept >= pending.first) {
436 stat.iodEarly += pending.num;
437 stat.maxEarly = max(stat.maxEarly, recept - pending.first);
438 it.remove();
439 continue;
440 }
441 }
442 if (final || currentTime() - pending.first > EPH_EARLY_MAX) {
443 stat.iodUnknown += pending.num;
444 it.remove();
445 }
446 }
447 if (pend.isEmpty()) {
448 _pendingIod.remove(satKey);
449 }
450}
451
452// Orbit corrections
453////////////////////////////////////////////////////////////////////////////
454void t_ssrQc::slotNewOrbCorrections(QList<t_orbCorr> orbCorrections) {
455 QMutexLocker locker(&_mutex);
456 for (const t_orbCorr& corr : orbCorrections) {
457 if (!_excluded.contains(QString::fromStdString(corr._staID)) || corr._staID == _reference.toStdString()) {
458 storeHist(&corr, 0);
459 }
460 _orbFormat[QString::fromStdString(corr._staID)] = corr._ssrFormat;
461 if (!selected(corr._staID)) continue;
462 QString prn = QString::fromStdString(corr._prn.toString());
463 checkInterval(corr._time);
464 newEpoch(corr._staID, corr._prn.system(), ORB, corr._time, corr._updateInt, prn);
465 t_satStat& stat = _satStat[QString::fromStdString(corr._staID) + ' ' + prn];
466 stat.numOrb += 1;
467 checkEph(stat, QString::fromStdString(corr._staID) + ' ' + prn,
468 QString::fromStdString(corr._prn.toInternalString()), corr._iod, corr._time, corr._staID);
469 double radial = fabs(corr._xr[0]);
470 double alongCross = max(fabs(corr._xr[1]), fabs(corr._xr[2]));
471 stat.maxRadial = max(stat.maxRadial, radial);
472 stat.maxAlongCross = max(stat.maxAlongCross, alongCross);
473 }
474}
475
476// Clock corrections
477////////////////////////////////////////////////////////////////////////////
478void t_ssrQc::slotNewClkCorrections(QList<t_clkCorr> clkCorrections) {
479 QMutexLocker locker(&_mutex);
480 for (const t_clkCorr& corr : clkCorrections) {
481 if (!_excluded.contains(QString::fromStdString(corr._staID)) || corr._staID == _reference.toStdString()) {
482 storeHist(0, &corr);
483 }
484 if (!selected(corr._staID)) continue;
485 QString prn = QString::fromStdString(corr._prn.toString());
486 checkInterval(corr._time);
487 newEpoch(corr._staID, corr._prn.system(), CLK, corr._time, corr._updateInt, prn);
488 t_satStat& stat = _satStat[QString::fromStdString(corr._staID) + ' ' + prn];
489 stat.numClk += 1;
490 checkEph(stat, QString::fromStdString(corr._staID) + ' ' + prn,
491 QString::fromStdString(corr._prn.toInternalString()), corr._iod, corr._time, corr._staID);
492
493 // jump: change between consecutive epochs (same IOD) beyond the clock rate
494 double clk = corr._dClk * t_CST::c;
495 if (stat.lastClkTime.valid() && stat.lastIod == corr._iod) {
496 double dt = corr._time - stat.lastClkTime;
497 int nominal = (corr._updateInt < unsigned(ssrUpdateInt.size())) ? ssrUpdateInt[corr._updateInt] : 0;
498 if (dt > 0.0 && dt <= max(2.0 * nominal, 60.0)) {
499 double jump = fabs(clk - stat.lastClk - corr._dotDClk * t_CST::c * dt);
500 stat.maxJump = max(stat.maxJump, jump);
501 if (jump > MAX_CLK_JUMP) {
502 stat.clkJumps += 1;
503 }
504 }
505 }
506 stat.lastClkTime = corr._time;
507 stat.lastIod = corr._iod;
508 stat.lastClk = clk;
509 }
510}
511
512// Code biases
513////////////////////////////////////////////////////////////////////////////
514void t_ssrQc::slotNewCodeBiases(QList<t_satCodeBias> codeBiases) {
515 QMutexLocker locker(&_mutex);
516 for (const t_satCodeBias& bias : codeBiases) {
517 bool sel = selected(bias._staID);
518 if (_excluded.contains(QString::fromStdString(bias._staID)) && bias._staID != _reference.toStdString()) continue;
519 char sys = bias._prn.system();
520 QString prn = QString::fromStdString(bias._prn.toString());
521 if (sel) {
522 checkInterval(bias._time);
523 newEpoch(bias._staID, sys, CBIAS, bias._time, bias._updateInt, prn);
524 }
525 QString staSys = QString("%1 %2").arg(bias._staID.c_str()).arg(sys);
526 QMap<QString, double> values;
527 for (const t_frqCodeBias& frqBias : bias._bias) {
528 QString sig = QString::fromStdString(frqBias._rnxType2ch);
529 _codeSignals[staSys].insert(sig);
530 values[sig] = frqBias._value;
531 }
532 if (!values.isEmpty()) {
533 _cbLast[QString::fromStdString(bias._staID)][prn] = values;
534 }
535 t_satStat& stat = _satStat[QString::fromStdString(bias._staID) + ' ' + prn];
536 QString sig1, sig2;
537 t_frequency::type frq1, frq2;
538 if (refSignals(sys, sig1, sig2, frq1, frq2)) {
539 stat.missingRefSig.clear();
540 if (!values.contains(sig1)) stat.missingRefSig.insert("C" + sig1);
541 if (!values.contains(sig2)) stat.missingRefSig.insert("C" + sig2);
542 stat.refBiasOK = stat.missingRefSig.isEmpty();
543 if (stat.refBiasOK) {
544 double channel = 0.0;
545 if (sys == 'R') {
546 t_eph* eph = _ephUser.ephLast(QString::fromStdString(bias._prn.toInternalString()));
547 if (!eph) {
548 stat.refBiasOK = false;
549 continue;
550 }
551 channel = eph->slotNum();
552 }
553 double f1 = t_CST::freq(frq1, channel);
554 double f2 = t_CST::freq(frq2, channel);
555 stat.biasIF = (f1 * f1 * values[sig1] - f2 * f2 * values[sig2]) / (f1 * f1 - f2 * f2);
556 }
557 }
558 }
559}
560
561// Phase biases
562////////////////////////////////////////////////////////////////////////////
563void t_ssrQc::slotNewPhaseBiases(QList<t_satPhaseBias> phaseBiases) {
564 QMutexLocker locker(&_mutex);
565 for (const t_satPhaseBias& bias : phaseBiases) {
566 QString staID = QString::fromStdString(bias._staID);
567 QString prn = QString::fromStdString(bias._prn.toString());
568 // latest biases for the Melbourne-Wuebbena check (also as other AC)
569 if (!_excluded.contains(staID) || staID == _reference) {
570 t_pbLast& pl = _pbLast[staID][prn];
571 pl.time = bias._time;
572 pl.values.clear();
573 for (const t_frqPhaseBias& frqBias : bias._bias) {
574 pl.values[QString::fromStdString(frqBias._rnxType2ch)] = frqBias._value;
575 }
576 }
577 if (!selected(bias._staID)) continue;
578 checkInterval(bias._time);
579 newEpoch(bias._staID, bias._prn.system(), PBIAS, bias._time, bias._updateInt, prn);
580 QString staSys = QString("%1 %2").arg(staID).arg(bias._prn.system());
581 t_satStat& stat = _satStat[staID + ' ' + prn];
582 t_pbIndStat& ind = _pbIndStat[staSys];
583 ind.numRec++;
584 ind.format[(bias._ssrFormat == ssrRtcmNew) ? "new RTCM-SSR" :
585 (bias._ssrFormat == ssrRtcmOld) ? "old RTCM-SSR" : "IGS-SSR"]++;
586 if (bias._ssrFormat != ssrRtcmNew) { // new RTCM-SSR: no consistency indicators
587 ind.dispInd[bias._dispBiasConsistInd]++;
588 ind.mwInd[bias._MelbWuebConsistInd]++;
589 }
590 bool jumped = false; // counted once per record, not per signal
591 for (const t_frqPhaseBias& frqBias : bias._bias) {
592 QString sig = QString::fromStdString(frqBias._rnxType2ch);
593 _phaseSignals[staSys].insert(sig);
594 ind.intInd[sig][frqBias._fixIndicator]++;
595 ind.wlInd[sig][frqBias._fixWideLaneIndicator]++;
596 QString jumpKey = staID + ' ' + prn + ' ' + sig;
597 if (_pbJumpLast.contains(jumpKey) && _pbJumpLast[jumpKey] != frqBias._jumpCounter) {
598 jumped = true;
599 }
600 _pbJumpLast[jumpKey] = frqBias._jumpCounter;
601 }
602 if (jumped) {
603 stat.pbJumps++;
604 }
605 // Yaw angle: new RTCM-SSR has an indicator, old RTCM-SSR and IGS-SSR always
606 // carry the field, providers without attitude information send zeros
607 stat.numPB++;
608 bool yawProvided = (bias._ssrFormat == ssrRtcmNew) ? (bias._satYawInfoInd != 0)
609 : (bias._yaw != 0.0 || bias._yawRate != 0.0);
610 if (yawProvided) {
611 stat.numYaw++;
612 t_yawLast& yl = _yawLast[QString::fromStdString(bias._staID)][QString::fromStdString(bias._prn.toString())];
613 double dt = 0.0;
614 if (bias._updateInt < unsigned(ssrUpdateInt.size())) {
615 dt = 0.5 * ssrUpdateInt[bias._updateInt]; // reference time in the middle of the interval
616 }
617 yl.time = bias._time + dt;
618 yl.yaw = bias._yaw;
619 yl.rate = bias._yawRate;
620 }
621 }
622}
623
624// Melbourne-Wuebbena combination of the phase and code biases of the
625// reference signals of a stream and satellite in wide-lane cycles:
626// (f1 b_L1 - f2 b_L2) / (f1 - f2) - (f1 b_C1 + f2 b_C2) / (f1 + f2)
627// The phase bias of a frequency is that of the reference signal or, if not
628// provided, of another signal of the frequency; the code biases are those
629// of the reference signals (as used for the clocks and a combination; with
630// the code bias of the phase signal instead, e.g. C1C for CNES' L1C, CNES and
631// NRCan agreed less on 2026-10-02)
632////////////////////////////////////////////////////////////////////////////
633bool t_ssrQc::mwBias(const QString& staID, const QString& prn, char sys, const bncTime& tt, double& mwCyc) {
634 QString sig1, sig2;
635 t_frequency::type frq1, frq2;
636 if (sys == 'R' || !refSignals(sys, sig1, sig2, frq1, frq2)) {
637 return false; // GLONASS FDMA: no integer wide-lane ambiguities between satellites
638 }
639 if (!_pbLast.value(staID).contains(prn) || !_cbLast.value(staID).contains(prn)) {
640 return false;
641 }
642 const t_pbLast& pl = _pbLast[staID][prn];
643 if (fabs(tt - pl.time) > MW_MAX_AGE) {
644 return false;
645 }
646 const QMap<QString, double>& cb = _cbLast[staID][prn];
647 auto biases = [&pl, &cb](const QString& sig, double& phase, double& code) {
648 QString used;
649 if (pl.values.contains(sig)) {
650 used = sig;
651 }
652 else {
653 QMapIterator<QString, double> it(pl.values);
654 while (it.hasNext()) {
655 it.next();
656 if (it.key()[0] == sig[0]) {
657 used = it.key();
658 break;
659 }
660 }
661 }
662 if (used.isEmpty()) {
663 return false;
664 }
665 if (!cb.contains(sig)) {
666 return false;
667 }
668 phase = pl.values[used];
669 code = cb[sig];
670 return true;
671 };
672 double pb1, pb2, cb1, cb2;
673 if (!biases(sig1, pb1, cb1) || !biases(sig2, pb2, cb2)) {
674 return false;
675 }
676 double f1 = t_CST::freq(frq1, 0);
677 double f2 = t_CST::freq(frq2, 0);
678 double mw = (f1 * pb1 - f2 * pb2) / (f1 - f2) - (f1 * cb1 + f2 * cb2) / (f1 + f2);
679 mwCyc = mw / (t_CST::c / (f1 - f2));
680 return true;
681}
682
683// Melbourne-Wuebbena check of one epoch: per pair of streams of different
684// ACs and system, the fractional parts of the MW differences of the
685// satellites about their common (circular mean) offset
686////////////////////////////////////////////////////////////////////////////
687void t_ssrQc::compareMw(const bncTime& tt) {
688 QStringList streams = _pbLast.keys();
689 for (const QString& staA : streams) {
690 if (!selected(staA.toStdString())) continue;
691 for (const QString& staB : streams) {
692 if (staB == staA || !votes(staB) || acOf(staB) == acOf(staA)) continue;
693 QMap<char, QMap<QString, double> > diff; // system, PRN: MW difference [cycles]
694 for (const QString& prn : _pbLast[staA].keys()) {
695 char sys = prn[0].toLatin1();
696 double mwA, mwB;
697 if (mwBias(staA, prn, sys, tt, mwA) && mwBias(staB, prn, sys, tt, mwB)) {
698 diff[sys][prn] = mwA - mwB;
699 }
700 }
701 QMapIterator<char, QMap<QString, double> > itSys(diff);
702 while (itSys.hasNext()) {
703 itSys.next();
704 const QMap<QString, double>& dd = itSys.value();
705 if (dd.size() < MW_MIN_SAT) continue;
706 double sSin = 0.0, sCos = 0.0;
707 for (double val : dd) {
708 sSin += sin(2.0 * M_PI * val);
709 sCos += cos(2.0 * M_PI * val);
710 }
711 double offset = atan2(sSin, sCos) / (2.0 * M_PI);
712 t_mwStat& ms = _mwStat[staA][staB][itSys.key()];
713 ms.numEpo++;
714 ms.offset = offset;
715 QMapIterator<QString, double> itD(dd);
716 while (itD.hasNext()) {
717 itD.next();
718 double res = itD.value() - offset;
719 res -= floor(res + 0.5); // fractional part in [-0.5, 0.5)
720 ms.numRes++;
721 ms.sRes2 += res * res;
722 QPair<unsigned, double>& sr = ms.satRes[itD.key()];
723 sr.first++;
724 sr.second += res * res;
725 }
726 }
727 }
728 }
729}
730
731// Reference DCBs (bias(base) - bias(signal)) of a satellite: median of the
732// other ACs (one vote per AC, own AC left out, combinations not voting) or
733// the selected reference stream, or from the Bias SINEX file
734////////////////////////////////////////////////////////////////////////////
735bool t_ssrQc::refDcbs(const QString& staID, const QString& prn, const QString& base, bool fromFile,
736 QMap<QString, double>& dcbs, const QString& onlyAC, QMap<QString, int>* numVotes) {
737 dcbs.clear();
738 if (numVotes) {
739 numVotes->clear();
740 }
741 if (fromFile) {
742 if (!_bsxRef) {
743 return false;
744 }
745 char sys = prn[0].toLatin1();
746 t_ssrRefSig::t_pair pair;
747 if (!t_ssrRefSig::get(sys, pair)) {
748 return false;
749 }
750 // the DCBs do not depend on the coefficients (as long as they add up to 1)
751 double f1 = t_CST::freq(pair.frq1, 0.0);
752 double f2 = t_CST::freq(pair.frq2, 0.0);
753 double aIF1 = f1 * f1 / (f1 * f1 - f2 * f2);
754 double aIF2 = -f2 * f2 / (f1 * f1 - f2 * f2);
755 t_satCodeBias satCodeBias;
756 _bsxRef->determineSsrSatCodeBiases(prn, aIF1, aIF2, satCodeBias);
757 QMap<QString, double> osb;
758 for (const t_frqCodeBias& bb : satCodeBias._bias) {
759 osb[QString::fromStdString(bb._rnxType2ch)] = bb._value;
760 }
761 if (!osb.contains(base)) {
762 return false;
763 }
764 for (auto it = osb.constBegin(); it != osb.constEnd(); ++it) {
765 if (it.key() != base) {
766 dcbs[it.key()] = osb[base] - it.value();
767 }
768 }
769 return !dcbs.isEmpty();
770 }
771
772 // per AC: DCBs of its streams
773 QMap<QString, QMap<QString, QVector<double> > > acDcbs; // AC, signal
774 for (auto itS = _cbLast.constBegin(); itS != _cbLast.constEnd(); ++itS) {
775 const QString& sta = itS.key();
776 if (sta == staID) {
777 continue;
778 }
779 if (_reference == "CONSENSUS") {
780 if (!votes(sta)) {
781 continue;
782 }
783 if (onlyAC.isEmpty() ? (acOf(sta) == acOf(staID))
784 : (solOf(sta) != onlyAC || solOf(sta) == solOf(staID))) {
785 continue;
786 }
787 }
788 else if (sta != _reference) {
789 continue;
790 }
791 if (!itS.value().contains(prn)) {
792 continue;
793 }
794 const QMap<QString, double>& bb = itS.value()[prn];
795 if (!bb.contains(base)) {
796 continue;
797 }
798 for (auto it = bb.constBegin(); it != bb.constEnd(); ++it) {
799 if (it.key() != base) {
800 acDcbs[solOf(sta)][it.key()].append(bb[base] - it.value());
801 }
802 }
803 }
804 QMap<QString, QVector<double> > votesPerSig;
805 for (auto itA = acDcbs.constBegin(); itA != acDcbs.constEnd(); ++itA) {
806 for (auto it = itA.value().constBegin(); it != itA.value().constEnd(); ++it) {
807 votesPerSig[it.key()].append(median(it.value()));
808 }
809 }
810 for (auto it = votesPerSig.constBegin(); it != votesPerSig.constEnd(); ++it) {
811 dcbs[it.key()] = median(it.value());
812 if (numVotes) {
813 (*numVotes)[it.key()] = it.value().size();
814 }
815 }
816 return !dcbs.isEmpty();
817}
818
819// Code bias check: the DCBs of the stream (relative to the first reference
820// signal, otherwise to another common signal) compared with a reference;
821// DCBs do not depend on the clock datum. A sign opposite to the reference
822// for most DCBs indicates the SINEX instead of the SSR sign convention.
823// References: the Bias SINEX file, the selected reference stream, or each
824// other AC separately (a median of two ACs cannot decide which one is wrong)
825////////////////////////////////////////////////////////////////////////////
826void t_ssrQc::compareCodeBiases(const QString& staID, char sys, QStringList& lines) {
827 const double MIN_DCB = 0.3; // [m] DCBs used for the sign check
828 const double MIN_DEV = 0.5; // [m] deviating DCBs: > max(MIN_DEV, DEV_FACTOR x median)
829 const int MIN_VOTE = 3; // ACs needed for a consensus DCB (deviating satellites)
830 if (!_cbLast.contains(staID)) {
831 return;
832 }
833 t_ssrRefSig::t_pair pair;
834 if (!t_ssrRefSig::get(sys, pair)) {
835 return;
836 }
837 const QString ref1 = QString::fromStdString(pair.sig1());
838
839 class t_cmp {
840 public:
841 unsigned numSat = 0, numSign = 0, numOpp = 0;
842 double sumSqr = 0.0;
843 QVector<double> absDiffs;
844 QMap<QString, QPair<QString, double> > maxDiff; // PRN: signal, difference
845 QSet<QString> bases;
846 bool opposite() const {return numSign >= 5 && numOpp > numSign / 2;}
847 double rms() const {return absDiffs.isEmpty() ? 0.0 : sqrt(sumSqr / absDiffs.size());}
848 };
849 // mode 0: file, 1: reference stream or median of the other ACs, 2: one other AC
850 auto compare = [&](int mode, const QString& onlyAC) {
851 t_cmp cc;
852 for (auto itP = _cbLast[staID].constBegin(); itP != _cbLast[staID].constEnd(); ++itP) {
853 const QString& prn = itP.key();
854 if (prn[0].toLatin1() != sys) {
855 continue;
856 }
857 const QMap<QString, double>& bb = itP.value();
858 QStringList candidates = QStringList() << ref1 << bb.keys();
859 QMap<QString, double> dcbs;
860 QMap<QString, int> numVotes;
861 QString base;
862 for (const QString& cand : candidates) {
863 if (bb.contains(cand) && refDcbs(staID, prn, cand, mode == 0, dcbs, onlyAC, &numVotes)) {
864 base = cand;
865 break;
866 }
867 }
868 if (base.isEmpty()) {
869 continue;
870 }
871 bool used = false;
872 for (auto it = dcbs.constBegin(); it != dcbs.constEnd(); ++it) {
873 if (!bb.contains(it.key())) {
874 continue;
875 }
876 if (mode == 1 && _reference == "CONSENSUS" && numVotes.value(it.key()) < MIN_VOTE) {
877 continue;
878 }
879 double dcb = bb[base] - bb[it.key()];
880 double diff = dcb - it.value();
881 used = true;
882 cc.sumSqr += diff * diff;
883 cc.absDiffs.append(fabs(diff));
884 if (fabs(diff) > fabs(cc.maxDiff.value(prn).second)) {
885 cc.maxDiff[prn] = qMakePair("C" + it.key(), diff);
886 }
887 if (fabs(it.value()) >= MIN_DCB) {
888 cc.numSign++;
889 if (dcb * it.value() < 0.0) {
890 cc.numOpp++;
891 }
892 }
893 }
894 if (used) {
895 cc.numSat++;
896 cc.bases.insert("C" + base);
897 }
898 }
899 return cc;
900 };
901 auto baseStr = [](const t_cmp& cc) {
902 QStringList ll = cc.bases.values();
903 ll.sort();
904 return ll.join("/");
905 };
906 auto deviating = [&](const t_cmp& cc, const QString& refName) {
907 if (cc.absDiffs.isEmpty() || cc.opposite()) {
908 return;
909 }
910 double limit = std::max(MIN_DEV, DEV_FACTOR * median(cc.absDiffs));
911 QStringList devs;
912 for (auto it = cc.maxDiff.constBegin(); it != cc.maxDiff.constEnd(); ++it) {
913 if (fabs(it.value().second) > limit) {
914 devs << QString("%1(%2 %3)").arg(it.key()).arg(it.value().first).arg(it.value().second, 0, 'f', 2);
915 }
916 }
917 if (!devs.isEmpty()) {
918 lines << QString("satellites with DCBs deviating from %1 [m]: %2").arg(refName).arg(devs.join(" "));
919 }
920 };
921
922 // Bias SINEX file or the selected reference stream
923 for (int mode = 0; mode < 2; mode++) {
924 if ((mode == 0 && !_bsxRef) || (mode == 1 && _reference == "CONSENSUS")) {
925 continue;
926 }
927 QString refName = (mode == 0) ? QString("Bias SINEX file %1").arg(_bsxName) : _reference;
928 t_cmp cc = compare(mode, QString());
929 if (cc.absDiffs.isEmpty()) {
930 continue;
931 }
932 lines << QString("code biases compared with %1 (DCBs to %2, %3 satellites, %4 DCBs): RMS of the differences "
933 "%5 m, opposite sign for %6 of %7 DCBs (|DCB| >= %8 m)")
934 .arg(refName).arg(baseStr(cc)).arg(cc.numSat).arg(cc.absDiffs.size())
935 .arg(cc.rms(), 0, 'f', 3).arg(cc.numOpp).arg(cc.numSign).arg(MIN_DCB, 0, 'f', 1);
936 if (cc.opposite()) {
937 lines << QString("code biases with the opposite sign of %1 for %2 of %3 DCBs - "
938 "SINEX sign convention instead of the SSR one?").arg(refName).arg(cc.numOpp).arg(cc.numSign);
939 }
940 deviating(cc, refName);
941 }
942
943 // Each other AC separately, and the median of the other ACs for deviating satellites
944 if (_reference == "CONSENSUS") {
945 QSet<QString> acs;
946 for (auto itS = _cbLast.constBegin(); itS != _cbLast.constEnd(); ++itS) {
947 if (itS.key() != staID && votes(itS.key()) && solOf(itS.key()) != solOf(staID)) {
948 acs.insert(solOf(itS.key()));
949 }
950 }
951 QStringList acList = acs.values();
952 acList.sort();
953 QStringList items;
954 QStringList oppACs;
955 int numACs = 0;
956 QSet<QString> bases;
957 for (const QString& ac : acList) {
958 t_cmp cc = compare(2, ac);
959 if (cc.absDiffs.isEmpty()) {
960 continue;
961 }
962 bases.unite(cc.bases);
963 items << QString("%1 RMS %2 m, opposite sign %3/%4").arg(ac).arg(cc.rms(), 0, 'f', 2)
964 .arg(cc.numOpp).arg(cc.numSign);
965 // the sign rule counts the solutions of other ACs only
966 if (acOfSol(ac) != acOf(staID)) {
967 numACs++;
968 if (cc.opposite()) {
969 oppACs << ac;
970 }
971 }
972 }
973 if (!items.isEmpty()) {
974 QStringList ll = bases.values();
975 ll.sort();
976 lines << QString("code biases compared with the other solutions (DCBs to %1): %2").arg(ll.join("/")).arg(items.join("; "));
977 if (numACs >= 2 && oppACs.size() > numACs / 2) {
978 lines << QString("code biases with the opposite sign of %1 of %2 solutions of other ACs (%3) - "
979 "SINEX sign convention instead of the SSR one?")
980 .arg(oppACs.size()).arg(numACs).arg(oppACs.join(" "));
981 }
982 deviating(compare(1, QString()), QString("the median of the other ACs (at least %1 solutions)").arg(MIN_VOTE));
983 }
984 }
985}
986
987// Code biases of an APC stream compared with the CoM stream of the same
988// solution and format (SSRA00GMV0 / SSRC00GMV0), IGS-SSR and old RTCM-SSR
989// only (new RTCM-SSR carries its own satellite antenna model, and the
990// reference point is left to the provider). Following the IGS SSR
991// convention, users of an APC stream reduce the satellite PCOs of all
992// frequencies by the PCO of the reference frequency themselves, so the code
993// biases of both streams have to be equal. Differences equal to
994// z(f) - z(ref) of the ANTEX file show frequency-dependent PCO differences in
995// the biases of the APC stream, which such users apply twice (ionosphere-free
996// combination of the reference signal biases z(IF) - z(ref) instead of 0).
997////////////////////////////////////////////////////////////////////////////
998void t_ssrQc::compareApcComBiases(const QString& staID, char sys, const bncTime& tt, QStringList& lines) {
999 const double MAX_DIFF = 0.02; // [m] equal biases (resolution 0.01 m, slightly different epochs)
1000 if (!staID.startsWith("SSRA")) {
1001 return;
1002 }
1003 const QString comID = "SSRC" + staID.mid(4);
1004 if (!_cbLast.contains(staID) || !_cbLast.contains(comID)) {
1005 return;
1006 }
1007 // format of the latest orbit corrections (IGS-SSR: ssrUnknown)
1008 if (_orbFormat.value(staID, ssrUnknown) == ssrRtcmNew || _orbFormat.value(comID, ssrUnknown) == ssrRtcmNew) {
1009 return;
1010 }
1011 // reference frequency of the APC (IGS SSR v1.00, table 2)
1012 t_frequency::type refFrq;
1013 switch (sys) {
1014 case 'G': refFrq = t_frequency::G1; break;
1015 case 'R': refFrq = t_frequency::R1; break;
1016 case 'E': refFrq = t_frequency::E1; break;
1017 case 'C': refFrq = t_frequency::C2; break;
1018 case 'J': refFrq = t_frequency::J1; break;
1019 case 'S': refFrq = t_frequency::S1; break;
1020 case 'I': refFrq = t_frequency::I5; break;
1021 default: return;
1022 }
1023 QSet<QString> sats;
1024 unsigned numBias = 0, numPco = 0;
1025 double sumSqr = 0.0, sumSqrRes = 0.0, maxDiff = 0.0;
1026 QString maxStr;
1027 const QMap<QString, QMap<QString, double> >& apc = _cbLast[staID];
1028 const QMap<QString, QMap<QString, double> >& com = _cbLast[comID];
1029 for (auto itP = apc.constBegin(); itP != apc.constEnd(); ++itP) {
1030 const QString& prn = itP.key();
1031 if (prn[0].toLatin1() != sys || !com.contains(prn)) {
1032 continue;
1033 }
1034 const QMap<QString, double>& bc = com[prn];
1035 for (auto itS = itP.value().constBegin(); itS != itP.value().constEnd(); ++itS) {
1036 const QString& sig = itS.key();
1037 if (!bc.contains(sig) || sig.isEmpty()) {
1038 continue;
1039 }
1040 double diff = itS.value() - bc[sig];
1041 sats.insert(prn);
1042 numBias++;
1043 sumSqr += diff * diff;
1044 if (fabs(diff) > fabs(maxDiff)) {
1045 maxDiff = diff;
1046 maxStr = QString("%1 C%2").arg(prn).arg(sig);
1047 }
1048 if (_antex) {
1049 // satCorr() at nadir 0 (PCV pattern at zenith 0 of the satellite) gives -z(f)
1050 bool foundF = false, foundR = false;
1051 double corrF = _antex->satCorr(prn, t_frequency::toFreq(sys, sig[0].toLatin1()), M_PI / 2.0, 0.0, foundF, tt);
1052 double corrR = _antex->satCorr(prn, refFrq, M_PI / 2.0, 0.0, foundR, tt);
1053 if (foundF && foundR) {
1054 double res = diff - (corrR - corrF); // expected z(f) - z(ref)
1055 sumSqrRes += res * res;
1056 numPco++;
1057 }
1058 }
1059 }
1060 }
1061 if (numBias == 0) {
1062 return;
1063 }
1064 double rms = sqrt(sumSqr / numBias);
1065 if (fabs(maxDiff) <= MAX_DIFF) {
1066 lines << QString("code biases equal to those of the CoM stream %1 (%2 satellites, %3 biases)")
1067 .arg(comID).arg(sats.size()).arg(numBias);
1068 return;
1069 }
1070 lines << QString("code biases differ from those of the CoM stream %1: RMS %2 m, max %3 m (%4) "
1071 "(%5 satellites, %6 biases)")
1072 .arg(comID).arg(rms, 0, 'f', 3).arg(maxDiff, 0, 'f', 3).arg(maxStr).arg(sats.size()).arg(numBias);
1073 if (numPco > 0) {
1074 double rmsRes = sqrt(sumSqrRes / numPco);
1075 if (rmsRes < MAX_DIFF || rmsRes < 0.2 * rms) {
1076 lines << QString("code bias differences APC - CoM equal the satellite PCO differences z(f) - z(ref) of the "
1077 "ANTEX file (RMS of the residuals %1 m, %2 biases): frequency-dependent PCOs in the biases "
1078 "of the APC stream, applied twice by users reducing the PCOs by the PCO of the reference "
1079 "frequency (IGS SSR convention)").arg(rmsRes, 0, 'f', 3).arg(numPco);
1080 }
1081 else {
1082 lines << QString("code bias differences APC - CoM not explained by the satellite PCO differences of the "
1083 "ANTEX file (RMS of the residuals %1 m, %2 biases)").arg(rmsRes, 0, 'f', 3).arg(numPco);
1084 }
1085 }
1086}
1087
1088// Reference point of the orbits of a stream: APC (SSRA...), CoM (SSRC...);
1089// the combined stream INTERNAL refers to the APC
1090////////////////////////////////////////////////////////////////////////////
1091char t_ssrQc::refPoint(const QString& staID) const {
1092 if (staID == "INTERNAL") {
1093 return 'A'; // the combined corrections always refer to the APC
1094 }
1095 const QString& sta = staID;
1096 if (sta.startsWith("SSRA")) return 'A';
1097 if (sta.startsWith("SSRC")) return 'C';
1098 return '?';
1099}
1100
1101// Keep the recent orbit and clock corrections of a stream
1102////////////////////////////////////////////////////////////////////////////
1103void t_ssrQc::storeHist(const t_orbCorr* orb, const t_clkCorr* clk) {
1104 if (orb) {
1105 QMap<double, t_orbCorr>& hist = _orbHist[QString::fromStdString(orb->_staID)]
1106 [QString::fromStdString(orb->_prn.toInternalString())];
1107 hist[tKey(orb->_time)] = *orb;
1108 while (!hist.isEmpty() && hist.firstKey() < tKey(orb->_time) - HIST_LENGTH) {
1109 hist.erase(hist.begin());
1110 }
1111 }
1112 if (clk) {
1113 QMap<double, t_clkCorr>& hist = _clkHist[QString::fromStdString(clk->_staID)]
1114 [QString::fromStdString(clk->_prn.toInternalString())];
1115 hist[tKey(clk->_time)] = *clk;
1116 while (!hist.isEmpty() && hist.firstKey() < tKey(clk->_time) - HIST_LENGTH) {
1117 hist.erase(hist.begin());
1118 }
1119 }
1120}
1121
1122// Compare the orbits and clocks of all streams at epoch tt
1123////////////////////////////////////////////////////////////////////////////
1124void t_ssrQc::compareEpoch(const bncTime& tt) {
1125 double tk = tKey(tt);
1126
1127 // Satellite positions and clocks of all streams (latest corrections <= tt)
1128 QMap<QString, QMap<QString, t_satCrd> > crd; // stream, PRN (external)
1129 QMapIterator<QString, QMap<QString, QMap<double, t_clkCorr> > > itSta(_clkHist);
1130 while (itSta.hasNext()) {
1131 itSta.next();
1132 const QString& staID = itSta.key();
1133 QMapIterator<QString, QMap<double, t_clkCorr> > itPrn(itSta.value());
1134 while (itPrn.hasNext()) {
1135 itPrn.next();
1136 const QString& prnInt = itPrn.key();
1137 QMap<double, t_clkCorr>::const_iterator itC = itPrn.value().upperBound(tk);
1138 if (itC == itPrn.value().constBegin()) {
1139 continue;
1140 }
1141 const t_clkCorr& clk = (--itC).value();
1142 const QMap<double, t_orbCorr>& orbHist = _orbHist[staID][prnInt];
1143 QMap<double, t_orbCorr>::const_iterator itO = orbHist.upperBound(tk);
1144 if (itO == orbHist.constBegin()) {
1145 continue;
1146 }
1147 const t_orbCorr& orb = (--itO).value();
1148 t_eph* eph = _ephUser.ephWithIOD(prnInt, orb._iod);
1149 if (eph && outDatedBcep(eph, tt) && fabs(tt - eph->TOC()) > EPH_IOD_REUSE) {
1150 eph = 0;
1151 }
1152 if (!eph || clk._iod != orb._iod) {
1153 continue;
1154 }
1155 eph->setOrbCorr(&orb);
1156 eph->setClkCorr(&clk);
1157 ColumnVector xc(6), vv(3);
1158 if (eph->getCrd(tt, xc, vv, true) != success) {
1159 continue;
1160 }
1161 t_satCrd& sc = crd[staID][QString::fromStdString(clk._prn.toString())];
1162 sc.xx = xc.Rows(1,3);
1163 sc.vv = vv;
1164 sc.vFrame = eph->ssrFrameVel(xc, vv);
1165 sc.clk = xc(4) * t_CST::c;
1166 sc.refPoint = refPoint(staID);
1167 // clock referred to the reference signals (as in the combination):
1168 // + B_IF of the stream's code biases; the combination (INTERNAL)
1169 // refers to them already
1170 sc.clkOK = (staID == "INTERNAL");
1171 QString satKey = staID + ' ' + QString::fromStdString(clk._prn.toString());
1172 if (!sc.clkOK && _satStat.contains(satKey) && _satStat[satKey].refBiasOK) {
1173 sc.clk += _satStat[satKey].biasIF;
1174 sc.clkOK = true;
1175 }
1176 }
1177 }
1178
1179 // Satellites per system
1180 QMap<char, QSet<QString> > satsSys;
1181 QMapIterator<QString, QMap<QString, t_satCrd> > itCrd(crd);
1182 while (itCrd.hasNext()) {
1183 itCrd.next();
1184 for (const QString& prn : itCrd.value().keys()) {
1185 satsSys[prn[0].toLatin1()].insert(prn);
1186 }
1187 }
1188
1189 QMapIterator<char, QSet<QString> > itSys(satsSys);
1190 while (itSys.hasNext()) {
1191 itSys.next();
1192 const QSet<QString>& sats = itSys.value();
1193 QStringList staList;
1194 for (const QString& staID : crd.keys()) {
1195 for (const QString& prn : sats) {
1196 if (crd[staID].contains(prn)) {
1197 staList << staID;
1198 break;
1199 }
1200 }
1201 }
1202
1203 // Consensus: one value per AC (median of its streams), so that an AC
1204 // with several streams (formats, APC/CoM) has one vote; the streams of
1205 // the AC compared are left out (leave-one-AC-out)
1206 auto acClocks = [&](const QString& prn, const QMap<QString, double>& off, bool useOff) {
1207 QMap<QString, QVector<double> > perAC;
1208 for (const QString& oo : staList) {
1209 if (!votes(oo) || !crd[oo].contains(prn) || !crd[oo][prn].clkOK) continue;
1210 if (useOff && !off.contains(oo)) continue;
1211 perAC[solOf(oo)] << crd[oo][prn].clk - (useOff ? off[oo] : 0.0);
1212 }
1213 QMap<QString, double> res;
1214 for (const QString& ac : perAC.keys()) res[ac] = median(perAC[ac]);
1215 return res;
1216 };
1217
1218 // Clock datum: offset of each stream w.r.t. the per-satellite consensus
1219 // of all ACs (or w.r.t. the reference stream)
1220 QMap<QString, double> offset;
1221 QMap<QString, double> noOff;
1222 QMap<QString, QMap<QString, double> > rawAC; // PRN, AC
1223 if (_reference == "CONSENSUS") {
1224 for (const QString& prn : sats) rawAC[prn] = acClocks(prn, noOff, false);
1225 }
1226 for (const QString& staID : staList) {
1227 QVector<double> diffs;
1228 for (const QString& prn : sats) {
1229 if (!crd[staID].contains(prn) || !crd[staID][prn].clkOK) continue;
1230 if (_reference == "CONSENSUS") {
1231 if (rawAC[prn].size() >= 3) diffs << crd[staID][prn].clk - median(rawAC[prn].values().toVector());
1232 }
1233 else if (crd.value(_reference).contains(prn) && crd[_reference][prn].clkOK) {
1234 diffs << crd[staID][prn].clk - crd[_reference][prn].clk;
1235 }
1236 }
1237 if (!diffs.isEmpty()) {
1238 offset[staID] = median(diffs);
1239 }
1240 }
1241 QMap<QString, QMap<QString, double> > alignedAC; // PRN, AC
1242 if (_reference == "CONSENSUS") {
1243 for (const QString& prn : sats) alignedAC[prn] = acClocks(prn, offset, true);
1244 }
1245
1246 // Differences of each selected stream to its reference
1247 for (const QString& staID : staList) {
1248 if (!selected(staID.toStdString()) || staID == _reference) {
1249 continue;
1250 }
1251 const QString ownAC = acOf(staID);
1252 QMap<QString, double> dClk;
1253 QMap<QString, ColumnVector> dRac;
1254 for (const QString& prn : sats) {
1255 if (!crd[staID].contains(prn)) continue;
1256 const t_satCrd& sc = crd[staID][prn];
1257 QVector<double> clks, xs[3];
1258 if (_reference == "CONSENSUS") {
1259 QMapIterator<QString, double> itA(alignedAC[prn]);
1260 while (itA.hasNext()) {
1261 itA.next();
1262 if (acOfSol(itA.key()) != ownAC) clks << itA.value();
1263 }
1264 // orbits: per AC the median of its streams with the same reference point
1265 QMap<QString, QVector<double> > perAC[3];
1266 for (const QString& oo : staList) {
1267 if (!votes(oo) || acOf(oo) == ownAC || !crd[oo].contains(prn)) continue;
1268 const t_satCrd& rc = crd[oo][prn];
1269 if (rc.refPoint != sc.refPoint || sc.refPoint == '?') continue;
1270 for (int ii = 0; ii < 3; ii++) perAC[ii][solOf(oo)] << rc.xx[ii];
1271 }
1272 for (const QString& ac : perAC[0].keys()) {
1273 for (int ii = 0; ii < 3; ii++) xs[ii] << median(perAC[ii][ac]);
1274 }
1275 if (clks.size() < 2) clks.clear();
1276 if (xs[0].size() < 2) for (int ii = 0; ii < 3; ii++) xs[ii].clear();
1277 }
1278 else {
1279 if (!crd.value(_reference).contains(prn)) continue;
1280 const t_satCrd& rc = crd[_reference][prn];
1281 if (rc.clkOK) clks << rc.clk;
1282 if (rc.refPoint == sc.refPoint && sc.refPoint != '?') {
1283 for (int ii = 0; ii < 3; ii++) xs[ii] << rc.xx[ii];
1284 }
1285 }
1286 if (sc.clkOK && offset.contains(staID) && !clks.isEmpty()) {
1287 dClk[prn] = sc.clk - offset[staID] - median(clks);
1288 }
1289 else if (!sc.clkOK) {
1290 _cmpStat[staID][prn].clkNotReferred += 1;
1291 }
1292 if (!xs[0].isEmpty()) {
1293 ColumnVector dx(3);
1294 for (int ii = 0; ii < 3; ii++) dx[ii] = sc.xx[ii] - median(xs[ii]);
1295 ColumnVector er = sc.xx / sc.xx.NormFrobenius();
1296 ColumnVector ec = crossproduct(sc.xx, sc.vFrame);
1297 ec /= ec.NormFrobenius();
1298 ColumnVector ea = crossproduct(ec, er);
1299 ColumnVector rac(3);
1300 rac[0] = DotProduct(dx, er);
1301 rac[1] = DotProduct(dx, ea);
1302 rac[2] = DotProduct(dx, ec);
1303 dRac[prn] = rac;
1304 }
1305 }
1306 if (dClk.isEmpty() && dRac.isEmpty()) {
1307 continue;
1308 }
1309 // remaining common clock offset of this stream and epoch
1310 double off = dClk.isEmpty() ? 0.0 : median(dClk.values().toVector());
1311 _cmpEpochs[staID] += 1;
1312 QSet<QString> prns;
1313 for (const QString& prn : dClk.keys()) prns.insert(prn);
1314 for (const QString& prn : dRac.keys()) prns.insert(prn);
1315 for (const QString& prn : prns) {
1316 t_cmpStat& stat = _cmpStat[staID][prn];
1317 if (dRac.contains(prn)) {
1318 const ColumnVector& rac = dRac[prn];
1319 stat.numOrb += 1;
1320 stat.sR += rac[0] * rac[0];
1321 stat.sA += rac[1] * rac[1];
1322 stat.sC += rac[2] * rac[2];
1323 }
1324 if (dClk.contains(prn)) {
1325 double dc = dClk[prn] - off;
1326 if (_antex && _yawLast.value(staID).contains(prn)) {
1327 attitudeSample(staID, prn, tt, crd[staID][prn].xx, crd[staID][prn].vv, dc);
1328 }
1329 stat.numClk += 1;
1330 stat.sClk += dc * dc;
1331 stat.mClk += dc;
1332 if (dRac.contains(prn)) {
1333 double sis = dRac[prn][0] - dc;
1334 stat.numSis += 1;
1335 stat.sSis += sis * sis;
1336 stat.mSis += sis;
1337 }
1338 }
1339 }
1340 }
1341 }
1342}
1343
1344// Attitude check: one sample per comparison epoch for a stream sending the
1345// yaw angle. The yaw difference of BNC's attitude model ('Computed') minus
1346// the stream is followed continuously over time; the predicted clock
1347// difference of the stream to an AC following the model is
1348// lambda_IF * dpsi / 2pi (see combination, dC_att). A turn starts when the
1349// yaw difference changes by more than ATT_ONSET against the samples 5-15
1350// minutes before, and ends when it is stable again for ATT_STABLE_T.
1351////////////////////////////////////////////////////////////////////////////
1352void t_ssrQc::attitudeSample(const QString& staID, const QString& prn, const bncTime& tt,
1353 const ColumnVector& xx, const ColumnVector& vv, double dc) {
1354 const t_yawLast& yl = _yawLast[staID][prn];
1355 double age = tt - yl.time;
1356 if (!yl.time.valid() || fabs(age) > 120.0) {
1357 return;
1358 }
1359 double psiAC = yl.yaw + yl.rate * age;
1360
1361 // model yaw, once per satellite and epoch (model state in time order)
1362 double tk = tKey(tt);
1363 if (tk != _psiModelT) {
1364 _psiModel.clear();
1365 _psiModelT = tk;
1366 }
1367 if (!_psiModel.contains(prn)) {
1368 ColumnVector dx(3);
1369 double psiM = 0.0;
1370 double Mjd = tt.mjd() + tt.daysec() / 86400.0;
1371 if (_antex->satCoMcorrection(prn, Mjd, xx, vv, dx, bncAntex::ATT_COMPUTED, 0.0,
1372 "ssrQc", &psiM) != success) {
1373 return;
1374 }
1375 _psiModel[prn] = psiM;
1376 }
1377
1378 // ionosphere-free wavelength of the reference signals, c / (f1 + f2)
1379 QString sig1, sig2;
1380 t_frequency::type frq1, frq2;
1381 if (!refSignals(prn[0].toLatin1(), sig1, sig2, frq1, frq2)) {
1382 return;
1383 }
1384 double lambda = t_CST::c / (t_CST::freq(frq1, 0) + t_CST::freq(frq2, 0));
1385
1386 t_attTrack& tr = _attTrack[staID][prn];
1387 if (tr.hasLast && tk - tr.lastT > ATT_MAX_GAP) {
1388 if (tr.active) {
1389 attitudeEvent(staID, prn, tr, "interrupted by a gap");
1390 }
1391 tr = t_attTrack();
1392 }
1393 double dpsi = remainder(_psiModel[prn] - psiAC, 2.0 * M_PI);
1394 if (tr.hasLast) {
1395 dpsi = tr.lastDPsi + remainder(dpsi - tr.lastDPsi, 2.0 * M_PI);
1396 }
1397 tr.hasLast = true;
1398 tr.lastDPsi = dpsi;
1399 tr.lastT = tk;
1400 t_attSample smp;
1401 smp.t = tk;
1402 smp.dc = dc;
1403 smp.p = lambda * dpsi / (2.0 * M_PI);
1404 smp.dpsi = dpsi;
1405
1406 if (!tr.active) {
1407 tr.hist << smp;
1408 while (!tr.hist.isEmpty() && tk - tr.hist.first().t > ATT_REF_FROM) {
1409 tr.hist.removeFirst();
1410 }
1411 // reference: samples 5 to 15 minutes before
1412 QVector<double> rDc, rP, rPsi;
1413 for (const t_attSample& hh : tr.hist) {
1414 if (tk - hh.t >= ATT_REF_TO) {
1415 rDc << hh.dc; rP << hh.p; rPsi << hh.dpsi;
1416 }
1417 }
1418 if (rPsi.size() >= 3 && fabs(dpsi - median(rPsi)) > ATT_ONSET) {
1419 tr.active = true;
1420 tr.dc0 = median(rDc);
1421 tr.p0 = median(rP);
1422 tr.dpsi0 = median(rPsi);
1423 for (const t_attSample& hh : tr.hist) {
1424 if (tk - hh.t < ATT_REF_TO) tr.event << hh; // the beginning of the turn
1425 }
1426 tr.hist.clear();
1427 }
1428 return;
1429 }
1430
1431 tr.event << smp;
1432 // end: yaw difference stable for ATT_STABLE_T, or the turn too long
1433 double tStart = tr.event.first().t;
1434 bool stable = (tk - tStart >= ATT_STABLE_T);
1435 if (stable) {
1436 for (int ii = tr.event.size() - 1; ii >= 0 && tk - tr.event[ii].t <= ATT_STABLE_T; ii--) {
1437 if (fabs(tr.event[ii].dpsi - dpsi) > ATT_STABLE) {
1438 stable = false;
1439 break;
1440 }
1441 }
1442 }
1443 if (stable || tk - tStart > ATT_MAX_TURN) {
1444 attitudeEvent(staID, prn, tr, stable ? "" : "closed after 3 h");
1445 double keepPsi = tr.lastDPsi, keepT = tr.lastT;
1446 tr = t_attTrack();
1447 tr.hasLast = true;
1448 tr.lastDPsi = keepPsi;
1449 tr.lastT = keepT;
1450 tr.hist << smp;
1451 }
1452}
1453
1454// Assessment of a turn: observed clock change of the stream relative to the
1455// consensus against the predicted one (regression slope, RMS reduction)
1456////////////////////////////////////////////////////////////////////////////
1457void t_ssrQc::attitudeEvent(const QString& staID, const QString& prn, t_attTrack& tr,
1458 const QString& end) {
1459 if (tr.event.size() < 3) {
1460 return;
1461 }
1462 double sxx = 0.0, sxy = 0.0, syy = 0.0, srr = 0.0, maxX = 0.0, maxPsi = 0.0;
1463 for (const t_attSample& ss : tr.event) {
1464 double x = ss.p - tr.p0;
1465 double y = ss.dc - tr.dc0;
1466 sxx += x * x; sxy += x * y; syy += y * y; srr += (y - x) * (y - x);
1467 if (fabs(x) > fabs(maxX)) maxX = x;
1468 if (fabs(ss.dpsi - tr.dpsi0) > fabs(maxPsi)) maxPsi = ss.dpsi - tr.dpsi0;
1469 }
1470 int nn = tr.event.size();
1471 // changes at the end of the turn: mean of the last 5 minutes
1472 double tEnd = tr.event.last().t, xEnd = 0.0, yEnd = 0.0;
1473 int nEnd = 0;
1474 for (const t_attSample& ss : tr.event) {
1475 if (tEnd - ss.t <= 300.0) {
1476 xEnd += ss.p - tr.p0; yEnd += ss.dc - tr.dc0; ++nEnd;
1477 }
1478 }
1479 xEnd /= nEnd; yEnd /= nEnd;
1480 double rmsObs = sqrt(syy / nn);
1481 double rmsRes = sqrt(srr / nn);
1482 double slope = (sxx > 0.0) ? sxy / sxx : 0.0;
1483
1484 bncTime t1, t2;
1485 t1.set(int(tr.event.first().t / 604800.0), fmod(tr.event.first().t, 604800.0));
1486 t2.set(int(tEnd / 604800.0), fmod(tEnd, 604800.0));
1487 QString verdict;
1488 if (fabs(maxX) < ATT_MIN_PRED) {
1489 // the consensus is assumed to follow BNC's attitude model; a larger clock
1490 // change shows that the other ACs model this turn differently
1491 verdict = (rmsObs >= ATT_MIN_PRED) ? "clock change not explained by the yaw difference "
1492 "(the other ACs model this turn differently?)"
1493 : "predicted change too small to assess";
1494 }
1495 else if (slope > 0.7 && slope < 1.3 && rmsRes < 0.5 * rmsObs) {
1496 verdict = "SSR yaw consistent with the clocks";
1497 }
1498 else {
1499 verdict = "SSR yaw NOT consistent with the clocks";
1500 }
1501 QString line = QString("attitude check %1 %2-%3: yaw difference to the model %4 deg, clock change vs. "
1502 "consensus %5 cm, predicted %6 cm (max %7 cm), slope %8, clock RMS %9 -> %10 cm: %11")
1503 .arg(prn).arg(QString::fromStdString(t1.timestr(0))).arg(QString::fromStdString(t2.timestr(0)))
1504 .arg(maxPsi * 180.0 / M_PI, 0, 'f', 0)
1505 .arg(yEnd * 100.0, 0, 'f', 1).arg(xEnd * 100.0, 0, 'f', 1).arg(maxX * 100.0, 0, 'f', 1)
1506 .arg(slope, 0, 'f', 2).arg(rmsObs * 100.0, 0, 'f', 1).arg(rmsRes * 100.0, 0, 'f', 1)
1507 .arg(verdict);
1508 if (!end.isEmpty()) {
1509 line += " (" + end + ")";
1510 }
1511 _attEvents[staID][prn[0].toLatin1()] << line;
1512}
1513
1514// Ionospheric model (VTEC)
1515////////////////////////////////////////////////////////////////////////////
1516void t_ssrQc::slotNewTec(t_vTec vTec) {
1517 QMutexLocker locker(&_mutex);
1518 if (vTec._layers.empty()) {
1519 return;
1520 }
1521 QString sta = QString::fromStdString(vTec._staID);
1522 if (!_excluded.contains(sta) || sta == _reference) {
1523 QMap<double, t_vTec>& hist = _vtecHist[sta];
1524 hist[tKey(vTec._time)] = vTec;
1525 while (!hist.isEmpty() && tKey(vTec._time) - hist.firstKey() > VTEC_HIST) {
1526 hist.erase(hist.begin());
1527 }
1528 }
1529 if (selected(vTec._staID)) {
1530 newEpoch(vTec._staID, 'V', VTEC, vTec._time, vTec._updateInt, "VTEC");
1531 QStringList layers;
1532 for (const t_vTecLayer& layer : vTec._layers) {
1533 layers << QString("%1 km (degree/order %2/%3)").arg(layer._height / 1000.0, 0, 'f', 0)
1534 .arg(layer._C.Nrows() - 1).arg(layer._C.Ncols() - 1);
1535 }
1536 _vtecStat[sta].model = QString("%1 layer(s): %2").arg(vTec._layers.size()).arg(layers.join(", "));
1537 }
1538 checkInterval(vTec._time);
1539}
1540
1541// VTEC [TECU] of a model at a geocentric latitude and longitude [rad] and
1542// epoch: spherical harmonics in the sun-fixed frame as used in PPP, sum of
1543// the layers (negative layer values set to zero as in PPP)
1544////////////////////////////////////////////////////////////////////////////
1545double t_ssrQc::vtecAt(const t_vTec& vTec, double lat, double lon, const bncTime& tt, bool& negative) {
1546 double epoch = fmod(tt.gpssec(), 86400.0);
1547 double lonS = fmod(lon + (epoch - 50400.0) * M_PI / 43200.0, 2.0 * M_PI);
1548 double vtec = 0.0;
1549 negative = false;
1550 for (const t_vTecLayer& layer : vTec._layers) {
1551 int N = layer._C.Nrows() - 1;
1552 int M = layer._C.Ncols() - 1;
1553 double vv = 0.0;
1554 for (int n = 0; n <= N; n++) {
1555 for (int m = 0; m <= min(n, M); m++) {
1556 double pnm = associatedLegendreFunction(n, m, sin(lat));
1557 double fac = (m == 0) ? sqrt(2.0 * n + 1.0)
1558 : sqrt(2.0 * (2.0 * n + 1.0) * factorial(n - m) / factorial(n + m));
1559 vv += (layer._C[n][m] * cos(m * lonS) + layer._S[n][m] * sin(m * lonS)) * pnm * fac;
1560 }
1561 }
1562 if (vv < 0.0) {
1563 negative = true;
1564 vv = 0.0;
1565 }
1566 vtec += vv;
1567 }
1568 return vtec;
1569}
1570
1571// VTEC comparison: each model (latest one not older than twice its update
1572// interval) evaluated on a global grid and compared with the median of the
1573// other AC solutions (one vote per solution, own AC left out, combination
1574// products not voting) or with the reference stream
1575////////////////////////////////////////////////////////////////////////////
1576void t_ssrQc::compareVtec(const bncTime& tt) {
1577 double tk = tKey(tt);
1578
1579 QMap<QString, const t_vTec*> models;
1580 QMapIterator<QString, QMap<double, t_vTec> > itH(_vtecHist);
1581 while (itH.hasNext()) {
1582 itH.next();
1583 QMap<double, t_vTec>::const_iterator it = itH.value().upperBound(tk);
1584 if (it == itH.value().constBegin()) {
1585 continue;
1586 }
1587 --it;
1588 const t_vTec& vTec = it.value();
1589 double interval = (vTec._updateInt < unsigned(ssrUpdateInt.size()) && ssrUpdateInt[vTec._updateInt] > 0)
1590 ? ssrUpdateInt[vTec._updateInt] : VTEC_CMP_SAMPL;
1591 double maxAge = min(3600.0, max(120.0, 2.0 * interval));
1592 if (tk - it.key() <= maxAge) {
1593 models[itH.key()] = &vTec;
1594 }
1595 }
1596 if (models.isEmpty()) {
1597 return;
1598 }
1599
1600 // grid values of all models
1601 QVector<QPair<double, double> > grid;
1602 for (double lat = -80.0; lat <= 80.0 + 1e-6; lat += VTEC_GRID_LAT) {
1603 for (double lon = -180.0; lon < 180.0 - 1e-6; lon += VTEC_GRID_LON) {
1604 grid << QPair<double, double>(lat * M_PI / 180.0, lon * M_PI / 180.0);
1605 }
1606 }
1607 QMap<QString, QVector<double> > val;
1608 QMapIterator<QString, const t_vTec*> itM(models);
1609 while (itM.hasNext()) {
1610 itM.next();
1611 QVector<double>& vv = val[itM.key()];
1612 vv.resize(grid.size());
1613 bool selectedSta = selected(itM.key().toStdString());
1614 t_vtecStat* st = selectedSta ? &_vtecStat[itM.key()] : 0;
1615 for (int ii = 0; ii < grid.size(); ii++) {
1616 bool negative = false;
1617 vv[ii] = vtecAt(*itM.value(), grid[ii].first, grid[ii].second, tt, negative);
1618 if (st) {
1619 if (st->numGrid == 0 || vv[ii] < st->minVal) st->minVal = vv[ii];
1620 if (st->numGrid == 0 || vv[ii] > st->maxVal) st->maxVal = vv[ii];
1621 st->numGrid += 1;
1622 if (negative) st->numNeg += 1;
1623 }
1624 }
1625 }
1626
1627 // comparison
1628 for (const QString& staID : models.keys()) {
1629 if (!selected(staID.toStdString())) {
1630 continue;
1631 }
1632 QMap<QString, QStringList> perSol; // solution: streams
1633 for (const QString& oo : models.keys()) {
1634 if (oo == staID) continue;
1635 if (_reference == "CONSENSUS") {
1636 if (!votes(oo) || acOf(oo) == acOf(staID)) continue;
1637 }
1638 else if (oo != _reference) {
1639 continue;
1640 }
1641 perSol[solOf(oo)] << oo;
1642 }
1643 if (perSol.isEmpty()) {
1644 continue;
1645 }
1646 t_vtecStat& st = _vtecStat[staID];
1647 st.numCmp += 1;
1648 st.numSol += perSol.size();
1649 for (int ii = 0; ii < grid.size(); ii++) {
1650 QVector<double> solVal;
1651 for (const QStringList& streams : perSol) {
1652 QVector<double> vv;
1653 for (const QString& oo : streams) vv << val[oo][ii];
1654 solVal << median(vv);
1655 }
1656 double diff = val[staID][ii] - median(solVal);
1657 st.numDiff += 1;
1658 st.sDiff += diff;
1659 st.sDiff2 += diff * diff;
1660 st.maxAbs = max(st.maxAbs, fabs(diff));
1661 }
1662 }
1663}
1664
1665
1666// Write the report of the current interval and reset the statistics
1667////////////////////////////////////////////////////////////////////////////
1668void t_ssrQc::writeReport(bool final) {
1669 if (_epoStat.isEmpty()) {
1670 return;
1671 }
1672 bncTime endTime = final ? _lastTime : _intervalStart + _interval;
1673
1674 // IODs not received: early or unknown (pending ones younger than
1675 // EPH_EARLY_MAX are decided in the next interval)
1676 for (const QString& satKey : _pendingIod.keys()) {
1677 resolvePendingIod(satKey, final);
1678 }
1679
1680 // Healthy and current broadcast ephemerides per system
1681 QMap<char, QSet<QString> > ephSats;
1682 for (const QString& prnInt : _ephUser.prnList()) {
1683 t_eph* eph = _ephUser.ephLast(prnInt);
1684 if (eph && eph->checkState() == t_eph::ok && !outDatedBcep(eph, endTime)) {
1685 ephSats[eph->prn().system()].insert(QString::fromStdString(eph->prn().toString()));
1686 }
1687 }
1688
1689 // Streams and systems
1690 QMap<QString, QSet<char> > streams;
1691 QMapIterator<QString, t_epoStat> itEpo(_epoStat);
1692 while (itEpo.hasNext()) {
1693 itEpo.next();
1694 QStringList hlp = itEpo.key().split(' ');
1695 streams[hlp[0]].insert(hlp[1][0].toLatin1());
1696 }
1697
1698 QMapIterator<QString, QSet<char> > itSta(streams);
1699 while (itSta.hasNext()) {
1700 itSta.next();
1701 const QString& staID = itSta.key();
1702 QList<char> systems = itSta.value().values();
1703 std::sort(systems.begin(), systems.end());
1704 ofstream& out = streamOut(staID, _intervalStart);
1705 if (final) {
1706 endTime = _staLast.value(staID, _lastTime);
1707 if (endTime < _intervalStart) { // stream without data in the last interval
1708 endTime = _lastTime;
1709 }
1710 }
1711 out << endl << "=== SSR QC " << staID.toStdString() << ' '
1712 << _intervalStart.datestr() << ' ' << _intervalStart.timestr(0)
1713 << " - " << endTime.datestr() << ' ' << endTime.timestr(0)
1714 << (final ? " (end of data)" : "") << " ===" << endl
1715 << " Sys Type Epochs Interval nom/med/max [s] Gaps Out-of-order"
1716 << " Latency med/max [s] Sats" << endl;
1717 for (char sys : systems) {
1718 for (int type = ORB; type <= VTEC; type++) {
1719 QString kk = QString("%1 %2 %3").arg(staID).arg(sys).arg(type);
1720 if (!_epoStat.contains(kk)) {
1721 continue;
1722 }
1723 const t_epoStat& stat = _epoStat[kk];
1724 double medInt = median(stat.intervals);
1725 double maxInt = stat.intervals.isEmpty() ? 0.0 :
1726 *std::max_element(stat.intervals.begin(), stat.intervals.end());
1727 double ref = max(double(stat.nominal), medInt);
1728 unsigned gaps = 0;
1729 for (double dt : stat.intervals) {
1730 if (ref > 0.0 && dt > 2.0 * ref) {
1731 ++gaps;
1732 }
1733 }
1734 double maxLat = stat.latencies.isEmpty() ? 0.0 :
1735 *std::max_element(stat.latencies.begin(), stat.latencies.end());
1736 out << " " << sys << " " << left << setw(10) << TYPE_NAME[type] << right
1737 << setw(8) << stat.numEpo
1738 << setw(10) << stat.nominal << " /" << setw(6) << setprecision(1) << fixed << medInt
1739 << " /" << setw(7) << maxInt
1740 << setw(6) << gaps << setw(14) << stat.numOutOfOrder
1741 << setw(10) << median(stat.latencies) << " /" << setw(7) << maxLat
1742 << setw(7) << stat.sats.size() << endl;
1743 }
1744 }
1745
1746 // Per system: completeness, ephemeris, biases, plausibility
1747 for (char sys : systems) {
1748 // Ionosphere (VTEC): model, values on the grid, comparison
1749 if (sys == 'V') {
1750 QStringList lines;
1751 QString kk = QString("%1 %2 %3").arg(staID).arg(sys).arg(int(VTEC));
1752 if (_epoStat.contains(kk)) {
1753 const t_epoStat& stat = _epoStat[kk];
1754 double medInt = median(stat.intervals);
1755 if (stat.nominal > 0 && stat.intervals.size() > 1 &&
1756 (medInt > 1.5 * stat.nominal || medInt < stat.nominal / 1.5)) {
1757 lines << QString("VTEC: declared update interval %1 s, actual %2 s")
1758 .arg(stat.nominal).arg(medInt, 0, 'f', 1);
1759 }
1760 }
1761 if (_vtecStat.contains(staID)) {
1762 const t_vtecStat& vs = _vtecStat[staID];
1763 if (!vs.model.isEmpty()) {
1764 lines << "VTEC model: " + vs.model;
1765 }
1766 if (vs.numGrid) {
1767 lines << QString("VTEC on a global %1 x %2 deg grid: %3 ... %4 TECU, negative (set to zero) %5 %")
1768 .arg(VTEC_GRID_LAT, 0, 'f', 0).arg(VTEC_GRID_LON, 0, 'f', 0)
1769 .arg(vs.minVal, 0, 'f', 1).arg(vs.maxVal, 0, 'f', 1)
1770 .arg(100.0 * vs.numNeg / vs.numGrid, 0, 'f', 1);
1771 }
1772 if (vs.numDiff) {
1773 QString refText = (_reference == "CONSENSUS")
1774 ? QString("consensus of the other ACs (%1 solutions on average)")
1775 .arg(double(vs.numSol) / vs.numCmp, 0, 'f', 1)
1776 : QString("stream %1").arg(_reference);
1777 double mean = vs.sDiff / vs.numDiff;
1778 double rms = sqrt(vs.sDiff2 / vs.numDiff);
1779 lines << QString("VTEC comparison with %1, %2 epochs: mean %3 TECU, RMS %4 TECU, max |diff| %5 TECU")
1780 .arg(refText).arg(vs.numCmp).arg(mean, 0, 'f', 2).arg(rms, 0, 'f', 2)
1781 .arg(vs.maxAbs, 0, 'f', 1);
1782 }
1783 else {
1784 lines << "VTEC not compared: no other model available";
1785 }
1786 }
1787 for (const QString& line : lines) {
1788 out << " " << sys << " " << line.toStdString() << endl;
1789 }
1790 continue;
1791 }
1792 QMap<QString, unsigned> iodEarly, outdated;
1793 double maxEarly = 0.0;
1794 QMap<QString, unsigned> missOrb, missClk, missCB, missPB, iodUnknown, unhealthy, noEph,
1795 jumps, missRef, noYaw, yawPartly, pbJumps;
1796 unsigned numPB = 0, numYaw = 0, yawSats = 0;
1797 double maxRadial = 0.0, maxAlongCross = 0.0;
1798 QString maxRadialPrn, maxAlongCrossPrn;
1799 QVector<double> biasIF;
1800 double maxBiasIF = 0.0;
1801 QString biasIFPrn;
1802 const QSet<QString>& ephs = ephSats[sys];
1803 for (int type = ORB; type <= PBIAS; type++) {
1804 QString kk = QString("%1 %2 %3").arg(staID).arg(sys).arg(type);
1805 if (!_epoStat.contains(kk)) {
1806 continue;
1807 }
1808 QMap<QString, unsigned>& miss = (type == ORB) ? missOrb : (type == CLK) ? missClk :
1809 (type == CBIAS) ? missCB : missPB;
1810 for (const QString& prn : ephs) {
1811 if (!_epoStat[kk].sats.contains(prn)) {
1812 miss[prn] = 0;
1813 }
1814 }
1815 }
1816 QMapIterator<QString, t_satStat> itSat(_satStat);
1817 while (itSat.hasNext()) {
1818 itSat.next();
1819 QStringList hlp = itSat.key().split(' ');
1820 if (hlp[0] != staID || hlp[1][0].toLatin1() != sys) {
1821 continue;
1822 }
1823 const QString& prn = hlp[1];
1824 const t_satStat& stat = itSat.value();
1825 if (stat.iodUnknown) iodUnknown[prn] = stat.iodUnknown;
1826 if (stat.iodEarly) {
1827 iodEarly[prn] = stat.iodEarly;
1828 maxEarly = max(maxEarly, stat.maxEarly);
1829 }
1830 if (stat.ephOutdated) outdated[prn] = stat.ephOutdated;
1831 if (stat.ephUnhealthy) unhealthy[prn] = stat.ephUnhealthy;
1832 if (stat.noEph) noEph[prn] = stat.noEph;
1833 if (stat.clkJumps) jumps[prn] = stat.clkJumps;
1834 if (stat.pbJumps) pbJumps[prn] = stat.pbJumps;
1835 if (stat.maxRadial > maxRadial) {
1836 maxRadial = stat.maxRadial;
1837 maxRadialPrn = prn;
1838 }
1839 if (stat.maxAlongCross > maxAlongCross) {
1840 maxAlongCross = stat.maxAlongCross;
1841 maxAlongCrossPrn = prn;
1842 }
1843 // only satellites with corrections (providers list satellites
1844 // without corrections with zero biases, e.g. GMV E14/E18)
1845 if (!stat.missingRefSig.isEmpty() && (stat.numClk || stat.numOrb)) {
1846 QStringList sigs = stat.missingRefSig.values();
1847 sigs.sort();
1848 missRef[prn + "[" + sigs.join("/") + "]"] = 0;
1849 }
1850 if (stat.refBiasOK) {
1851 biasIF.push_back(stat.biasIF);
1852 if (biasIFPrn.isEmpty() || fabs(stat.biasIF) > maxBiasIF) {
1853 maxBiasIF = fabs(stat.biasIF);
1854 biasIFPrn = prn;
1855 }
1856 }
1857 if (stat.numPB) {
1858 numPB += stat.numPB;
1859 numYaw += stat.numYaw;
1860 if (stat.numYaw) {
1861 yawSats++;
1862 if (stat.numYaw < stat.numPB) {
1863 yawPartly[prn] = stat.numPB - stat.numYaw;
1864 }
1865 }
1866 else {
1867 noYaw[prn] = 0;
1868 }
1869 }
1870 }
1871 // only findings are listed
1872 QStringList lines;
1873 for (int type = ORB; type <= PBIAS; type++) {
1874 QString kk = QString("%1 %2 %3").arg(staID).arg(sys).arg(type);
1875 if (_epoStat.contains(kk)) {
1876 const t_epoStat& stat = _epoStat[kk];
1877 double medInt = median(stat.intervals);
1878 if (stat.nominal > 0 && stat.intervals.size() > 1 &&
1879 (medInt > 1.5 * stat.nominal || medInt < stat.nominal / 1.5)) {
1880 lines << QString("%1: declared update interval %2 s, actual %3 s")
1881 .arg(TYPE_NAME[type]).arg(stat.nominal).arg(medInt, 0, 'f', 1);
1882 }
1883 }
1884 }
1885 auto addSats = [&lines](const QString& text, const QMap<QString, unsigned>& sats) {
1886 if (!sats.isEmpty()) {
1887 lines << text + ":" + satList(sats);
1888 }
1889 };
1890 addSats("orbit corrections missing (healthy broadcast ephemeris available)", missOrb);
1891 addSats("clock corrections missing (healthy broadcast ephemeris available)", missClk);
1892 addSats("code biases missing (healthy broadcast ephemeris available)", missCB);
1893 addSats("phase biases missing (healthy broadcast ephemeris available)", missPB);
1894 addSats("corrections referring to an IOD of no received broadcast ephemeris", iodUnknown);
1895 if (!iodEarly.isEmpty()) {
1896 addSats(QString("corrections referring to an IOD received from the ephemeris stream(s) "
1897 "only later (up to %1 s)").arg(maxEarly, 0, 'f', 0), iodEarly);
1898 }
1899 addSats("corrections referring to a broadcast ephemeris outside its validity", outdated);
1900 addSats("corrections for unhealthy broadcast ephemeris", unhealthy);
1901 addSats("corrections for satellites without broadcast ephemeris", noEph);
1902 QString staSys = QString("%1 %2").arg(staID).arg(sys);
1903 if (_codeSignals.contains(staSys)) {
1904 QStringList sigs = _codeSignals[staSys].values();
1905 sigs.sort();
1906 lines << "code bias signals: " + sigs.join(" ");
1907 addSats("code biases of the reference signals missing", missRef);
1908 if (biasIF.size() > 1) {
1909 double mean = 0.0;
1910 for (double bb : biasIF) mean += bb / biasIF.size();
1911 double var = 0.0;
1912 for (double bb : biasIF) var += (bb - mean) * (bb - mean) / biasIF.size();
1913 // the median shows whether the clocks refer to other signals (all
1914 // satellites) or single satellites have inconsistent biases
1915 QVector<double> absIF;
1916 for (double bb : biasIF) absIF << fabs(bb);
1917 lines << QString("ionosphere-free combination B_IF of the reference signal biases: "
1918 "std. dev. %1 m, median |B_IF| %2 m, max |B_IF| %3 m (%4) (%5 satellites)")
1919 .arg(sqrt(var), 0, 'f', 3).arg(median(absIF), 0, 'f', 3).arg(maxBiasIF, 0, 'f', 3)
1920 .arg(biasIFPrn).arg(biasIF.size());
1921 }
1922 }
1923 compareCodeBiases(staID, sys, lines);
1924 compareApcComBiases(staID, sys, endTime, lines);
1925 if (_phaseSignals.contains(staSys)) {
1926 QStringList sigs = _phaseSignals[staSys].values();
1927 sigs.sort();
1928 lines << "phase bias signals: " + sigs.join(" ");
1929 }
1930 if (_pbIndStat.contains(staSys)) {
1931 const t_pbIndStat& ind = _pbIndStat[staSys];
1932 // value list "1" or "0 (12 %), 1 (88 %)"
1933 auto values = [](const QMap<int, unsigned>& counts) {
1934 unsigned total = 0;
1935 for (unsigned nn : counts) total += nn;
1936 QStringList parts;
1937 QMapIterator<int, unsigned> it(counts);
1938 while (it.hasNext()) {
1939 it.next();
1940 parts << ((counts.size() == 1) ? QString::number(it.key())
1941 : QString("%1 (%2 %)").arg(it.key())
1942 .arg(100.0 * it.value() / total, 0, 'f', 0));
1943 }
1944 return parts.join(", ");
1945 };
1946 QStringList formats = ind.format.keys();
1947 QString line = "phase bias format and indicators: " + formats.join("/");
1948 if (!ind.mwInd.isEmpty()) {
1949 line += QString(", dispersive bias consistency indicator %1, MW consistency indicator %2")
1950 .arg(values(ind.dispInd)).arg(values(ind.mwInd));
1951 }
1952 else {
1953 line += " (no consistency indicators)";
1954 }
1955 lines << line;
1956 QStringList sigParts;
1957 QMapIterator<QString, QMap<int, unsigned> > itSig(ind.intInd);
1958 while (itSig.hasNext()) {
1959 itSig.next();
1960 sigParts << QString("%1 integer %2 / wide-lane %3").arg(itSig.key())
1961 .arg(values(itSig.value())).arg(values(ind.wlInd.value(itSig.key())));
1962 }
1963 if (!sigParts.isEmpty()) {
1964 lines << "phase bias integer / wide-lane integer indicators: " + sigParts.join("; ");
1965 }
1966 addSats("phase bias discontinuity counter changes", pbJumps);
1967 }
1968 bool mwAny = false;
1969 for (const QMap<char, t_mwStat>& mm : _mwStat.value(staID)) {
1970 mwAny = mwAny || mm.contains(sys);
1971 }
1972 QString mwSig1, mwSig2;
1973 t_frequency::type mwFrq1, mwFrq2;
1974 if (mwAny && refSignals(sys, mwSig1, mwSig2, mwFrq1, mwFrq2)) {
1975 // phase signals used (see mwBias)
1976 QStringList used;
1977 QStringList pSigs = _phaseSignals.value(staSys).values();
1978 pSigs.sort();
1979 for (const QString& sig : {mwSig1, mwSig2}) {
1980 QString uu = pSigs.contains(sig) ? sig : QString();
1981 for (const QString& ps : pSigs) {
1982 if (uu.isEmpty() && ps[0] == sig[0]) uu = ps;
1983 }
1984 used << "L" + uu;
1985 }
1986 lines << QString("MW check: phase biases %1 with the code biases C%2 C%3 of the reference signals, "
1987 "wide-lane cycles (%4 m)")
1988 .arg(used.join(" ")).arg(mwSig1).arg(mwSig2)
1989 .arg(t_CST::c / (t_CST::freq(mwFrq1, 0) - t_CST::freq(mwFrq2, 0)), 0, 'f', 3);
1990 }
1991 if (_mwStat.contains(staID)) {
1992 QMapIterator<QString, QMap<char, t_mwStat> > itOther(_mwStat[staID]);
1993 while (itOther.hasNext()) {
1994 itOther.next();
1995 if (!itOther.value().contains(sys)) continue;
1996 const t_mwStat& ms = itOther.value()[sys];
1997 if (ms.numRes == 0) continue;
1998 double rms = sqrt(ms.sRes2 / ms.numRes);
1999 QString verdict = (rms < MW_OK) ? "consistent (integer wide-lane biases)" :
2000 (rms > MW_BAD) ? "NOT consistent" : "not clearly consistent";
2001 lines << QString("MW biases vs. %1 (%2 epochs, %3 satellites): fractional parts about the "
2002 "common offset %4 cycles: RMS %5 cycles, %6")
2003 .arg(itOther.key()).arg(ms.numEpo).arg(ms.satRes.size())
2004 .arg(ms.offset, 0, 'f', 2).arg(rms, 0, 'f', 3).arg(verdict);
2005 QStringList dev;
2006 QMapIterator<QString, QPair<unsigned, double> > itS(ms.satRes);
2007 while (itS.hasNext()) {
2008 itS.next();
2009 double rmsSat = sqrt(itS.value().second / itS.value().first);
2010 if (rmsSat > MW_BAD) {
2011 dev << QString("%1(%2)").arg(itS.key()).arg(rmsSat, 0, 'f', 2);
2012 }
2013 }
2014 if (!dev.isEmpty() && rms < MW_BAD) {
2015 lines << QString("MW biases vs. %1: satellites with RMS > %2 cycles: %3")
2016 .arg(itOther.key()).arg(MW_BAD, 0, 'f', 2).arg(dev.join(" "));
2017 }
2018 }
2019 }
2020 if (numPB) {
2021 if (numYaw == 0) {
2022 lines << "yaw angle: not provided";
2023 }
2024 else {
2025 lines << QString("yaw angle: provided for %1 of %2 satellites (%3 % of the phase bias records)")
2026 .arg(yawSats).arg(yawSats + noYaw.size()).arg(100.0 * numYaw / numPB, 0, 'f', 1);
2027 addSats("phase biases without yaw angle", noYaw);
2028 addSats("phase biases partly without yaw angle (records)", yawPartly);
2029 }
2030 }
2031 for (const QString& line : _attEvents.value(staID).value(sys)) {
2032 lines << line;
2033 }
2034 addSats(QString("clock jumps > %1 m").arg(MAX_CLK_JUMP), jumps);
2035 if (!maxRadialPrn.isEmpty()) {
2036 lines << QString("largest orbit corrections: radial %1 m (%2), along/cross %3 m (%4)")
2037 .arg(maxRadial, 0, 'f', 2).arg(maxRadialPrn).arg(maxAlongCross, 0, 'f', 2).arg(maxAlongCrossPrn);
2038 }
2039 // stream comparison
2040 if (_cmpStat.contains(staID)) {
2041 unsigned nSat = 0, nClk = 0, nOrb = 0, nSis = 0;
2042 double sClk = 0.0, sR = 0.0, sA = 0.0, sC = 0.0, sSis = 0.0;
2043 double vClk = 0.0, vSis = 0.0; // sums of squares about the satellite means
2044 QMap<QString, double> rmsSis, rmsClk, rmsOrb;
2045 QMap<QString, unsigned> notReferred;
2046 QMapIterator<QString, t_cmpStat> itC(_cmpStat[staID]);
2047 while (itC.hasNext()) {
2048 itC.next();
2049 if (itC.key()[0].toLatin1() != sys) continue;
2050 const t_cmpStat& st = itC.value();
2051 if (st.numClk == 0 && st.numOrb == 0) {
2052 if (st.clkNotReferred) notReferred[itC.key()] = 0;
2053 continue;
2054 }
2055 ++nSat;
2056 if (st.clkNotReferred) notReferred[itC.key()] = 0;
2057 nClk += st.numClk; sClk += st.sClk;
2058 nOrb += st.numOrb; sR += st.sR; sA += st.sA; sC += st.sC;
2059 nSis += st.numSis; sSis += st.sSis;
2060 if (st.numClk) vClk += st.sClk - st.mClk * st.mClk / st.numClk;
2061 if (st.numSis) vSis += st.sSis - st.mSis * st.mSis / st.numSis;
2062 if (st.numSis) rmsSis[itC.key()] = sqrt(st.sSis / st.numSis);
2063 else if (st.numClk) rmsClk[itC.key()] = sqrt(st.sClk / st.numClk);
2064 if (st.numOrb) rmsOrb[itC.key()] = sqrt((st.sR + st.sA + st.sC) / st.numOrb);
2065 }
2066 if (nSat) {
2067 QString refText = (_reference == "CONSENSUS") ? QString("consensus of the other ACs")
2068 : QString("stream %1").arg(_reference);
2069 QStringList parts;
2070 if (nClk) parts << QString("clock %1 (STD %2)").arg(sqrt(sClk / nClk), 0, 'f', 3)
2071 .arg(sqrt(max(0.0, vClk) / nClk), 0, 'f', 3);
2072 if (nOrb) parts << QString("radial %1, along %2, cross %3")
2073 .arg(sqrt(sR / nOrb), 0, 'f', 3).arg(sqrt(sA / nOrb), 0, 'f', 3)
2074 .arg(sqrt(sC / nOrb), 0, 'f', 3);
2075 if (nSis) parts << QString("SIS (radial - clock) %1 (STD %2)").arg(sqrt(sSis / nSis), 0, 'f', 3)
2076 .arg(sqrt(max(0.0, vSis) / nSis), 0, 'f', 3);
2077 lines << QString("comparison with %1 (%2 satellites), RMS (STD about the satellite means) [m]: %3")
2078 .arg(refText).arg(nSat).arg(parts.join(", "));
2079 if (!nOrb) {
2080 lines << "orbits not compared: no other stream with the same reference point (APC/CoM)";
2081 }
2082 addSats("clocks not compared (code biases of the reference signals missing)", notReferred);
2083 auto deviating = [&lines](const QString& what, const QMap<QString, double>& rms) {
2084 if (rms.size() < 2) return;
2085 double med = median(rms.values().toVector());
2086 QStringList dev;
2087 QMapIterator<QString, double> itR(rms);
2088 while (itR.hasNext()) {
2089 itR.next();
2090 if (itR.value() > max(DEV_MIN, DEV_FACTOR * med)) {
2091 dev << QString("%1(%2)").arg(itR.key()).arg(itR.value(), 0, 'f', 2);
2092 }
2093 }
2094 if (!dev.isEmpty()) {
2095 lines << QString("satellites deviating from the reference, RMS %1 [m]: %2").arg(what).arg(dev.join(" "));
2096 }
2097 };
2098 deviating("SIS", rmsSis);
2099 deviating("clock", rmsClk);
2100 deviating("orbit (3D)", rmsOrb);
2101 }
2102 }
2103 for (const QString& line : lines) {
2104 out << " " << sys << " " << line.toStdString() << endl;
2105 }
2106 }
2107 out.flush();
2108 }
2109
2110 emit newLogRecord(t_logRecord::message(t_logRecord::info, QString("SSR QC: report %1 %2 of %3 stream(s) written to %4")
2111 .arg(QString::fromStdString(_intervalStart.datestr()))
2112 .arg(QString::fromStdString(_intervalStart.timestr(0)))
2113 .arg(streams.size()).arg(_dirName).toLatin1()), false);
2114
2115 _cmpStat.clear();
2116 _cmpEpochs.clear();
2117 _attEvents.clear();
2118 _pbIndStat.clear();
2119 _mwStat.clear();
2120 for (QMap<QString, t_vtecStat>::iterator it = _vtecStat.begin(); it != _vtecStat.end(); ++it) {
2121 t_vtecStat fresh;
2122 fresh.model = it.value().model;
2123 it.value() = fresh;
2124 }
2125
2126 // reset, keeping the state needed across intervals
2127 for (QMap<QString, t_epoStat>::iterator it = _epoStat.begin(); it != _epoStat.end(); ++it) {
2128 t_epoStat& stat = it.value();
2129 bncTime last = stat.last;
2130 int nominal = stat.nominal;
2131 stat = t_epoStat();
2132 stat.last = last;
2133 stat.nominal = nominal;
2134 }
2135 for (QMap<QString, t_satStat>::iterator it = _satStat.begin(); it != _satStat.end(); ++it) {
2136 t_satStat& stat = it.value();
2137 t_satStat fresh;
2138 fresh.lastClkTime = stat.lastClkTime;
2139 fresh.lastIod = stat.lastIod;
2140 fresh.lastClk = stat.lastClk;
2141 fresh.missingRefSig = stat.missingRefSig;
2142 fresh.refBiasOK = stat.refBiasOK;
2143 fresh.biasIF = stat.biasIF;
2144 stat = fresh;
2145 }
2146}
Note: See TracBrowser for help on using the repository browser.