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

Last change on this file since 11218 was 11218, checked in by stuerze, 8 hours ago

improvements regarding ssrqc ephemerides upload and combination

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