source: ntrip/branches/BNC_2.12/src/PPP/pppSatObs.cpp@ 9085

Last change on this file since 9085 was 9085, checked in by stuerze, 4 years ago

minor changes

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