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

Last change on this file since 8215 was 8026, checked in by stuerze, 8 years ago

minor changes to prevent the usage of zero observation values in PPP

  • Property svn:keywords set to Author Date Id Rev URL;svn:eol-style=native
  • Property svn:mime-type set to text/plain
File size: 16.4 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 <cmath>
20#include <newmatio.h>
21
22#include "pppSatObs.h"
23#include "bncconst.h"
24#include "pppEphPool.h"
25#include "pppStation.h"
26#include "bncutils.h"
27#include "bncantex.h"
28#include "pppObsPool.h"
29#include "pppClient.h"
30
31using namespace BNC_PPP;
32using namespace std;
33
34// Constructor
35////////////////////////////////////////////////////////////////////////////
36t_pppSatObs::t_pppSatObs(const t_satObs& pppSatObs) {
37 _prn = pppSatObs._prn;
38 _time = pppSatObs._time;
39 _outlier = false;
40 _valid = true;
41 for (unsigned ii = 0; ii < t_frequency::max; ii++) {
42 _obs[ii] = 0;
43 }
44 prepareObs(pppSatObs);
45}
46
47// Destructor
48////////////////////////////////////////////////////////////////////////////
49t_pppSatObs::~t_pppSatObs() {
50 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
51 delete _obs[iFreq];
52 }
53}
54
55//
56////////////////////////////////////////////////////////////////////////////
57void t_pppSatObs::prepareObs(const t_satObs& pppSatObs) {
58
59 _model.reset();
60
61 // Select pseudoranges and phase observations
62 // ------------------------------------------
63 const string preferredAttrib = "CWPXI_";
64
65 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
66 string frqNum = t_frequency::toString(t_frequency::type(iFreq)).substr(1);
67 for (unsigned iPref = 0; iPref < preferredAttrib.length(); iPref++) {
68 string obsType = (preferredAttrib[iPref] == '_') ? frqNum : frqNum + preferredAttrib[iPref];
69 if (_obs[iFreq] == 0) {
70 for (unsigned ii = 0; ii < pppSatObs._obs.size(); ii++) {
71 const t_frqObs* obs = pppSatObs._obs[ii];
72 if (obs->_rnxType2ch == obsType &&
73 obs->_codeValid && obs->_code &&
74 obs->_phaseValid && obs->_phase) {
75 _obs[iFreq] = new t_frqObs(*obs);
76 }
77 }
78 }
79 }
80 }
81
82 // Used frequency types
83 // --------------------
84 _fType1 = t_lc::toFreq(_prn.system(),t_lc::l1);
85 _fType2 = t_lc::toFreq(_prn.system(),t_lc::l2);
86
87 // Check whether all required frequencies available
88 // ------------------------------------------------
89 for (unsigned ii = 0; ii < OPT->LCs(_prn.system()).size(); ii++) {
90 t_lc::type tLC = OPT->LCs(_prn.system())[ii];
91 if (!isValid(tLC)) {
92 _valid = false;
93 return;
94 }
95 }
96
97 // Find Glonass Channel Number
98 // ---------------------------
99 if (_prn.system() == 'R') {
100 _channel = PPP_CLIENT->ephPool()->getChannel(_prn);
101 }
102 else {
103 _channel = 0;
104 }
105
106 // Compute Satellite Coordinates at Time of Transmission
107 // -----------------------------------------------------
108 _xcSat.ReSize(4); _xcSat = 0.0;
109 _vvSat.ReSize(4); _vvSat = 0.0;
110 bool totOK = false;
111 ColumnVector satPosOld(4); satPosOld = 0.0;
112 t_lc::type tLC = isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
113 double prange = obsValue(tLC);
114 for (int ii = 1; ii <= 10; ii++) {
115 bncTime ToT = _time - prange / t_CST::c - _xcSat[3];
116 if (PPP_CLIENT->ephPool()->getCrd(_prn, ToT, _xcSat, _vvSat) != success) {
117 _valid = false;
118 return;
119 }
120 ColumnVector dx = _xcSat - satPosOld;
121 dx[3] *= t_CST::c;
122 if (dx.norm_Frobenius() < 1.e-4) {
123 totOK = true;
124 break;
125 }
126 satPosOld = _xcSat;
127 }
128 if (totOK) {
129 _signalPropagationTime = prange / t_CST::c - _xcSat[3];
130 _model._satClkM = _xcSat[3] * t_CST::c;
131 }
132 else {
133 _valid = false;
134 }
135}
136
137//
138////////////////////////////////////////////////////////////////////////////
139void t_pppSatObs::lcCoeff(t_lc::type tLC,
140 map<t_frequency::type, double>& codeCoeff,
141 map<t_frequency::type, double>& phaseCoeff) const {
142
143 codeCoeff.clear();
144 phaseCoeff.clear();
145
146 double f1 = t_CST::freq(_fType1, _channel);
147 double f2 = t_CST::freq(_fType2, _channel);
148
149 switch (tLC) {
150 case t_lc::l1:
151 phaseCoeff[_fType1] = 1.0;
152 return;
153 case t_lc::l2:
154 phaseCoeff[_fType2] = 1.0;
155 return;
156 case t_lc::lIF:
157 phaseCoeff[_fType1] = f1 * f1 / (f1 * f1 - f2 * f2);
158 phaseCoeff[_fType2] = -f2 * f2 / (f1 * f1 - f2 * f2);
159 return;
160 case t_lc::MW:
161 phaseCoeff[_fType1] = f1 / (f1 - f2);
162 phaseCoeff[_fType2] = -f2 / (f1 - f2);
163 codeCoeff[_fType1] = -f1 / (f1 + f2);
164 codeCoeff[_fType2] = -f2 / (f1 + f2);
165 return;
166 case t_lc::CL:
167 phaseCoeff[_fType1] = 0.5;
168 codeCoeff[_fType1] = 0.5;
169 return;
170 case t_lc::c1:
171 codeCoeff[_fType1] = 1.0;
172 return;
173 case t_lc::c2:
174 codeCoeff[_fType2] = 1.0;
175 return;
176 case t_lc::cIF:
177 codeCoeff[_fType1] = f1 * f1 / (f1 * f1 - f2 * f2);
178 codeCoeff[_fType2] = -f2 * f2 / (f1 * f1 - f2 * f2);
179 return;
180 case t_lc::dummy:
181 case t_lc::maxLc:
182 return;
183 }
184}
185
186//
187////////////////////////////////////////////////////////////////////////////
188bool t_pppSatObs::isValid(t_lc::type tLC) const {
189 bool valid = true;
190 obsValue(tLC, &valid);
191 return valid;
192}
193//
194////////////////////////////////////////////////////////////////////////////
195double t_pppSatObs::obsValue(t_lc::type tLC, bool* valid) const {
196
197 map<t_frequency::type, double> codeCoeff;
198 map<t_frequency::type, double> phaseCoeff;
199 lcCoeff(tLC, codeCoeff, phaseCoeff);
200
201 double retVal = 0.0;
202 if (valid) *valid = true;
203
204 map<t_frequency::type, double>::const_iterator it;
205 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
206 t_frequency::type tFreq = it->first;
207 if (_obs[tFreq] == 0) {
208 if (valid) *valid = false;
209 return 0.0;
210 }
211 else {
212 retVal += it->second * _obs[tFreq]->_code;
213 }
214 }
215 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
216 t_frequency::type tFreq = it->first;
217 if (_obs[tFreq] == 0) {
218 if (valid) *valid = false;
219 return 0.0;
220 }
221 else {
222 retVal += it->second * _obs[tFreq]->_phase * t_CST::lambda(tFreq, _channel);
223 }
224 }
225
226 return retVal;
227}
228
229//
230////////////////////////////////////////////////////////////////////////////
231double t_pppSatObs::lambda(t_lc::type tLC) const {
232
233 double f1 = t_CST::freq(_fType1, _channel);
234 double f2 = t_CST::freq(_fType2, _channel);
235
236 if (tLC == t_lc::l1) {
237 return t_CST::c / f1;
238 }
239 else if (tLC == t_lc::l2) {
240 return t_CST::c / f2;
241 }
242 else if (tLC == t_lc::lIF) {
243 return t_CST::c / (f1 + f2);
244 }
245 else if (tLC == t_lc::MW) {
246 return t_CST::c / (f1 - f2);
247 }
248 else if (tLC == t_lc::CL) {
249 return t_CST::c / f1 / 2.0;
250 }
251
252 return 0.0;
253}
254
255//
256////////////////////////////////////////////////////////////////////////////
257double t_pppSatObs::sigma(t_lc::type tLC) const {
258
259 map<t_frequency::type, double> codeCoeff;
260 map<t_frequency::type, double> phaseCoeff;
261 lcCoeff(tLC, codeCoeff, phaseCoeff);
262
263 double retVal = 0.0;
264
265 map<t_frequency::type, double>::const_iterator it;
266 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
267 retVal += it->second * it->second * OPT->_sigmaC1 * OPT->_sigmaC1;
268 }
269 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
270 retVal += it->second * it->second * OPT->_sigmaL1 * OPT->_sigmaL1;
271 }
272
273 retVal = sqrt(retVal);
274
275 // De-Weight GLONASS
276 // -----------------
277 if (_prn.system() == 'R') {
278 retVal *= 5.0;
279 }
280
281 // Elevation-Dependent Weighting
282 // -----------------------------
283 double cEle = 1.0;
284 if ( (OPT->_eleWgtCode && t_lc::includesCode(tLC)) ||
285 (OPT->_eleWgtPhase && t_lc::includesPhase(tLC)) ) {
286 double eleD = eleSat()*180.0/M_PI;
287 double hlp = fabs(90.0 - eleD);
288 cEle = (1.0 + hlp*hlp*hlp*0.000004);
289 }
290
291 return cEle * retVal;
292}
293
294//
295////////////////////////////////////////////////////////////////////////////
296double t_pppSatObs::maxRes(t_lc::type tLC) const {
297
298 map<t_frequency::type, double> codeCoeff;
299 map<t_frequency::type, double> phaseCoeff;
300 lcCoeff(tLC, codeCoeff, phaseCoeff);
301
302 double retVal = 0.0;
303
304 map<t_frequency::type, double>::const_iterator it;
305 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
306 retVal += it->second * it->second * OPT->_maxResC1 * OPT->_maxResC1;
307 }
308 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
309 retVal += it->second * it->second * OPT->_maxResL1 * OPT->_maxResL1;
310 }
311
312 return sqrt(retVal);
313}
314
315
316//
317////////////////////////////////////////////////////////////////////////////
318t_irc t_pppSatObs::cmpModel(const t_pppStation* station) {
319
320 // Reset all model values
321 // ----------------------
322 _model.reset();
323
324 // Topocentric Satellite Position
325 // ------------------------------
326 ColumnVector rSat = _xcSat.Rows(1,3);
327 ColumnVector rhoV = rSat - station->xyzApr();
328 _model._rho = rhoV.norm_Frobenius();
329
330 ColumnVector neu(3);
331 xyz2neu(station->ellApr().data(), rhoV.data(), neu.data());
332
333 _model._eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / _model._rho );
334 if (neu[2] < 0) {
335 _model._eleSat *= -1.0;
336 }
337 _model._azSat = atan2(neu[1], neu[0]);
338
339 // Satellite Clocks
340 // ----------------
341 _model._satClkM = _xcSat[3] * t_CST::c;
342
343 // Receiver Clocks
344 // ---------------
345 _model._recClkM = station->dClk() * t_CST::c;
346
347 // Sagnac Effect (correction due to Earth rotation)
348 // ------------------------------------------------
349 ColumnVector Omega(3);
350 Omega[0] = 0.0;
351 Omega[1] = 0.0;
352 Omega[2] = t_CST::omega / t_CST::c;
353 _model._sagnac = DotProduct(Omega, crossproduct(rSat, station->xyzApr()));
354
355 // Antenna Eccentricity
356 // --------------------
357 _model._antEcc = -DotProduct(station->xyzEcc(), rhoV) / _model._rho;
358
359 // Antenna Phase Center Offsets and Variations
360 // -------------------------------------------
361 if (PPP_CLIENT->antex()) {
362 for (unsigned ii = 0; ii < t_frequency::max; ii++) {
363 t_frequency::type frqType = static_cast<t_frequency::type>(ii);
364 bool found;
365 _model._antPCO[ii] = PPP_CLIENT->antex()->rcvCorr(station->antName(), frqType,
366 _model._eleSat, _model._azSat, found);
367 }
368 }
369
370 // Tropospheric Delay
371 // ------------------
372 _model._tropo = t_tropo::delay_saast(station->xyzApr(), _model._eleSat);
373
374 // Phase Wind-Up
375 // -------------
376 _model._windUp = station->windUp(_time, _prn, rSat);
377
378 // Code Biases
379 // -----------
380 const t_satCodeBias* satCodeBias = PPP_CLIENT->obsPool()->satCodeBias(_prn);
381 if (satCodeBias) {
382 for (unsigned ii = 0; ii < satCodeBias->_bias.size(); ii++) {
383 const t_frqCodeBias& bias = satCodeBias->_bias[ii];
384 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
385 const t_frqObs* obs = _obs[iFreq];
386 if (obs && obs->_rnxType2ch == bias._rnxType2ch) {
387 _model._codeBias[iFreq] = bias._value;
388 }
389 }
390 }
391 }
392
393 // Phase Biases
394 // -----------
395 // TODO: consideration of fix indicators, yaw angle and jump counter
396 const t_satPhaseBias* satPhaseBias = PPP_CLIENT->obsPool()->satPhaseBias(_prn);
397 if (satPhaseBias) {
398 for (unsigned ii = 0; ii < satPhaseBias->_bias.size(); ii++) {
399 const t_frqPhaseBias& bias = satPhaseBias->_bias[ii];
400 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
401 const t_frqObs* obs = _obs[iFreq];
402 if (obs && obs->_rnxType2ch == bias._rnxType2ch) {
403 _model._phaseBias[iFreq] = bias._value;
404 }
405 }
406 }
407 }
408
409 // Tidal Correction
410 // ----------------
411 _model._tide = -DotProduct(station->tideDspl(), rhoV) / _model._rho;
412
413 // Ionospheric Delay
414 // -----------------
415 const t_vTec* vTec = PPP_CLIENT->obsPool()->vTec();
416 bool vTecUsage = true;
417 for (unsigned ii = 0; ii < OPT->LCs(_prn.system()).size(); ii++) {
418 t_lc::type tLC = OPT->LCs(_prn.system())[ii];
419 if (tLC == t_lc::cIF || tLC == t_lc::lIF) {
420 vTecUsage = false;
421 }
422 }
423 if (vTecUsage && vTec) {
424 double stec = station->stec(vTec, _signalPropagationTime, rSat);
425 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
426 t_frequency::type frqType = static_cast<t_frequency::type>(iFreq);
427 _model._ionoCodeDelay[iFreq] = 40.3E16 / pow(t_CST::freq(frqType, _channel), 2) * stec;
428 }
429 }
430
431 // Ocean Loading
432 // -------------
433 // TODO
434
435 // Set Model Set Flag
436 // ------------------
437 _model._set = true;
438
439 //printModel();
440
441 return success;
442}
443
444//
445////////////////////////////////////////////////////////////////////////////
446void t_pppSatObs::printModel() const {
447
448 LOG.setf(ios::fixed);
449 LOG << "MODEL for Satellite " << _prn.toString() << endl
450 << "RHO: " << setw(12) << setprecision(3) << _model._rho << endl
451 << "ELE: " << setw(12) << setprecision(3) << _model._eleSat * 180.0 / M_PI << endl
452 << "AZI: " << setw(12) << setprecision(3) << _model._azSat * 180.0 / M_PI << endl
453 << "SATCLK: " << setw(12) << setprecision(3) << _model._satClkM << endl
454 << "RECCLK: " << setw(12) << setprecision(3) << _model._recClkM << endl
455 << "SAGNAC: " << setw(12) << setprecision(3) << _model._sagnac << endl
456 << "ANTECC: " << setw(12) << setprecision(3) << _model._antEcc << endl
457 << "TROPO: " << setw(12) << setprecision(3) << _model._tropo << endl
458 << "WINDUP: " << setw(12) << setprecision(3) << _model._windUp << endl
459 << "TIDES: " << setw(12) << setprecision(3) << _model._tide << endl;
460 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
461 if (_obs[iFreq]) {
462 string frqStr = t_frequency::toString(t_frequency::type(iFreq));
463 if (_prn.system() == frqStr[0]) {
464 LOG << "PCO : " << frqStr << setw(12) << setprecision(3) << _model._antPCO[iFreq] << endl
465 << "BIAS CODE : " << frqStr << setw(12) << setprecision(3) << _model._codeBias[iFreq] << endl
466 << "BIAS PHASE : " << frqStr << setw(12) << setprecision(3) << _model._phaseBias[iFreq] << endl
467 << "IONO CODEDELAY: " << frqStr << setw(12) << setprecision(3) << _model._ionoCodeDelay[iFreq] << endl;
468 }
469 }
470 }
471 for (unsigned ii = 0; ii < OPT->LCs(_prn.system()).size(); ii++) {
472 t_lc::type tLC = OPT->LCs(_prn.system())[ii];
473 LOG << "OBS-CMP " << t_lc::toString(tLC) << ": " << _prn.toString() << " "
474 << setw(12) << setprecision(3) << obsValue(tLC) << " "
475 << setw(12) << setprecision(3) << cmpValue(tLC) << " "
476 << setw(12) << setprecision(3) << obsValue(tLC) - cmpValue(tLC) << endl;
477
478 }
479 LOG << "OBS-CMP MW: " << _prn.toString() << " "
480 << setw(12) << setprecision(3) << obsValue(t_lc::MW) << " "
481 << setw(12) << setprecision(3) << cmpValue(t_lc::MW) << " "
482 << setw(12) << setprecision(3) << obsValue(t_lc::MW) - cmpValue(t_lc::MW) << endl;
483}
484
485//
486////////////////////////////////////////////////////////////////////////////
487double t_pppSatObs::cmpValueForBanc(t_lc::type tLC) const {
488 return cmpValue(tLC) - _model._rho - _model._sagnac - _model._recClkM;
489}
490
491//
492////////////////////////////////////////////////////////////////////////////
493double t_pppSatObs::cmpValue(t_lc::type tLC) const {
494
495 if (!isValid(tLC)) {
496 return 0.0;
497 }
498
499 // Non-Dispersive Part
500 // -------------------
501 double nonDisp = _model._rho + _model._recClkM - _model._satClkM
502 + _model._sagnac + _model._antEcc + _model._tropo
503 + _model._tide;
504
505 // Add Dispersive Part
506 // -------------------
507 map<t_frequency::type, double> codeCoeff;
508 map<t_frequency::type, double> phaseCoeff;
509 lcCoeff(tLC, codeCoeff, phaseCoeff);
510
511 double dispPart = 0.0;
512
513 map<t_frequency::type, double>::const_iterator it;
514 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
515 t_frequency::type tFreq = it->first;
516 dispPart += it->second * (_model._antPCO[tFreq] - _model._codeBias[tFreq] +
517 _model._ionoCodeDelay[tFreq]);
518 }
519 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
520 t_frequency::type tFreq = it->first;
521 dispPart += it->second * (_model._antPCO[tFreq] - _model._phaseBias[tFreq] +
522 _model._windUp * t_CST::lambda(tFreq, _channel) -
523 _model._ionoCodeDelay[tFreq]);
524 }
525
526 return nonDisp + dispPart;
527}
528
529//
530////////////////////////////////////////////////////////////////////////////
531void t_pppSatObs::setRes(t_lc::type tLC, double res) {
532 _res[tLC] = res;
533}
534
535//
536////////////////////////////////////////////////////////////////////////////
537double t_pppSatObs::getRes(t_lc::type tLC) const {
538 map<t_lc::type, double>::const_iterator it = _res.find(tLC);
539 if (it != _res.end()) {
540 return it->second;
541 }
542 else {
543 return 0.0;
544 }
545}
Note: See TracBrowser for help on using the repository browser.