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

Last change on this file since 6398 was 6116, checked in by mervart, 10 years ago
File size: 15.1 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 = "CWPX_";
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 && obs->_codeValid && obs->_phaseValid) {
73 _obs[iFreq] = new t_frqObs(*obs);
74 }
75 }
76 }
77 }
78 }
79
80 // Used frequency types
81 // --------------------
82 _fType1 = t_lc::toFreq(_prn.system(),t_lc::l1);
83 if (_prn.system() == 'E') {
84 _fType2 = t_frequency::E5;
85 }
86 else {
87 _fType2 = t_lc::toFreq(_prn.system(),t_lc::l2);
88 }
89
90 // Check whether all required frequencies available
91 // ------------------------------------------------
92 for (unsigned ii = 0; ii < OPT->LCs(_prn.system()).size(); ii++) {
93 t_lc::type tLC = OPT->LCs(_prn.system())[ii];
94 if (!isValid(tLC)) {
95 _valid = false;
96 return;
97 }
98 }
99
100 // Find Glonass Channel Number
101 // ---------------------------
102 if (_prn.system() == 'R') {
103 _channel = PPP_CLIENT->ephPool()->getChannel(_prn);
104 }
105 else {
106 _channel = 0;
107 }
108
109 // Compute Satellite Coordinates at Time of Transmission
110 // -----------------------------------------------------
111 _xcSat.ReSize(4); _xcSat = 0.0;
112 _vvSat.ReSize(4); _vvSat = 0.0;
113 bool totOK = false;
114 ColumnVector satPosOld(4); satPosOld = 0.0;
115 t_lc::type tLC = isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
116 double prange = obsValue(tLC);
117 for (int ii = 1; ii <= 10; ii++) {
118 bncTime ToT = _time - prange / t_CST::c - _xcSat[3];
119 if (PPP_CLIENT->ephPool()->getCrd(_prn, ToT, _xcSat, _vvSat) != success) {
120 _valid = false;
121 return;
122 }
123 ColumnVector dx = _xcSat - satPosOld;
124 dx[3] *= t_CST::c;
125 if (dx.norm_Frobenius() < 1.e-4) {
126 totOK = true;
127 break;
128 }
129 satPosOld = _xcSat;
130 }
131 if (totOK) {
132 _model._satClkM = _xcSat[3] * t_CST::c;
133 }
134 else {
135 _valid = false;
136 }
137}
138
139//
140////////////////////////////////////////////////////////////////////////////
141void t_pppSatObs::lcCoeff(t_lc::type tLC,
142 map<t_frequency::type, double>& codeCoeff,
143 map<t_frequency::type, double>& phaseCoeff) const {
144
145 codeCoeff.clear();
146 phaseCoeff.clear();
147
148 double f1 = t_CST::freq(_fType1, _channel);
149 double f2 = t_CST::freq(_fType2, _channel);
150
151 switch (tLC) {
152 case t_lc::l1:
153 phaseCoeff[_fType1] = 1.0;
154 return;
155 case t_lc::l2:
156 phaseCoeff[_fType2] = 1.0;
157 return;
158 case t_lc::lIF:
159 phaseCoeff[_fType1] = f1 * f1 / (f1 * f1 - f2 * f2);
160 phaseCoeff[_fType2] = -f2 * f2 / (f1 * f1 - f2 * f2);
161 return;
162 case t_lc::MW:
163 phaseCoeff[_fType1] = f1 / (f1 - f2);
164 phaseCoeff[_fType2] = -f2 / (f1 - f2);
165 codeCoeff[_fType1] = -f1 / (f1 + f2);
166 codeCoeff[_fType2] = -f2 / (f1 + f2);
167 return;
168 case t_lc::CL:
169 phaseCoeff[_fType1] = 0.5;
170 codeCoeff[_fType1] = 0.5;
171 return;
172 case t_lc::c1:
173 codeCoeff[_fType1] = 1.0;
174 return;
175 case t_lc::c2:
176 codeCoeff[_fType2] = 1.0;
177 return;
178 case t_lc::cIF:
179 codeCoeff[_fType1] = f1 * f1 / (f1 * f1 - f2 * f2);
180 codeCoeff[_fType2] = -f2 * f2 / (f1 * f1 - f2 * f2);
181 return;
182 case t_lc::dummy:
183 case t_lc::maxLc:
184 return;
185 }
186}
187
188//
189////////////////////////////////////////////////////////////////////////////
190bool t_pppSatObs::isValid(t_lc::type tLC) const {
191 bool valid = true;
192 obsValue(tLC, &valid);
193 return valid;
194}
195//
196////////////////////////////////////////////////////////////////////////////
197double t_pppSatObs::obsValue(t_lc::type tLC, bool* valid) const {
198
199 map<t_frequency::type, double> codeCoeff;
200 map<t_frequency::type, double> phaseCoeff;
201 lcCoeff(tLC, codeCoeff, phaseCoeff);
202
203 double retVal = 0.0;
204 if (valid) *valid = true;
205
206 map<t_frequency::type, double>::const_iterator it;
207 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
208 t_frequency::type tFreq = it->first;
209 if (_obs[tFreq] == 0) {
210 if (valid) *valid = false;
211 return 0.0;
212 }
213 else {
214 retVal += it->second * _obs[tFreq]->_code;
215 }
216 }
217 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
218 t_frequency::type tFreq = it->first;
219 if (_obs[tFreq] == 0) {
220 if (valid) *valid = false;
221 return 0.0;
222 }
223 else {
224 retVal += it->second * _obs[tFreq]->_phase * t_CST::lambda(tFreq, _channel);
225 }
226 }
227
228 return retVal;
229}
230
231//
232////////////////////////////////////////////////////////////////////////////
233double t_pppSatObs::lambda(t_lc::type tLC) const {
234
235 double f1 = t_CST::freq(_fType1, _channel);
236 double f2 = t_CST::freq(_fType2, _channel);
237
238 if (tLC == t_lc::l1) {
239 return t_CST::c / f1;
240 }
241 else if (tLC == t_lc::l2) {
242 return t_CST::c / f2;
243 }
244 else if (tLC == t_lc::lIF) {
245 return t_CST::c / (f1 + f2);
246 }
247 else if (tLC == t_lc::MW) {
248 return t_CST::c / (f1 - f2);
249 }
250 else if (tLC == t_lc::CL) {
251 return t_CST::c / f1 / 2.0;
252 }
253
254 return 0.0;
255}
256
257//
258////////////////////////////////////////////////////////////////////////////
259double t_pppSatObs::sigma(t_lc::type tLC) const {
260
261 map<t_frequency::type, double> codeCoeff;
262 map<t_frequency::type, double> phaseCoeff;
263 lcCoeff(tLC, codeCoeff, phaseCoeff);
264
265 double retVal = 0.0;
266
267 map<t_frequency::type, double>::const_iterator it;
268 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
269 retVal += it->second * it->second * OPT->_sigmaC1 * OPT->_sigmaC1;
270 }
271 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
272 retVal += it->second * it->second * OPT->_sigmaL1 * OPT->_sigmaL1;
273 }
274
275 retVal = sqrt(retVal);
276
277 // De-Weight GLONASS
278 // -----------------
279 if (_prn.system() == 'R') {
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 bool found;
365 double pco = PPP_CLIENT->antex()->rcvCorr(station->antName(), _model._eleSat, found);
366 for (unsigned ii = 0; ii < t_frequency::max; ii++) {
367 _model._antPCO[ii] = pco;
368 }
369 }
370
371 // Tropospheric Delay
372 // ------------------
373 _model._tropo = t_tropo::delay_saast(station->xyzApr(), _model._eleSat);
374
375 // Phase Wind-Up
376 // -------------
377 _model._windUp = station->windUp(_time, _prn, rSat);
378
379 // Code and Phase Biases
380 // ---------------------
381 const t_satBias* satBias = PPP_CLIENT->obsPool()->satBias(_prn);
382 if (satBias) {
383 for (unsigned ii = 0; ii < satBias->_bias.size(); ii++) {
384 const t_frqBias& bias = satBias->_bias[ii];
385 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
386 const t_frqObs* obs = _obs[iFreq];
387 if (obs && obs->_rnxType2ch == bias._rnxType2ch) {
388 _model._codeBias[iFreq] = bias._code;
389 _model._phaseBias[iFreq] = bias._phase;
390 }
391 }
392 }
393 }
394
395 // Tidal Correction
396 // ----------------
397 _model._tide = -DotProduct(station->tideDspl(), rhoV) / _model._rho;
398
399 // Ionospheric Delay
400 // -----------------
401 // TODO
402
403 // Ocean Loading
404 // -------------
405 // TODO
406
407 // Set Model Set Flag
408 // ------------------
409 _model._set = true;
410
411 return success;
412}
413
414//
415////////////////////////////////////////////////////////////////////////////
416void t_pppSatObs::printModel() const {
417 LOG.setf(ios::fixed);
418 LOG << "MODEL for Satellite " << _prn.toString() << endl
419 << "RHO: " << setw(12) << setprecision(3) << _model._rho << endl
420 << "ELE: " << setw(12) << setprecision(3) << _model._eleSat * 180.0 / M_PI << endl
421 << "AZI: " << setw(12) << setprecision(3) << _model._azSat * 180.0 / M_PI << endl
422 << "SATCLK: " << setw(12) << setprecision(3) << _model._satClkM << endl
423 << "RECCLK: " << setw(12) << setprecision(3) << _model._recClkM << endl
424 << "SAGNAC: " << setw(12) << setprecision(3) << _model._sagnac << endl
425 << "ANTECC: " << setw(12) << setprecision(3) << _model._antEcc << endl
426 << "TROPO: " << setw(12) << setprecision(3) << _model._tropo << endl
427 << "WINDUP: " << setw(12) << setprecision(3) << _model._windUp << endl
428 << "TIDES: " << setw(12) << setprecision(3) << _model._tide << endl;
429 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
430 if (_obs[iFreq]) {
431 LOG << "PCO: " << t_frequency::toString(t_frequency::type(iFreq)) << setw(12) << setprecision(3) << _model._antPCO[iFreq] << endl
432 << "BIAS CODE: " << t_frequency::toString(t_frequency::type(iFreq)) << setw(12) << setprecision(3) << _model._codeBias[iFreq] << endl
433 << "BIAS PHASE: " << t_frequency::toString(t_frequency::type(iFreq)) << setw(12) << setprecision(3) << _model._phaseBias[iFreq] << endl;
434 }
435 }
436 LOG << "OBS-CMP P3: " << _prn.toString() << " "
437 << setw(12) << setprecision(3) << obsValue(t_lc::cIF) << " "
438 << setw(12) << setprecision(3) << cmpValue(t_lc::cIF) << " "
439 << setw(12) << setprecision(3) << obsValue(t_lc::cIF) - cmpValue(t_lc::cIF) << endl;
440
441 LOG << "OBS-CMP L3: " << _prn.toString() << " "
442 << setw(12) << setprecision(3) << obsValue(t_lc::lIF) << " "
443 << setw(12) << setprecision(3) << cmpValue(t_lc::lIF) << " "
444 << setw(12) << setprecision(3) << obsValue(t_lc::lIF) - cmpValue(t_lc::lIF) << endl;
445
446 LOG << "OBS-CMP MW: " << _prn.toString() << " "
447 << setw(12) << setprecision(3) << obsValue(t_lc::MW) << " "
448 << setw(12) << setprecision(3) << cmpValue(t_lc::MW) << " "
449 << setw(12) << setprecision(3) << obsValue(t_lc::MW) - cmpValue(t_lc::MW) << endl;
450}
451
452//
453////////////////////////////////////////////////////////////////////////////
454double t_pppSatObs::cmpValueForBanc(t_lc::type tLC) const {
455 return cmpValue(tLC) - _model._rho - _model._sagnac - _model._recClkM;
456}
457
458//
459////////////////////////////////////////////////////////////////////////////
460double t_pppSatObs::cmpValue(t_lc::type tLC) const {
461
462 if (!isValid(tLC)) {
463 return 0.0;
464 }
465
466 // Non-Dispersive Part
467 // -------------------
468 double nonDisp = _model._rho + _model._recClkM - _model._satClkM
469 + _model._sagnac + _model._antEcc + _model._tropo
470 + _model._tide;
471
472 // Add Dispersive Part
473 // -------------------
474 map<t_frequency::type, double> codeCoeff;
475 map<t_frequency::type, double> phaseCoeff;
476 lcCoeff(tLC, codeCoeff, phaseCoeff);
477
478 double dispPart = 0.0;
479
480 map<t_frequency::type, double>::const_iterator it;
481 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
482 t_frequency::type tFreq = it->first;
483 dispPart += it->second * (_model._antPCO[tFreq] + _model._codeBias[tFreq]);
484 }
485 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
486 t_frequency::type tFreq = it->first;
487 dispPart += it->second * (_model._antPCO[tFreq] + _model._phaseBias[tFreq] +
488 _model._windUp * t_CST::lambda(tFreq, _channel));
489 }
490
491 return nonDisp + dispPart;
492}
493
494//
495////////////////////////////////////////////////////////////////////////////
496void t_pppSatObs::setRes(t_lc::type tLC, double res) {
497 _res[tLC] = res;
498}
499
500//
501////////////////////////////////////////////////////////////////////////////
502double t_pppSatObs::getRes(t_lc::type tLC) const {
503 map<t_lc::type, double>::const_iterator it = _res.find(tLC);
504 if (it != _res.end()) {
505 return it->second;
506 }
507 else {
508 return 0.0;
509 }
510}
Note: See TracBrowser for help on using the repository browser.