source: ntrip/trunk/BNC/src/PPP/pppFilter.cpp@ 9386

Last change on this file since 9386 was 9386, checked in by stuerze, 3 years ago

update regarding 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: 26.3 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: t_pppFilter
6 *
7 * Purpose: Filter Adjustment
8 *
9 * Author: L. Mervart
10 *
11 * Created: 29-Jul-2014
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include <iostream>
18#include <iomanip>
19#include <cmath>
20#include <newmat.h>
21#include <newmatio.h>
22#include <newmatap.h>
23
24#include "pppFilter.h"
25#include "bncutils.h"
26#include "pppParlist.h"
27#include "pppObsPool.h"
28#include "pppStation.h"
29
30using namespace BNC_PPP;
31using namespace std;
32
33// Constructor
34////////////////////////////////////////////////////////////////////////////
35t_pppFilter::t_pppFilter(t_pppObsPool* obsPool) {
36 _parlist = 0;
37 _numSat = 0;
38 _obsPool = obsPool;
39 _refPrn = t_prn();
40 _datumTrafo = new t_datumTrafo();
41}
42
43// Destructor
44////////////////////////////////////////////////////////////////////////////
45t_pppFilter::~t_pppFilter() {
46 delete _parlist;
47 delete _datumTrafo;
48}
49
50// Process Single Epoch
51////////////////////////////////////////////////////////////////////////////
52t_irc t_pppFilter::processEpoch() {
53 _numSat = 0;
54 const double maxSolGap = 60.0;
55
56 if (!_parlist) {
57 _parlist = new t_pppParlist();
58 }
59
60 // Vector of all Observations
61 // --------------------------
62 t_pppObsPool::t_epoch* epoch = _obsPool->lastEpoch();
63 if (!epoch) {
64 return failure;
65 }
66 vector<t_pppSatObs*>& allObs = epoch->obsVector();
67
68 // Time of the Epoch
69 // -----------------
70 _epoTime = epoch->epoTime();
71
72 if (!_firstEpoTime.valid() ||
73 !_lastEpoTimeOK.valid() ||
74 (maxSolGap > 0.0 && _epoTime - _lastEpoTimeOK > maxSolGap)) {
75 _firstEpoTime = _epoTime;
76 }
77
78 string epoTimeStr = string(_epoTime);
79
80 //--
81 // Set Parameters
82 // --------------
83 _parlist->set(_epoTime, allObs, _obsPool->getRefSatMap());
84 const vector<t_pppParam*>& params = _parlist->params();
85#ifdef BNC_DEBUG_PPP
86 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
87 LOG << params[iPar]->toString() << endl;
88 }
89#endif
90 // Status Vector, Variance-Covariance Matrix
91 // -----------------------------------------
92 ColumnVector xFltOld = _xFlt;
93 SymmetricMatrix QFltOld = _QFlt;
94
95 _QFlt.ReSize(_parlist->nPar()); _QFlt = 0.0;
96 _xFlt.ReSize(_parlist->nPar()); _xFlt = 0.0;
97 _x0.ReSize(_parlist->nPar()); _x0 = 0.0;
98
99 for (unsigned ii = 0; ii < params.size(); ii++) {
100 t_pppParam* par1 = params[ii];
101 if (QFltOld.size() == 0) {
102 par1->resetIndex();
103 }
104 _x0[ii] = par1->x0();
105 int iOld = par1->indexOld();
106 if (iOld < 0) {
107 _QFlt[ii][ii] = par1->sigma0() * par1->sigma0(); // new parameter
108 }
109 else {
110 _QFlt[ii][ii] = QFltOld[iOld][iOld] + par1->noise() * par1->noise();
111 _xFlt[ii] = xFltOld[iOld];
112 for (unsigned jj = 0; jj < ii; jj++) {
113 t_pppParam* par2 = params[jj];
114 int jOld = par2->indexOld();
115 if (jOld >= 0) {
116 _QFlt[ii][jj] = QFltOld(iOld+1,jOld+1);
117 }
118 }
119 }
120 }
121 predictCovCrdPart(QFltOld);
122
123 // Pre-Process Satellite Systems separately
124 // ----------------------------------------
125 bool preProcessing = false;
126 if (OPT->_obsModelType == OPT->DCMcodeBias ||
127 OPT->_obsModelType == OPT->DCMphaseBias) {
128 preProcessing = true;
129 for (unsigned iSys = 0; iSys < OPT->systems().size(); iSys++) {
130 char sys = OPT->systems()[iSys];
131 if (OPT->_refSatRequired) {
132 _refPrn = (_obsPool->getRefSatMapElement(sys))->prn();
133 }
134 vector<t_pppSatObs*> obsVector;
135 for (unsigned jj = 0; jj < allObs.size(); jj++) {
136 if (allObs[jj]->prn().system() == sys) {
137 obsVector.push_back(allObs[jj]);
138 }
139 }
140 if (processSystem(OPT->LCs(sys), obsVector, _refPrn,
141 epoch->pseudoObsIono(), preProcessing) != success) {
142 _xFlt = xFltOld;
143 _QFlt = QFltOld;
144 return failure;
145 }
146 }
147 // refSat change required?
148 // -----------------------
149 if (_obsPool->refSatChangeRequired()) {
150 _xFlt = xFltOld;
151 _QFlt = QFltOld;
152 return success;
153 }
154 else if (!_obsPool->refSatChangeRequired()) {
155 initDatumTransformation(allObs);
156 }
157 }
158
159 // Process Satellite Systems separately
160 // ------------------------------------
161 preProcessing = false;
162 for (unsigned iSys = 0; iSys < OPT->systems().size(); iSys++) {
163 (iSys) ? _datumTrafo->setFirstSystem(false) : _datumTrafo->setFirstSystem(true);
164 char system = OPT->systems()[iSys];
165 if (OPT->_refSatRequired) {
166 _refPrn = (_obsPool->getRefSatMapElement(system))->prn();
167 }
168 unsigned int num = 0;
169 vector<t_pppSatObs*> obsVector;
170 for (unsigned jj = 0; jj < allObs.size(); jj++) {
171 if (allObs[jj]->prn().system() == system) {
172 obsVector.push_back(allObs[jj]);
173 num++;
174 }
175 }
176 LOG << epoTimeStr << " SATNUM " << system << ' ' << right << setw(2) << num << endl;
177 if (processSystem(OPT->LCs(system), obsVector, _refPrn,
178 epoch->pseudoObsIono(), preProcessing) != success) {
179 return failure;
180 }
181 }
182
183 // close epoch processing
184 // ----------------------
185 cmpDOP(allObs);
186 _parlist->printResult(_epoTime, _QFlt, _xFlt);
187 _lastEpoTimeOK = _epoTime; // remember time of last successful epoch processing
188 if (OPT->_refSatRequired) {
189 _obsPool->saveLastEpoRefSats();
190 }
191 return success;
192}
193
194// Process Selected LCs
195////////////////////////////////////////////////////////////////////////////
196t_irc t_pppFilter::processSystem(const vector<t_lc::type>& LCs,
197 const vector<t_pppSatObs*>& obsVector,
198 const t_prn& refPrn,
199 bool pseudoObsIonoAvailable,
200 bool preProcessing) {
201 LOG.setf(ios::fixed);
202 char sys = refPrn.system();
203
204 // Detect Cycle Slips
205 // ------------------
206 if (detectCycleSlips(LCs, obsVector, refPrn, preProcessing) != success) {
207 return failure;
208 }
209 if (preProcessing && _obsPool->refSatChangeRequired(sys)) { // from detectCycleSlips()
210#ifdef BNC_DEBUG_PPP
211 LOG << "_obsPool->refSatChangeRequired(" << sys << ") from detectCycleSlips()" << endl;
212#endif
213 return success;
214 }
215
216 ColumnVector xSav = _xFlt;
217 SymmetricMatrix QSav = _QFlt;
218 string epoTimeStr = string(_epoTime);
219 const vector<t_pppParam*>& params = _parlist->params();
220
221 unsigned usedLCs = LCs.size();
222 unsigned realUsedLCs = usedLCs;
223 if (OPT->_pseudoObsIono && !pseudoObsIonoAvailable) {
224 usedLCs -= 1; // GIM not used
225 }
226 int hlpLCs = 0;
227 if (OPT->_pseudoObsTropo) {
228 hlpLCs = -1;
229 realUsedLCs -= 1;
230 }
231 // max Obs
232 unsigned maxObs = obsVector.size() * (usedLCs + hlpLCs);
233 if (OPT->_pseudoObsTropo) {
234 maxObs += 1;
235 }
236 if (OPT->_pseudoObsIono && pseudoObsIonoAvailable) {
237 maxObs -= 1; // pseudo obs iono with respect to refSat
238 }
239
240 // Outlier Detection Loop
241 // ----------------------
242 for (unsigned iOutlier = 0; iOutlier < maxObs; iOutlier++) {
243
244 if (iOutlier > 0) {
245 _xFlt = xSav;
246 _QFlt = QSav;
247 }
248
249 // First-Design Matrix, Terms Observed-Computed, Weight Matrix
250 // -----------------------------------------------------------
251 Matrix AA(maxObs, _parlist->nPar());
252 ColumnVector ll(maxObs);
253 DiagonalMatrix PP(maxObs); PP = 0.0;
254
255 int iObs = -1;
256 vector<t_pppSatObs*> usedObs;
257 vector<t_lc::type> usedTypes;
258
259 // Real Observations
260 // =================
261 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
262 t_pppSatObs* obs = obsVector[ii];
263 if (!obs->outlier()) {
264 for (unsigned jj = 0; jj < usedLCs; jj++) {
265 const t_lc::type tLC = LCs[jj];
266 if (tLC == t_lc::GIM) {continue;}
267 if (tLC == t_lc::Tz0) {continue;}
268 ++iObs;
269 usedObs.push_back(obs);
270 usedTypes.push_back(tLC);
271 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
272 const t_pppParam* par = params[iPar];
273 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
274 }
275 ll[iObs] = obs->obsValue(tLC) - obs->cmpValue(tLC) - DotProduct(_x0, AA.Row(iObs+1));
276 PP[iObs] = 1.0 / (obs->sigma(tLC) * obs->sigma(tLC));
277 }
278 }
279 }
280
281 if ((!iOutlier) &&
282 (OPT->_obsModelType == OPT->DCMcodeBias ||
283 OPT->_obsModelType == OPT->DCMphaseBias ) && (!preProcessing)) {
284 _datumTrafo->updateIndices(iObs+1);
285 _datumTrafo->prepareAA(AA.SubMatrix(1, iObs+1 , 1, _parlist->nPar()), 1);
286 }
287
288 // Pseudo Obs Iono
289 // ================
290 if (OPT->_pseudoObsIono && pseudoObsIonoAvailable) {
291 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
292 t_pppSatObs* obs = obsVector[ii];
293 if (!obs->outlier()) {
294 for (unsigned jj = 0; jj < usedLCs; jj++) {
295 const t_lc::type tLC = LCs[jj];
296 if (tLC == t_lc::GIM && !obs->isReference()) {
297 ++iObs;
298 } else {continue;}
299 usedObs.push_back(obs);
300 usedTypes.push_back(tLC);
301 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
302 const t_pppParam* par = params[iPar];
303 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
304 }
305 ll[iObs] = obs->obsValue(tLC) - obs->cmpValue(tLC) - DotProduct(_x0, AA.Row(iObs+1));
306 PP[iObs] = 1.0 / (obs->sigma(tLC) * obs->sigma(tLC));
307 }
308 }
309 }
310 }
311 // pseudo Obs Tropo
312 // ================
313 if (OPT->_pseudoObsTropo) {
314 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
315 t_pppSatObs* obs = obsVector[ii];
316 if (!obs->isReference()) {continue;}
317 for (unsigned jj = 0; jj < usedLCs; jj++) {
318 const t_lc::type tLC = LCs[jj];
319 if (tLC != t_lc::Tz0) {continue;}
320 ++iObs;
321 usedObs.push_back(obs);
322 usedTypes.push_back(tLC);
323 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
324 const t_pppParam* par = params[iPar];
325 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
326 }
327 ll[iObs] = obs->obsValue(tLC) - obs->cmpValue(tLC) - DotProduct(_x0, AA.Row(iObs+1));
328 PP[iObs] = 1.0 / (obs->sigma(tLC) * obs->sigma(tLC));
329 }
330 }
331 }
332
333 // Check number of observations, truncate matrices
334 // -----------------------------------------------
335 if (iObs == -1) {
336 return failure;
337 }
338 AA = AA.Rows(1, iObs+1);
339 ll = ll.Rows(1, iObs+1);
340 PP = PP.SymSubMatrix(1, iObs+1);
341
342 // Kalman update step
343 // ------------------
344 kalman(AA, ll, PP, _QFlt, _xFlt);
345
346 // Check Residuals
347 // ---------------
348 ColumnVector vv = AA * _xFlt - ll;
349 double maxOutlier = 0.0;
350 int maxOutlierIndex = -1;
351 t_lc::type maxOutlierLC = t_lc::dummy;
352 for (unsigned ii = 0; ii < usedObs.size(); ii++) {
353 const t_lc::type tLC = usedTypes[ii];
354 double res = fabs(vv[ii]);
355 if (res > usedObs[ii]->maxRes(tLC)) {
356 if (res > fabs(maxOutlier)) {
357 maxOutlier = vv[ii];
358 maxOutlierIndex = ii;
359 maxOutlierLC = tLC;
360 }
361 }
362 }
363
364 // Mark outlier or break outlier detection loop
365 // --------------------------------------------
366 if (maxOutlierIndex > -1) {
367 t_pppSatObs* obs = usedObs[maxOutlierIndex];
368 t_pppParam* par = 0;
369#ifdef BNC_DEBUG_PPP
370 LOG << epoTimeStr << " Outlier ("
371 << ((preProcessing) ? "pre-processing) " : "fin-processing) ") << t_lc::toString(maxOutlierLC) << ' '
372 << obs->prn().toString() << ' '
373 << setw(8) << setprecision(4) << maxOutlier << endl;
374#endif
375 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
376 t_pppParam* hlp = params[iPar];
377 if (hlp->type() == t_pppParam::amb &&
378 hlp->prn() == obs->prn() &&
379 hlp->tLC() == usedTypes[maxOutlierIndex]) {
380 par = hlp;
381 }
382 }
383 if (preProcessing) {
384 // for refSats no ambiguity parameter exists
385 if ((obs->prn() == refPrn) &&
386 (t_lc::toString(maxOutlierLC) == "l1" ||
387 t_lc::toString(maxOutlierLC) == "l2") ) {
388 _obsPool->setRefSatChangeRequired(sys, true);
389 }
390 else {
391 if (par) {
392 par->setAmbResetCandidate();
393 obs->setOutlier();
394 }
395 else {
396 obs->setOutlier();
397 }
398 }
399 }
400 else {// fin-processing
401 if (par) {
402 if (par->ambResetCandidate()) {
403 resetAmb(par->prn(), obsVector, &QSav, &xSav);
404 }
405 else {
406 par->setAmbResetCandidate();
407 obs->setOutlier();
408 }
409 }
410 else {
411 obs->setOutlier();
412 }
413 }
414 }
415 // Print Residuals
416 // ---------------
417 else {
418 if (!preProcessing) {
419 for (unsigned jj = 0; jj < LCs.size(); jj++) {
420 for (unsigned ii = 0; ii < usedObs.size(); ii++) {
421 const t_lc::type tLC = usedTypes[ii];
422 t_pppSatObs* obs = usedObs[ii];
423 if (tLC == LCs[jj]) {
424 obs->setRes(tLC, vv[ii]);
425 LOG << epoTimeStr << " RES "
426 << left << setw(3) << t_lc::toString(tLC) << right << ' ';
427 if (t_lc::toString(tLC) == "Tz0") {LOG << sys << " ";}
428 else {LOG << obs->prn().toString();}
429 LOG << setw(8) << setprecision(4) << vv[ii] << endl;
430 }
431 }
432 }
433 }
434 break;
435 }
436 }
437 return success;
438}
439
440// Cycle-Slip Detection
441////////////////////////////////////////////////////////////////////////////
442t_irc t_pppFilter::detectCycleSlips(const vector<t_lc::type>& LCs,
443 const vector<t_pppSatObs*>& obsVector,
444 const t_prn& refPrn,
445 bool preProcessing) {
446
447 const double SLIP = 20.0;
448 char sys = refPrn.system();
449 string epoTimeStr = string(_epoTime);
450 const vector<t_pppParam*>& params = _parlist->params();
451
452 for (unsigned ii = 0; ii < LCs.size(); ii++) {
453 const t_lc::type& tLC = LCs[ii];
454 if (t_lc::includesPhase(tLC)) {
455 for (unsigned iObs = 0; iObs < obsVector.size(); iObs++) {
456 const t_pppSatObs* obs = obsVector[iObs];
457
458 // Check set Slips and Jump Counters
459 // ---------------------------------
460 bool slip = false;
461
462 // in pre-processing only the reference satellite has to be checked
463 if (preProcessing && obs->prn() != refPrn) {
464 continue;
465 }
466
467 if (obs->slip()) {
468 LOG << epoTimeStr << "cycle slip set (obs) " << obs->prn().toString() << endl;
469 slip = true;
470 }
471
472 if (_slips[obs->prn()]._obsSlipCounter != -1 &&
473 _slips[obs->prn()]._obsSlipCounter != obs->slipCounter()) {
474 LOG << epoTimeStr << "cycle slip set (obsSlipCounter) " << obs->prn().toString() << endl;
475 slip = true;
476 }
477 if (!preProcessing) {
478 _slips[obs->prn()]._obsSlipCounter = obs->slipCounter();
479 }
480 if (_slips[obs->prn()]._biasJumpCounter != -1 &&
481 _slips[obs->prn()]._biasJumpCounter != obs->biasJumpCounter()) {
482 LOG << epoTimeStr << "cycle slip set (biasJumpCounter) " << obs->prn().toString() << endl;
483 slip = true;
484 }
485 if (!preProcessing) {
486 _slips[obs->prn()]._biasJumpCounter = obs->biasJumpCounter();
487 }
488 // Slip Set
489 // --------
490 if (slip) {
491 if (preProcessing) {
492 _obsPool->setRefSatChangeRequired(sys, true);
493 }
494 else {
495 resetAmb(obs->prn(), obsVector);
496 }
497 }
498 // Check Pre-Fit Residuals
499 // -----------------------
500 else {
501 ColumnVector AA(params.size());
502 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
503 const t_pppParam* par = params[iPar];
504 AA[iPar] = par->partial(_epoTime, obs, tLC, refPrn);
505 }
506 double ll = obs->obsValue(tLC) - obs->cmpValue(tLC) - DotProduct(_x0, AA);
507 double vv = DotProduct(AA, _xFlt) - ll;
508 if (fabs(vv) > SLIP) {
509 LOG << epoTimeStr << " cycle slip detected " << t_lc::toString(tLC) << ' '
510 << obs->prn().toString() << ' ' << setw(8) << setprecision(4) << vv << endl;
511 if (preProcessing) {
512 _obsPool->setRefSatChangeRequired(sys, true);
513 }
514 else {
515 resetAmb(obs->prn(), obsVector);
516 }
517 }
518 }
519 }
520 }
521 }
522 return success;
523}
524
525// Reset Ambiguity Parameter (cycle slip)
526////////////////////////////////////////////////////////////////////////////
527t_irc t_pppFilter::resetAmb(t_prn prn, const vector<t_pppSatObs*>& obsVector,
528 SymmetricMatrix* QSav, ColumnVector* xSav) {
529
530 t_irc irc = failure;
531 vector<t_pppParam*>& params = _parlist->params();
532 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
533 t_pppParam* par = params[iPar];
534 if (par->type() == t_pppParam::amb && par->prn() == prn) {
535 int ind = par->indexNew();
536 t_lc::type tLC = par->tLC();
537 LOG << string(_epoTime) << " RESET " << par->toString() << endl;
538 delete par; par = new t_pppParam(t_pppParam::amb, prn, tLC, &obsVector);
539 par->setIndex(ind);
540 params[iPar] = par;
541 for (unsigned ii = 1; ii <= params.size(); ii++) {
542 _QFlt(ii, ind+1) = 0.0;
543 if (QSav) {
544 (*QSav)(ii, ind+1) = 0.0;
545 }
546 }
547 _QFlt(ind+1,ind+1) = par->sigma0() * par->sigma0();
548 if (QSav) {
549 (*QSav)(ind+1,ind+1) = _QFlt(ind+1,ind+1);
550 }
551 _xFlt[ind] = 0.0;
552 if (xSav) {
553 (*xSav)[ind] = _xFlt[ind];
554 }
555 _x0[ind] = par->x0();
556 irc = success;
557 }
558 }
559
560 return irc;
561}
562
563// Add innfinite noise to iono
564////////////////////////////////////////////////////////////////////////////
565t_irc t_pppFilter::addNoiseToIono(char sys) {
566
567 t_irc irc = failure;
568 vector<t_pppParam*>& params = _parlist->params();
569 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
570 t_pppParam* par = params[iPar];
571 if (par->type() == t_pppParam::ion && par->prn().system() == sys) {
572 int ind = par->indexNew();
573 LOG << string(_epoTime) << " ADD IONO_NOISE TO " << par->prn().toString() << endl;
574 par->setIndex(ind);
575 _QFlt(ind+1,ind+1) += par->sigma0() * par->sigma0();
576 irc = success;
577 }
578 }
579
580 return irc;
581}
582
583// Compute various DOP Values
584////////////////////////////////////////////////////////////////////////////
585void t_pppFilter::cmpDOP(const vector<t_pppSatObs*>& obsVector) {
586
587 _dop.reset();
588
589 try {
590 const unsigned numPar = 4;
591 Matrix AA(obsVector.size(), numPar);
592 _numSat = 0;
593 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
594 t_pppSatObs* obs = obsVector[ii];
595 char system = obs->prn().system();
596 t_prn refPrn = t_prn();
597 if (OPT->_refSatRequired) {
598 refPrn = _obsPool->getRefSatMapElement(system)->prn();
599 }
600 if (obs->isValid() && !obs->outlier()) {
601 ++_numSat;
602 for (unsigned iPar = 0; iPar < numPar; iPar++) {
603 const t_pppParam* par = _parlist->params()[iPar];
604 AA[_numSat-1][iPar] = par->partial(_epoTime, obs, t_lc::c1, refPrn);
605 }
606 }
607 }
608 if (_numSat < 4) {
609 return;
610 }
611 AA = AA.Rows(1, _numSat);
612 SymmetricMatrix NN; NN << AA.t() * AA;
613 SymmetricMatrix QQ = NN.i();
614
615 _dop.H = sqrt(QQ(1,1) + QQ(2,2));
616 _dop.V = sqrt(QQ(3,3));
617 _dop.P = sqrt(QQ(1,1) + QQ(2,2) + QQ(3,3));
618 _dop.T = sqrt(QQ(4,4));
619 _dop.G = sqrt(QQ(1,1) + QQ(2,2) + QQ(3,3) + QQ(4,4));
620 }
621 catch (...) {
622 }
623}
624
625// Compute various DOP Values
626////////////////////////////////////////////////////////////////////////////
627void t_pppFilter::predictCovCrdPart(const SymmetricMatrix& QFltOld) {
628
629 const vector<t_pppParam*>& params = _parlist->params();
630 if (params.size() < 3) {
631 return;
632 }
633
634 bool first = (params[0]->indexOld() < 0);
635
636 SymmetricMatrix Qneu(3); Qneu = 0.0;
637 for (unsigned ii = 0; ii < 3; ii++) {
638 const t_pppParam* par = params[ii];
639 if (first) {
640 Qneu[ii][ii] = par->sigma0() * par->sigma0();
641 }
642 else {
643 Qneu[ii][ii] = par->noise() * par->noise();
644 }
645 }
646
647 const t_pppStation* sta = PPP_CLIENT->staRover();
648 SymmetricMatrix Qxyz(3);
649 covariNEU_XYZ(Qneu, sta->ellApr().data(), Qxyz);
650
651 if (first) {
652 _QFlt.SymSubMatrix(1,3) = Qxyz;
653 }
654 else {
655 double dt = _epoTime - _firstEpoTime;
656 if (dt < OPT->_seedingTime) {
657 _QFlt.SymSubMatrix(1,3) = QFltOld.SymSubMatrix(1,3);
658 }
659 else {
660 _QFlt.SymSubMatrix(1,3) = QFltOld.SymSubMatrix(1,3) + Qxyz;
661 }
662 }
663}
664
665// Compute datum transformation
666////////////////////////////////////////////////////////////////////////////
667t_irc t_pppFilter::datumTransformation() {
668 t_pppObsPool::t_epoch* epoch = _obsPool->lastEpoch();
669 if (!epoch) {LOG << "!epoch" << endl;
670 return failure;
671 }
672 else {
673 LOG.setf(ios::fixed);
674 LOG << string(epoch->epoTime()) << " DATUM TRANSFORMATION " << endl;
675 }
676 vector<t_pppSatObs*>& allObs = epoch->obsVector();
677
678 // reset old and set new refSats in last epoch (ambiguities)
679 // ========================================================
680 if (resetRefSatellitesLastEpoch(allObs) != true) {
681 return failure;
682 }
683
684 // set AA2
685 // =======
686 _parlist->set(epoch->epoTime(), allObs, _obsPool->getRefSatMap());
687 const vector<t_pppParam*>& params = _parlist->params();
688#ifdef BNC_DEBUG_PPP
689 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
690 LOG << params[iPar]->toString() << "\t\t" << endl;
691 }
692#endif
693 for (unsigned iSys = 0; iSys < OPT->systems().size(); iSys++) {
694 (iSys) ? _datumTrafo->setFirstSystem(false) : _datumTrafo->setFirstSystem(true);
695 char sys = OPT->systems()[iSys];
696 t_prn refPrn = (_obsPool->getRefSatMapElement(sys))->prn();
697#ifdef BNC_DEBUG_PPP
698 LOG << "refPrn: " << refPrn.toString() << endl;
699#endif
700 vector<t_pppSatObs*> obsVector;
701 for (unsigned jj = 0; jj < allObs.size(); jj++) {
702 if (allObs[jj]->prn().system() == sys) {
703 obsVector.push_back(allObs[jj]);
704 }
705 }
706
707 vector<t_lc::type> LCs = OPT->LCs(sys);
708 unsigned usedLCs = LCs.size();
709 unsigned realUsedLCs = usedLCs;
710 if (OPT->_pseudoObsIono && !epoch->pseudoObsIono()) {
711 usedLCs -= 1; // GIM not used
712 }
713 int hlpLCs = 0;
714 if (OPT->_pseudoObsTropo) {
715 hlpLCs = -1;
716 realUsedLCs -= 1;
717 }
718 // max Obs
719 unsigned maxObs = obsVector.size() * (usedLCs + hlpLCs);
720 if (OPT->_pseudoObsTropo) {
721 maxObs += 1;
722 }
723 if (OPT->_pseudoObsIono && epoch->pseudoObsIono()) {
724 maxObs -= 1; // pseudo obs iono with respect to refSat
725 }
726
727 Matrix AA(maxObs, _parlist->nPar());
728
729 // Real Observations
730 // -----------------
731 int iObs = -1;
732 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
733 t_pppSatObs* obs = obsVector[ii];
734 if (!obs->outlier()) {
735 for (unsigned jj = 0; jj < usedLCs; jj++) {
736 const t_lc::type tLC = LCs[jj];
737 if (tLC == t_lc::GIM) {continue;}
738 if (tLC == t_lc::Tz0) {continue;}
739 ++iObs;
740 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
741 const t_pppParam* par = params[iPar];
742 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
743 }
744 }
745 }
746 }
747 _datumTrafo->updateIndices(iObs+1);
748 _datumTrafo->prepareAA(AA.SubMatrix(1, iObs+1 , 1, _parlist->nPar()), 2);
749 }
750
751 // Datum Transformation
752 // ====================
753#ifdef BNC_DEBUG_PPP
754 LOG << "AA1\n"; _datumTrafo->printMatrix(_datumTrafo->AA1(), _datumTrafo->obsNum(), _datumTrafo->parNum());
755 LOG << "AA2\n"; _datumTrafo->printMatrix(_datumTrafo->AA2(), _datumTrafo->obsNum(), _datumTrafo->parNum());
756#endif
757 Matrix D21 = _datumTrafo->computeTrafoMatrix();
758#ifdef BNC_DEBUG_PPP
759 LOG << "D21" << endl; _datumTrafo->printMatrix(D21, _datumTrafo->parNum(), _datumTrafo->parNum());
760#endif
761 ColumnVector xFltOld = _xFlt;
762 SymmetricMatrix QFltOld = _QFlt;
763
764 _QFlt << D21 * QFltOld * D21.t();
765 _xFlt = D21 * xFltOld;
766
767#ifdef BNC_DEBUG_PPP
768 LOG << "xFltOld:\n" << xFltOld << endl;
769 LOG << "xFlt :\n" << _xFlt << endl;
770#endif
771
772 // Reset Ambiguities after Datum Transformation
773 // ============================================
774 for (unsigned iSys = 0; iSys < OPT->systems().size(); iSys++) {
775 char sys = OPT->systems()[iSys];
776 t_irc irc = resetAmb(_obsPool->getRefSatMapElementLastEpoch(sys), allObs);
777 if (OPT->_obsModelType == OPT->DCMcodeBias) {
778 if (irc == success) {
779 addNoiseToIono(sys);}
780 }
781 }
782
783 // switch AA2 to AA1
784 // =================
785 _datumTrafo->switchAA();
786
787 return success;
788}
789
790// Init datum transformation
791////////////////////////////////////////////////////////////////////////////
792void t_pppFilter::initDatumTransformation(const std::vector<t_pppSatObs*>& allObs) {
793 unsigned realObs = 0;
794 for (unsigned iSys = 0; iSys < OPT->systems().size(); iSys++) {
795 char system = OPT->systems()[iSys];
796 int satNum = 0;
797 for (unsigned jj = 0; jj < allObs.size(); jj++) {
798 if (allObs[jj]->prn().system() == system) {
799 satNum++;
800 }
801 }
802 // all LCs
803 unsigned realUsedLCs = OPT->LCs(system).size();
804 // exclude pseudo obs GIM
805 if (OPT->_pseudoObsIono) {
806 realUsedLCs -= 1;
807 }
808 if (OPT->_pseudoObsTropo) {
809 realUsedLCs -= 1;
810 }
811 realObs += satNum * realUsedLCs;
812 }
813 _datumTrafo->setObsNum(realObs);
814 _datumTrafo->setParNum(_parlist->nPar());
815 _datumTrafo->initAA();
816}
817
818//
819//////////////////////////////////////////////////////////////////////////////
820bool t_pppFilter::resetRefSatellitesLastEpoch(std::vector<t_pppSatObs*>& obsVector) {
821
822 bool resetRefSat = false;
823 // reference satellite definition per system
824 for (unsigned iSys = 0; iSys < OPT->systems().size(); iSys++) {
825 char sys = OPT->systems()[iSys];
826 t_pppRefSat* refSat = _obsPool->getRefSatMapElement(sys);
827 t_prn newPrn = refSat->prn();
828 t_prn oldPrn = _obsPool->getRefSatMapElementLastEpoch(sys);
829#ifdef BNC_DEBUG_PPP
830 LOG << "oldPrn: " << oldPrn.toString() << " => newPrn: " << newPrn.toString() << endl;
831#endif
832 vector<t_pppSatObs*>::iterator it = obsVector.begin();
833 while (it != obsVector.end()) {
834 t_pppSatObs* satObs = *it;
835 if (satObs->prn() == newPrn) {
836 resetRefSat = true;
837 satObs->setAsReference();
838 }
839 else if (satObs->prn() == oldPrn) {
840 satObs->resetReference();
841 }
842 it++;
843 }
844 }
845 return resetRefSat;
846}
Note: See TracBrowser for help on using the repository browser.