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

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