source: ntrip/trunk/BNC/src/PPP/pppSatObs.cpp@ 11042

Last change on this file since 11042 was 11042, checked in by stuerze, 43 hours ago

updates regarding RTCM-SSR

  • Property svn:keywords set to Author Date Id Rev URL;svn:eol-style=native
  • Property svn:mime-type set to text/plain
File size: 28.7 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: t_pppSatObs
6 *
7 * Purpose: Satellite observations
8 *
9 * Author: L. Mervart
10 *
11 * Created: 29-Jul-2014
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17
18#include <iostream>
19#include <iomanip>
20#include <cmath>
21#include <algorithm>
22#include <set>
23#include <newmatio.h>
24
25#include "pppSatObs.h"
26#include "bncconst.h"
27#include "pppEphPool.h"
28#include "pppStation.h"
29#include "bncutils.h"
30#include "bncantex.h"
31#include "pppObsPool.h"
32#include "pppClient.h"
33
34using namespace BNC_PPP;
35using namespace std;
36
37
38// Constructor
39////////////////////////////////////////////////////////////////////////////
40t_pppSatObs::t_pppSatObs(const t_satObs& pppSatObs) {
41 _prn = pppSatObs._prn;
42 _time = pppSatObs._time;
43 _outlier = false;
44 _valid = true;
45 _reference = false;
46 _stecSat = 0.0;
47 _stecRefSat = 0.0;
48 for (unsigned ii = 0; ii < t_frequency::max; ii++) {
49 _obs[ii] = 0;
50 }
51 prepareObs(pppSatObs);
52}
53
54// Destructor
55////////////////////////////////////////////////////////////////////////////
56t_pppSatObs::~t_pppSatObs() {
57 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
58 delete _obs[iFreq];
59 }
60}
61
62//
63////////////////////////////////////////////////////////////////////////////
64bool t_pppSatObs::isBetter(const t_frqObs* aa, t_frqObs* bb, const string& trkModes) const {
65
66 if (!trkModes.empty()) {
67 size_t posA = trkModes.find(aa->trkChar());
68 size_t posB = trkModes.find(bb->trkChar());
69 if (posA != posB) {
70 if (posA == string::npos) {
71 return false;
72 }
73 else if (posB == string::npos) {
74 return true;
75 }
76 else {
77 return posA < posB;
78 }
79 }
80 }
81
82 unsigned numValA = 0;
83 if (aa->_codeValid) numValA += 1;
84 if (aa->_phaseValid) numValA += 1;
85
86 unsigned numValB = 0;
87 if (bb->_codeValid) numValB += 1;
88 if (bb->_phaseValid) numValB += 1;
89
90 if (numValA != numValB) {
91 return numValA > numValB;
92 }
93
94 return false;
95}
96
97//
98////////////////////////////////////////////////////////////////////////////
99void t_pppSatObs::prepareObs(const t_satObs& satObs) {
100
101 _model.reset();
102
103 const t_pppOptions::SysTrkModes* sysTrkModes = OPT->sysTrkModes(_prn.system());
104 using FrqTrkModes = t_pppOptions::SysTrkModes::FrqTrkModes;
105
106 for (const t_frqObs* obs : satObs._obs) {
107 if ( (obs->_codeValid || obs->_phaseValid)) {
108 t_frequency::type frq = t_frequency::toFreq(_prn.system(), obs->frqChar());
109 if (frq == t_frequency::dummy) {
110 continue;
111 }
112 string trkModes;
113 if (sysTrkModes) {
114 const vector<FrqTrkModes>& frqTrkModes = sysTrkModes->_frqTrkModes;
115 auto it = find_if(frqTrkModes.begin(), frqTrkModes.end(),
116 [frq](const FrqTrkModes& mm){return mm._frq == frq;});
117 if (it != frqTrkModes.end()) {
118 trkModes = it->_trkModes;
119 }
120 }
121 if (_obs[frq] == 0 || isBetter(obs, _obs[frq], trkModes)) {
122 delete _obs[frq];
123 _obs[frq] = new t_frqObs(*obs);
124 }
125 }
126 }
127
128 // Check whether all required frequencies available
129 // ------------------------------------------------
130 const std::vector<t_lc>& LCs = OPT->LCs(_prn.system());
131 for (unsigned ii = 0; ii < LCs.size(); ii++) {
132 t_lc LC = LCs[ii];
133 if (LC._type == t_lc::GIM) {
134 continue;
135 }
136 if (LC._frq1 != t_frequency::G5 && !isValid(LC)) {
137 _valid = false;
138 return;
139 }
140 }
141
142 // Find GLONASS Channel Number
143 // ---------------------------
144 if (_prn.system() == 'R') {
145 _channel = PPP_CLIENT->ephPool()->getChannel(_prn);
146 }
147 else {
148 _channel = 0;
149 }
150
151 // Compute Satellite Coordinates at Time of Transmission
152 // -----------------------------------------------------
153 _xcSat.ReSize(6); _xcSat = 0.0;
154 _vvSat.ReSize(3); _vvSat = 0.0;
155 bool totOK = false;
156 ColumnVector satPosOld(6); satPosOld = 0.0;
157
158 _valid = false;
159 t_frequency::type frq1 = t_frequency::dummy;
160 t_frequency::type frq2 = t_frequency::dummy;
161 OPT->defaultFrqs(_prn.system(), frq1, frq2);
162 if (frq1 != t_frequency::dummy) {
163 t_lc lc1(t_lc::code, frq1);
164 if (isValid(lc1)) {
165 _valid = true;
166 _rangeLC = lc1;
167 }
168 if (frq2 != t_frequency::dummy) {
169 t_lc lcIF(t_lc::codeIF, frq1, frq2);
170 if (isValid(lcIF)) {
171 _valid = true;
172 _rangeLC = lcIF;
173 }
174 }
175 }
176 if (!_valid) {
177 return;
178 }
179
180 double prange = obsValue(_rangeLC);
181 for (int ii = 1; ii <= 10; ii++) {
182 bncTime ToT = _time - prange / t_CST::c - _xcSat[3];
183 if (PPP_CLIENT->ephPool()->getCrd(_prn, ToT, _xcSat, _vvSat) != success) {
184 _valid = false;
185 return;
186 }
187 ColumnVector dx = _xcSat - satPosOld;
188 dx[3] *= t_CST::c;
189 if (dx.NormFrobenius() < 1.e-4) {
190 totOK = true;
191 break;
192 }
193 satPosOld = _xcSat;
194 }
195 if (totOK) {
196 _signalPropagationTime = prange / t_CST::c - _xcSat[3];
197 _model._satClkM = _xcSat[3] * t_CST::c;
198 }
199 else {
200 _valid = false;
201 }
202}
203
204//
205////////////////////////////////////////////////////////////////////////////
206void t_pppSatObs::lcCoeff(t_lc LC,
207 map<t_frequency::type, double>& codeCoeff,
208 map<t_frequency::type, double>& phaseCoeff,
209 map<t_frequency::type, double>& ionoCoeff) const {
210
211 codeCoeff.clear();
212 phaseCoeff.clear();
213 ionoCoeff.clear();
214
215 double f1 = t_CST::freq(LC._frq1, _channel);
216 double f2 = t_CST::freq(LC._frq2, _channel);
217 double f1GPS = t_CST::freq(t_frequency::G1, 0);
218
219 switch (LC._type) {
220 case t_lc::phase:
221 phaseCoeff[LC._frq1] = 1.0;
222 ionoCoeff [LC._frq1] = -1.0 * pow(f1GPS, 2) / pow(f1, 2);
223 return;
224 case t_lc::code:
225 codeCoeff[LC._frq1] = 1.0;
226 ionoCoeff[LC._frq1] = pow(f1GPS, 2) / pow(f1, 2);
227 return;
228 case t_lc::phaseIF:
229 phaseCoeff[LC._frq1] = f1 * f1 / (f1 * f1 - f2 * f2);
230 phaseCoeff[LC._frq2] = -f2 * f2 / (f1 * f1 - f2 * f2);
231 return;
232 case t_lc::codeIF:
233 codeCoeff[LC._frq1] = f1 * f1 / (f1 * f1 - f2 * f2);
234 codeCoeff[LC._frq2] = -f2 * f2 / (f1 * f1 - f2 * f2);
235 return;
236 case t_lc::MW:
237 phaseCoeff[LC._frq1] = f1 / (f1 - f2);
238 phaseCoeff[LC._frq2] = -f2 / (f1 - f2);
239 codeCoeff [LC._frq1] = -f1 / (f1 + f2);
240 codeCoeff [LC._frq2] = -f2 / (f1 + f2);
241 return;
242 case t_lc::CL:
243 phaseCoeff[LC._frq1] = 0.5;
244 codeCoeff [LC._frq1] = 0.5;
245 return;
246 case t_lc::GIM:
247 case t_lc::dummy:
248 case t_lc::maxLc:
249 return;
250 }
251}
252
253//
254////////////////////////////////////////////////////////////////////////////
255bool t_pppSatObs::isValid(t_lc LC) const {
256 bool valid = true;
257 obsValue(LC, &valid);
258
259 return valid;
260}
261//
262////////////////////////////////////////////////////////////////////////////
263double t_pppSatObs::obsValue(t_lc LC, bool* valid) const {
264
265 double retVal = 0.0;
266 if (valid) *valid = true;
267
268 // Pseudo observations (single-differenced: reference minus satellite)
269 if (LC._type == t_lc::GIM) {
270 if (_stecSat == 0.0 || _stecRefSat == 0.0) {
271 if (valid) *valid = false;
272 return 0.0;
273 }
274 else {
275 return _stecRefSat - _stecSat;
276 }
277 }
278
279 map<t_frequency::type, double> codeCoeff;
280 map<t_frequency::type, double> phaseCoeff;
281 map<t_frequency::type, double> ionoCoeff;
282 lcCoeff(LC, codeCoeff, phaseCoeff, ionoCoeff);
283
284 map<t_frequency::type, double>::const_iterator it;
285
286 // Code observations
287 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
288 t_frequency::type tFreq = it->first;
289 if (_obs[tFreq] == 0) {
290 if (valid) *valid = false;
291 return 0.0;
292 }
293 else {
294 retVal += it->second * _obs[tFreq]->_code;
295 }
296 }
297 // Phase observations
298 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
299 t_frequency::type tFreq = it->first;
300 if (_obs[tFreq] == 0) {
301 if (valid) *valid = false;
302 return 0.0;
303 }
304 else {
305 retVal += it->second * _obs[tFreq]->_phase * t_CST::lambda(tFreq, _channel);
306 }
307 }
308 return retVal;
309}
310
311//
312////////////////////////////////////////////////////////////////////////////
313double t_pppSatObs::lambda(t_lc LC) const {
314
315 double f1 = t_CST::freq(LC._frq1, _channel);
316 double f2 = t_CST::freq(LC._frq2, _channel);
317
318 if (LC._type == t_lc::phase) {
319 return t_CST::c / f1;
320 }
321 else if (LC._type == t_lc::phaseIF) {
322 return t_CST::c / (f1 + f2);
323 }
324 else if (LC._type == t_lc::MW) {
325 return t_CST::c / (f1 - f2);
326 }
327 else if (LC._type == t_lc::CL) {
328 return t_CST::c / f1 / 2.0;
329 }
330
331 return 0.0;
332}
333
334//
335////////////////////////////////////////////////////////////////////////////
336double t_pppSatObs::sigma(t_lc LC) const {
337
338 double retVal = 0.0;
339 map<t_frequency::type, double> codeCoeff;
340 map<t_frequency::type, double> phaseCoeff;
341 map<t_frequency::type, double> ionoCoeff;
342 lcCoeff(LC, codeCoeff, phaseCoeff, ionoCoeff);
343
344 if (LC._type == t_lc::GIM) {
345 retVal = OPT->_sigmaGIM * OPT->_sigmaGIM;
346 }
347
348 map<t_frequency::type, double>::const_iterator it;
349 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
350 retVal += it->second * it->second * OPT->_sigmaC1 * OPT->_sigmaC1;
351 }
352
353 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
354 retVal += it->second * it->second * OPT->_sigmaL1 * OPT->_sigmaL1;
355 }
356
357 retVal = sqrt(retVal);
358
359 // De-Weight R
360 // -----------
361 if (_prn.system() == 'R'&& LC.includesCode()) {
362 retVal *= 5.0;
363 }
364
365 // Elevation-Dependent Weighting
366 // -----------------------------
367 double cEle = 1.0;
368 if ( (OPT->_eleWgtCode && LC.includesCode()) ||
369 (OPT->_eleWgtPhase && LC.includesPhase()) ) {
370 double eleD = eleSat()*180.0/M_PI;
371 double hlp = fabs(90.0 - eleD);
372 cEle = (1.0 + hlp*hlp*hlp*0.000004);
373 }
374
375 return cEle * retVal;
376}
377
378//
379////////////////////////////////////////////////////////////////////////////
380double t_pppSatObs::maxRes(t_lc LC) const {
381 double retVal = 0.0;
382
383 map<t_frequency::type, double> codeCoeff;
384 map<t_frequency::type, double> phaseCoeff;
385 map<t_frequency::type, double> ionoCoeff;
386 lcCoeff(LC, codeCoeff, phaseCoeff, ionoCoeff);
387
388 map<t_frequency::type, double>::const_iterator it;
389 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
390 retVal += it->second * it->second * OPT->_maxResC1 * OPT->_maxResC1;
391 }
392 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
393 retVal += it->second * it->second * OPT->_maxResL1 * OPT->_maxResL1;
394 }
395
396 retVal = sqrt(retVal);
397
398 return retVal;
399}
400
401
402// A system's Satellite Antenna message is only trustworthy once the
403// provider has confirmed it via Metadata: SatelliteAntennaIOD (DF+010) must
404// be non-zero, and must match the Data IOD (DF+069) of a Metadata entry for
405// model-correction type 1 (satellite antenna PCV) or type 2 (GDV) - either
406// entry matching is sufficient. Metadata carries this IOD once globally, not
407// per system (DF+010 is GNSS-specific, DF+069 is not), so the same Metadata
408// entries are reused as the trust anchor for every system's check - the
409// provider is relied on to keep DF+010 synchronized with DF+069 across all
410// systems for this to work.
411//
412// Separately, providers only guarantee SatelliteAntennaIOD uniqueness within
413// a rolling 64-day window (it wraps/repeats after that), so a client that
414// has been without a fresh Antenna message for that system for 64 days or
415// more must treat any cached data as unverifiable and stop using it, even
416// if the IOD/Metadata check above would otherwise pass - the same IOD value
417// could by then legitimately mean something else. epoTime is the current
418// processing epoch, compared against t_satAntenna::_time (when this data
419// was actually decoded, not a wire epoch - the message carries none).
420////////////////////////////////////////////////////////////////////////////
421static bool ssrSatAntennaTrusted(const t_satAntenna* satAntenna, const bncTime& epoTime) {
422 const double MAX_AGE_SEC = 64.0 * 86400.0;
423 if (!satAntenna || satAntenna->_satelliteAntennaIOD == 0) {
424 return false;
425 }
426 if (epoTime.valid() && satAntenna->_time.valid() &&
427 epoTime - satAntenna->_time >= MAX_AGE_SEC) {
428 return false;
429 }
430 const t_metaData* metaData = PPP_CLIENT->obsPool()->metaData();
431 if (!metaData) {
432 return false;
433 }
434 for (unsigned ii = 0; ii < metaData->_entries.size(); ii++) {
435 const t_metaDataEntry& entry = metaData->_entries[ii];
436 if ((entry._typeIndicator == 1 || entry._typeIndicator == 2) && // PCV or GDV
437 entry._dataIODIndicator &&
438 entry._dataIOD == satAntenna->_satelliteAntennaIOD) {
439 return true;
440 }
441 }
442 return false;
443}
444
445// Satellite antenna correction (offset + nadir-angle-dependent PCV) from a
446// live SSR Satellite Antenna message, in the same additive sense as
447// bncAntex::satCorr(). Returns false (corr untouched) if no trusted SSR data
448// is available for this PRN/frequency (see ssrSatAntennaTrusted), so the
449// caller falls back to the static ANTEX file.
450////////////////////////////////////////////////////////////////////////////
451static bool ssrSatAntennaCorr(const t_satAntenna* satAntenna, const string& frqStr,
452 double elTx, double& corr) {
453 if (!satAntenna) {
454 return false;
455 }
456 for (unsigned ii = 0; ii < satAntenna->_freq.size(); ii++) {
457 const t_frqAntenna& frq = satAntenna->_freq[ii];
458 if (frq._frqType != frqStr) {
459 continue;
460 }
461 corr = 0.0;
462 if (frq._nadirCorrectionIndicator) {
463 corr += frq._nadirCorrection;
464 }
465 if (!frq._nadirAngleCorrection.empty()) {
466 // 1-degree bins starting at nadir (0 deg), per RTCM-SSR spec
467 double nadirDeg = 90.0 - elTx * 180.0 / M_PI;
468 int idx = int(nadirDeg + 0.5);
469 if (idx < 0) {
470 idx = 0;
471 }
472 else if (idx >= (int)frq._nadirAngleCorrection.size()) {
473 idx = (int)frq._nadirAngleCorrection.size() - 1;
474 }
475 corr += frq._nadirAngleCorrection[idx];
476 }
477 return true;
478 }
479 return false;
480}
481
482//
483////////////////////////////////////////////////////////////////////////////
484t_irc t_pppSatObs::cmpModel(const t_pppStation* station) {
485
486 // Reset all model values
487 // ----------------------
488 _model.reset();
489
490 // Topocentric Satellite Position
491 // ------------------------------
492 ColumnVector rSat = _xcSat.Rows(1,3);
493 ColumnVector rRec = station->xyzApr();
494 ColumnVector rhoV = rSat - rRec;
495 _model._rho = rhoV.NormFrobenius();
496
497 ColumnVector vSat = _vvSat;
498
499 ColumnVector neu(3);
500 xyz2neu(station->ellApr().data(), rhoV.data(), neu.data());
501
502 _model._eleSat = acos(sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / _model._rho);
503 if (neu[2] < 0.0) {
504 _model._eleSat *= -1.0;
505 }
506 _model._azSat = atan2(neu[1], neu[0]);
507
508 // Sun unit vector
509 ColumnVector xSun = t_astro::Sun(_time.mjddec());
510 xSun /= xSun.norm_Frobenius();
511
512 // Satellite unit vectors sz, sy, sx
513 ColumnVector sz = -rSat / rSat.norm_Frobenius();
514 ColumnVector sy = crossproduct(sz, xSun);
515 ColumnVector sx = crossproduct(sy, sz);
516
517 sx /= sx.norm_Frobenius();
518 sy /= sy.norm_Frobenius();
519
520 // LOS unit vector satellite --> receiver
521 ColumnVector rho = rRec - rSat;
522 rho /= rho.norm_Frobenius();
523
524 // LOS vector in satellite frame
525 ColumnVector u(3);
526 u(1) = dotproduct(sx, rho);
527 u(2) = dotproduct(sy, rho);
528 u(3) = dotproduct(sz, rho);
529
530 // Azimuth and elevation in satellite antenna frame
531 _model._elTx = atan2(u(3),sqrt(pow(u(2),2)+pow(u(1),2)));
532 _model._azTx = atan2(u(2),u(1));
533
534
535 // Satellite Clocks
536 // ----------------
537 _model._satClkM = _xcSat[3] * t_CST::c; // satellite system specific
538
539 // Receiver Clocks
540 // ---------------
541 _model._recClkM = station->dClk() * t_CST::c;
542
543 // Sagnac Effect (correction due to Earth rotation)
544 // ------------------------------------------------
545 ColumnVector Omega(3);
546 Omega[0] = 0.0;
547 Omega[1] = 0.0;
548 Omega[2] = t_CST::omega / t_CST::c;
549 _model._sagnac = DotProduct(Omega, crossproduct(rSat, rRec));
550
551 // Antenna Eccentricity
552 // --------------------
553 _model._antEcc = -DotProduct(station->xyzEcc(), rhoV) / _model._rho;
554
555 // Antenna Phase Center Offsets and Variations
556 // -------------------------------------------
557 if (PPP_CLIENT->antex()) {
558 const t_satAntenna* satAntenna = PPP_CLIENT->obsPool()->satAntenna(_prn);
559 if (!ssrSatAntennaTrusted(satAntenna, _time)) {
560 satAntenna = 0; // untrusted (IOD zero, or not confirmed via Metadata) - fall back to ANTEX
561 }
562 for (unsigned ii = 0; ii < t_frequency::max; ii++) {
563 t_frequency::type frqType = static_cast<t_frequency::type>(ii);
564 string frqStr = t_frequency::toString(frqType);
565 if (frqStr[0] != _prn.system()) {continue;}
566 bool found;
567 QString prn(_prn.toString().c_str());
568 _model._antPCO[ii] = PPP_CLIENT->antex()->rcvCorr(station->antName(), frqType, _model._eleSat, _model._azSat, found);
569
570 // Prefer a live, trusted SSR Satellite Antenna correction over the
571 // static ANTEX file when available for this satellite/frequency,
572 // mirroring how SSR orbit/clock corrections already take precedence
573 // over broadcast ephemerides elsewhere in this codebase. Unlike
574 // ANTEX's satCorr() (a single geometric PCO/PCV value shared by code
575 // and phase alike), the SSR message's DF+011/DF+012 indicators say
576 // explicitly which observable(s) the correction applies to, so it is
577 // routed into the dedicated phase-only/code-only fields instead of
578 // the shared _antPCO - both may fire for the same ssrCorr value if
579 // both indicators are set.
580 double ssrCorr;
581 if (ssrSatAntennaCorr(satAntenna, frqStr, _model._elTx, ssrCorr)) {
582 if (satAntenna->_phaseCenterInfoInd) {
583 _model._antPCV[ii] += ssrCorr;
584 }
585 if (satAntenna->_groupDelayInfoInd) {
586 _model._antGDV[ii] += ssrCorr;
587 }
588 }
589 else {
590 _model._antPCO[ii] += PPP_CLIENT->antex()->satCorr(prn, frqType, _model._elTx, _model._azTx, found);
591 if (OPT->_isAPC && found) {
592 // the PCOs as given in the satellite antenna correction for all frequencies
593 // have to be reduced by the PCO of the respective reference frequency
594 if (_prn.system() == 'G') {
595 _model._antPCO[ii] -= PPP_CLIENT->antex()->satCorr(prn, t_frequency::G1, _model._elTx, _model._azTx, found);
596 }
597 else if (_prn.system() == 'R') {
598 _model._antPCO[ii] -= PPP_CLIENT->antex()->satCorr(prn, t_frequency::R1, _model._elTx, _model._azTx, found);
599 }
600 else if (_prn.system() == 'E') {
601 _model._antPCO[ii] -= PPP_CLIENT->antex()->satCorr(prn, t_frequency::E1, _model._elTx, _model._azTx, found);
602 }
603 else if (_prn.system() == 'C') {
604 _model._antPCO[ii] -= PPP_CLIENT->antex()->satCorr(prn, t_frequency::C2, _model._elTx, _model._azTx, found);
605 }
606 }
607 }
608 }
609 }
610
611 // Tropospheric Delay
612 // ------------------
613 _model._tropo = t_tropo::delay_saast(rRec, _model._eleSat);
614
615 // Code Biases
616 // -----------
617 const t_satCodeBias* satCodeBias = PPP_CLIENT->obsPool()->satCodeBias(_prn);
618 if (satCodeBias) {
619 for (unsigned ii = 0; ii < satCodeBias->_bias.size(); ii++) {
620 const t_frqCodeBias& bias = satCodeBias->_bias[ii];
621 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
622 string frqStr = t_frequency::toString(t_frequency::type(iFreq));
623 if (frqStr[0] != _prn.system()) {
624 continue;
625 }
626 const t_frqObs* obs = _obs[iFreq];
627 if (obs && obs->_rnxType2ch == bias._rnxType2ch) {
628 _model._codeBias[iFreq] = (bias._value != 0.0 ? bias._value : ZEROVALUE);
629 }
630 }
631 }
632 }
633
634 // Phase Biases
635 // -----------
636 double yaw = 0.0;
637 bool useYaw = false;
638 if (OPT->arSystem(_prn.system())) {
639 const t_satPhaseBias* satPhaseBias = PPP_CLIENT->obsPool()->satPhaseBias(_prn);
640 if (satPhaseBias) {
641 if (OPT->_ar._useYaw) {
642 double dt = station->epochTime() - satPhaseBias->_time;
643 if (satPhaseBias->_updateInt) {
644 dt -= (0.5 * ssrUpdateInt[satPhaseBias->_updateInt]);
645 }
646 yaw = satPhaseBias->_yaw + satPhaseBias->_yawRate * dt;
647 useYaw = true;
648 }
649 for (unsigned ii = 0; ii < satPhaseBias->_bias.size(); ii++) {
650 const t_frqPhaseBias& bias = satPhaseBias->_bias[ii];
651 if (bias._fixIndicator) { // if AR, biases without fixIndicator not used
652 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
653 string frqStr = t_frequency::toString(t_frequency::type(iFreq));
654 if (frqStr[0] != _prn.system()) {
655 continue;
656 }
657 t_frqObs* obs = _obs[iFreq];
658 if (obs && obs->_rnxType2ch[0] == bias._rnxType2ch[0]) { // allow different tracking mode
659 _model._phaseBias[iFreq] = (bias._value != 0.0 ? bias._value : ZEROVALUE);
660 obs->_biasJumpCounter = bias._jumpCounter;
661 }
662 }
663 }
664 }
665 }
666 }
667
668 // Phase Wind-Up
669 // -------------
670 _model._windUp = station->windUp(_time, _prn, rSat, useYaw, yaw, vSat) ;
671
672 // Relativistic effect due to earth gravity
673 // ----------------------------------------
674 double a = rSat.NormFrobenius() + rRec.NormFrobenius();
675 double b = (rSat - rRec).NormFrobenius();
676 double gm = 3.986004418e14; // m3/s2
677 _model._rel = 2 * gm / t_CST::c / t_CST::c * log((a + b) / (a - b));
678
679 // Tidal Correction
680 // ----------------
681 _model._tideEarth = -DotProduct(station->tideDsplEarth(), rhoV) / _model._rho;
682 _model._tideOcean = -DotProduct(station->tideDsplOcean(), rhoV) / _model._rho;
683
684 // Ionospheric Delay
685 // -----------------
686 const t_vTec* vTec = PPP_CLIENT->obsPool()->vTec();
687 bool vTecUsage = true;
688 for (unsigned ii = 0; ii < OPT->LCs(_prn.system()).size(); ii++) {
689 t_lc LC = OPT->LCs(_prn.system())[ii];
690 if (LC._type == t_lc::codeIF || LC._type == t_lc::phaseIF) {
691 vTecUsage = false;
692 }
693 }
694
695 if (vTecUsage && vTec) {
696 double stec = station->stec(vTec, _signalPropagationTime, rSat);
697 double f1GPS = t_CST::freq(t_frequency::G1, 0);
698 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
699 if (OPT->_pseudoObsIono) {
700 // For scaling the slant ionospheric delays the trick is to be consistent with units!
701 // The conversion of TECU into meters requires the frequency of the signal.
702 // Hence, GPS L1 frequency is used for all systems. The same is true for mu_i in lcCoeff().
703 _model._ionoCodeDelay[iFreq] = 40.3E16 / pow(f1GPS, 2) * stec;
704 }
705 else { // PPP-RTK
706 t_frequency::type frqType = static_cast<t_frequency::type>(iFreq);
707 _model._ionoCodeDelay[iFreq] = 40.3E16 / pow(t_CST::freq(frqType, _channel), 2) * stec;
708 }
709 }
710 }
711
712 // Set Model Set Flag
713 // ------------------
714 _model._set = true;
715
716 if (OPT->_logMode == t_pppOptions::all) {
717 printModel();
718 }
719
720 return success;
721}
722
723//
724////////////////////////////////////////////////////////////////////////////
725void t_pppSatObs::printModel() const {
726
727 LOG.setf(ios::fixed);
728 LOG << "\nMODEL for Satellite " << _prn.toString() << (isReference() ? " (Reference Satellite)" : "")
729
730 << "\n======================= " << endl
731 << "PPP "
732 << ((OPT->_pseudoObsIono) ? " with pseudo-observations for STEC" : "") << endl
733 << "RHO : " << setw(12) << setprecision(3) << _model._rho << endl
734 << "ELE : " << setw(12) << setprecision(3) << _model._eleSat * RHO_DEG << endl
735 << "AZI : " << setw(12) << setprecision(3) << _model._azSat * RHO_DEG << endl
736 << "SATCLK : " << setw(12) << setprecision(3) << _model._satClkM << endl
737 << "RECCLK : " << setw(12) << setprecision(3) << _model._recClkM << endl
738 << "SAGNAC : " << setw(12) << setprecision(3) << _model._sagnac << endl
739 << "ANTECC : " << setw(12) << setprecision(3) << _model._antEcc << endl
740 << "TROPO : " << setw(12) << setprecision(3) << _model._tropo << endl
741 << "WINDUP : " << setw(12) << setprecision(3) << _model._windUp << endl
742 << "REL : " << setw(12) << setprecision(3) << _model._rel << endl
743 << "EARTH TIDES : " << setw(12) << setprecision(3) << _model._tideEarth << endl
744 << "OCEAN TIDES : " << setw(12) << setprecision(3) << _model._tideOcean << endl
745 << endl
746 << "FREQUENCY DEPENDENT CORRECTIONS:" << endl
747 << "-------------------------------" << endl;
748 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
749 if (_obs[iFreq]) {
750 string frqStr = t_frequency::toString(t_frequency::type(iFreq));
751 if (_prn.system() == frqStr[0]) {
752 LOG << "PCO : " << frqStr << setw(12) << setprecision(3) << _model._antPCO[iFreq] << endl
753 << "SSR PCV : " << frqStr << setw(12) << setprecision(3) << _model._antPCV[iFreq] << endl
754 << "SSR GDV : " << frqStr << setw(12) << setprecision(3) << _model._antGDV[iFreq] << endl
755 << "BIAS CODE : " << frqStr << setw(12) << setprecision(3) << _model._codeBias[iFreq] << "\t(" << _obs[iFreq]->trkChar() << ") " << endl
756 << "BIAS PHASE : " << frqStr << setw(12) << setprecision(3) << _model._phaseBias[iFreq] << "\t(" << _obs[iFreq]->trkChar() << ") " << endl
757 << "IONO CODEDELAY: " << frqStr << setw(12) << setprecision(3) << _model._ionoCodeDelay[iFreq]<< endl;
758 }
759 }
760 }
761}
762
763//
764////////////////////////////////////////////////////////////////////////////
765void t_pppSatObs::printObsMinusComputed() const {
766 LOG.setf(ios::fixed);
767 LOG << "\nOBS-COMP for Satellite " << _prn.toString() << (isReference() ? " (Reference Satellite)" : "") << endl
768 << "========================== " << endl;
769 char sys = _prn.system();
770 for (unsigned ii = 0; ii < OPT->LCs(sys).size(); ii++) {
771 t_lc LC = OPT->LCs(sys)[ii];
772 LOG << "OBS-CMP " << setw(4) << LC.toString() << ": " << _prn.toString() << " "
773 << setw(12) << setprecision(3) << obsValue(LC) << " "
774 << setw(12) << setprecision(3) << cmpValue(LC) << " "
775 << setw(12) << setprecision(3) << obsValue(LC) - cmpValue(LC) << endl;
776 }
777}
778
779//
780////////////////////////////////////////////////////////////////////////////
781double t_pppSatObs::cmpValueForBanc(t_lc LC) const {
782 return cmpValue(LC) - _model._rho - _model._sagnac - _model._recClkM;
783}
784
785//
786////////////////////////////////////////////////////////////////////////////
787double t_pppSatObs::cmpValue(t_lc LC) const {
788 double cmpValue;
789
790 if (!isValid(LC)) {
791 cmpValue = 0.0;
792 }
793 else if (LC._type == t_lc::GIM) {
794 cmpValue = 0.0;
795 }
796 else {
797 // Non-Dispersive Part
798 // -------------------
799 double nonDisp = _model._rho
800 + _model._recClkM - _model._satClkM
801 + _model._sagnac + _model._antEcc + _model._tropo
802 + _model._tideEarth + _model._tideOcean + _model._rel;
803
804 // Add Dispersive Part
805 // -------------------
806 double dispPart = 0.0;
807 map<t_frequency::type, double> codeCoeff;
808 map<t_frequency::type, double> phaseCoeff;
809 map<t_frequency::type, double> ionoCoeff;
810 lcCoeff(LC, codeCoeff, phaseCoeff, ionoCoeff);
811 map<t_frequency::type, double>::const_iterator it;
812 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
813 t_frequency::type tFreq = it->first;
814 dispPart += it->second * (_model._antPCO[tFreq] + _model._antGDV[tFreq] - _model._codeBias[tFreq]);
815 }
816 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
817 t_frequency::type tFreq = it->first;
818 dispPart += it->second * (_model._antPCO[tFreq] + _model._antPCV[tFreq] - _model._phaseBias[tFreq] +
819 _model._windUp * t_CST::lambda(tFreq, _channel));
820 }
821 cmpValue = nonDisp + dispPart;
822 }
823
824 return cmpValue;
825}
826
827//
828////////////////////////////////////////////////////////////////////////////
829void t_pppSatObs::setRes(t_lc LC, double res) {
830 _res[LC] = res;
831}
832
833//
834////////////////////////////////////////////////////////////////////////////
835double t_pppSatObs::getRes(t_lc LC) const {
836 map<t_lc, double>::const_iterator it = _res.find(LC);
837 if (it != _res.end()) {
838 return it->second;
839 }
840 else {
841 return 0.0;
842 }
843}
844
845//
846////////////////////////////////////////////////////////////////////////////
847bool t_pppSatObs::setPseudoObsIono(t_frequency::type freq, double stecRefSat) {
848 _stecSat = _model._ionoCodeDelay[freq];
849 _stecRefSat = stecRefSat;
850 return (_stecSat != 0.0 && _stecRefSat != 0.0);
851}
852
853//
854////////////////////////////////////////////////////////////////////////////
855bool t_pppSatObs::hasBiases() const {
856 bool ar = OPT->arSystem(_prn.system());
857 set<t_frequency::type> frqs;
858 for (const auto& lc : OPT->LCs(_prn.system())) {
859 if (lc._frq1 != t_frequency::dummy) frqs.insert(lc._frq1);
860 if (lc._frq2 != t_frequency::dummy) frqs.insert(lc._frq2);
861 }
862 for (int iFreq : frqs) {
863 if (_obs[iFreq] != 0) {
864 if (_model._codeBias[iFreq] == 0 || (ar && _model._phaseBias[iFreq] == 0)) {
865 return false;
866 }
867 }
868 }
869 return true;
870}
Note: See TracBrowser for help on using the repository browser.