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

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