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

Last change on this file since 9578 was 9577, checked in by stuerze, 2 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: 27.5 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
[9556]264 // Check number of observations
265 // ----------------------------
266 if (iObs == -1) {LOG << "iObs == -1\n";
267 return failure;
268 }
269
[9386]270 if ((!iOutlier) &&
271 (OPT->_obsModelType == OPT->DCMcodeBias ||
[9419]272 OPT->_obsModelType == OPT->DCMphaseBias) &&
273 (!preProcessing)) {
274 _datumTrafo->updateIndices(sys, iObs+1);
[9504]275 _datumTrafo->prepareAA(AA.SubMatrix(1, iObs+1 , 1, _parlist.nPar()), 1);
[9386]276 }
277
278 // Pseudo Obs Iono
279 // ================
280 if (OPT->_pseudoObsIono && pseudoObsIonoAvailable) {
281 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
282 t_pppSatObs* obs = obsVector[ii];
283 if (!obs->outlier()) {
284 for (unsigned jj = 0; jj < usedLCs; jj++) {
285 const t_lc::type tLC = LCs[jj];
286 if (tLC == t_lc::GIM && !obs->isReference()) {
287 ++iObs;
288 } else {continue;}
289 usedObs.push_back(obs);
290 usedTypes.push_back(tLC);
[9524]291 for (unsigned iPar = 0; iPar < nPar; iPar++) {
[9386]292 const t_pppParam* par = params[iPar];
293 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
294 }
295 ll[iObs] = obs->obsValue(tLC) - obs->cmpValue(tLC) - DotProduct(_x0, AA.Row(iObs+1));
296 PP[iObs] = 1.0 / (obs->sigma(tLC) * obs->sigma(tLC));
297 }
298 }
[8956]299 }
[8915]300 }
301
[9556]302 // Truncate matrices
303 // -----------------
[7237]304 AA = AA.Rows(1, iObs+1);
305 ll = ll.Rows(1, iObs+1);
306 PP = PP.SymSubMatrix(1, iObs+1);
307
308 // Kalman update step
309 // ------------------
310 kalman(AA, ll, PP, _QFlt, _xFlt);
311
312 // Check Residuals
313 // ---------------
314 ColumnVector vv = AA * _xFlt - ll;
315 double maxOutlier = 0.0;
316 int maxOutlierIndex = -1;
317 t_lc::type maxOutlierLC = t_lc::dummy;
318 for (unsigned ii = 0; ii < usedObs.size(); ii++) {
319 const t_lc::type tLC = usedTypes[ii];
320 double res = fabs(vv[ii]);
321 if (res > usedObs[ii]->maxRes(tLC)) {
322 if (res > fabs(maxOutlier)) {
323 maxOutlier = vv[ii];
324 maxOutlierIndex = ii;
325 maxOutlierLC = tLC;
326 }
327 }
328 }
329
330 // Mark outlier or break outlier detection loop
331 // --------------------------------------------
332 if (maxOutlierIndex > -1) {
333 t_pppSatObs* obs = usedObs[maxOutlierIndex];
334 t_pppParam* par = 0;
[9524]335 for (unsigned iPar = 0; iPar < nPar; iPar++) {
[7237]336 t_pppParam* hlp = params[iPar];
[8905]337 if (hlp->type() == t_pppParam::amb &&
338 hlp->prn() == obs->prn() &&
[7237]339 hlp->tLC() == usedTypes[maxOutlierIndex]) {
340 par = hlp;
341 }
342 }
[8956]343 if (preProcessing) {
[9491]344 // for refSats no ambiguity parameter exists
[9386]345 if ((obs->prn() == refPrn) &&
346 (t_lc::toString(maxOutlierLC) == "l1" ||
347 t_lc::toString(maxOutlierLC) == "l2") ) {
348 _obsPool->setRefSatChangeRequired(sys, true);
[9556]349 LOG << epoTimeStr << " Outlier ("
350 << ((preProcessing) ? "pre-processing) " : "fin-processing) ") << t_lc::toString(maxOutlierLC) << ' '
351 << obs->prn().toString() << ' ' << setw(8) << setprecision(4) << maxOutlier << endl;
[9491]352 break;
[9386]353 }
354 else {
355 if (par) {
[9577]356 par->setAmbResetCandidate();
[9562]357 obs->setOutlier();
[9386]358 }
[9562]359 else {
360 obs->setOutlier();
361 }
[8905]362 }
363 }
[9386]364 else {// fin-processing
[9556]365 LOG << epoTimeStr << " Outlier " << t_lc::toString(maxOutlierLC) << ' '
366 << obs->prn().toString() << ' ' << setw(8) << setprecision(4) << maxOutlier << endl;
[8956]367 if (par) {
[9577]368 if (par->ambResetCandidate()) {
[8956]369 resetAmb(par->prn(), obsVector, &QSav, &xSav);
[9577]370 }
371 else {
372 par->setAmbResetCandidate();
373 obs->setOutlier();
374 }
[7237]375 }
376 else {
377 obs->setOutlier();
378 }
379 }
380 }
381 // Print Residuals
382 // ---------------
383 else {
[8905]384 if (!preProcessing) {
385 for (unsigned jj = 0; jj < LCs.size(); jj++) {
386 for (unsigned ii = 0; ii < usedObs.size(); ii++) {
387 const t_lc::type tLC = usedTypes[ii];
[9386]388 t_pppSatObs* obs = usedObs[ii];
[8905]389 if (tLC == LCs[jj]) {
390 obs->setRes(tLC, vv[ii]);
391 LOG << epoTimeStr << " RES "
[9386]392 << left << setw(3) << t_lc::toString(tLC) << right << ' ';
393 if (t_lc::toString(tLC) == "Tz0") {LOG << sys << " ";}
394 else {LOG << obs->prn().toString();}
[9435]395 LOG << setw(9) << setprecision(4) << vv[ii] << endl;
[8905]396 }
[7237]397 }
398 }
399 }
400 break;
401 }
402 }
403 return success;
404}
405
406// Cycle-Slip Detection
407////////////////////////////////////////////////////////////////////////////
[7267]408t_irc t_pppFilter::detectCycleSlips(const vector<t_lc::type>& LCs,
[8905]409 const vector<t_pppSatObs*>& obsVector,
410 const t_prn& refPrn,
411 bool preProcessing) {
[9386]412 const double SLIP = 20.0;
413 char sys = refPrn.system();
414 string epoTimeStr = string(_epoTime);
[9504]415 const vector<t_pppParam*>& params = _parlist.params();
[9524]416 unsigned nPar = _parlist.nPar();
[7237]417
418 for (unsigned ii = 0; ii < LCs.size(); ii++) {
419 const t_lc::type& tLC = LCs[ii];
420 if (t_lc::includesPhase(tLC)) {
421 for (unsigned iObs = 0; iObs < obsVector.size(); iObs++) {
422 const t_pppSatObs* obs = obsVector[iObs];
423
[7267]424 // Check set Slips and Jump Counters
[7237]425 // ---------------------------------
426 bool slip = false;
[9386]427
428 // in pre-processing only the reference satellite has to be checked
429 if (preProcessing && obs->prn() != refPrn) {
430 continue;
431 }
432
[7237]433 if (obs->slip()) {
[8329]434 LOG << epoTimeStr << "cycle slip set (obs) " << obs->prn().toString() << endl;
[7237]435 slip = true;
436 }
437
438 if (_slips[obs->prn()]._obsSlipCounter != -1 &&
[9088]439 _slips[obs->prn()]._obsSlipCounter != obs->slipCounter()) {
[8329]440 LOG << epoTimeStr << "cycle slip set (obsSlipCounter) " << obs->prn().toString() << endl;
[7237]441 slip = true;
442 }
[8956]443 if (!preProcessing) {
444 _slips[obs->prn()]._obsSlipCounter = obs->slipCounter();
445 }
[7237]446 if (_slips[obs->prn()]._biasJumpCounter != -1 &&
447 _slips[obs->prn()]._biasJumpCounter != obs->biasJumpCounter()) {
[8329]448 LOG << epoTimeStr << "cycle slip set (biasJumpCounter) " << obs->prn().toString() << endl;
[7237]449 slip = true;
450 }
[8956]451 if (!preProcessing) {
452 _slips[obs->prn()]._biasJumpCounter = obs->biasJumpCounter();
453 }
[7237]454 // Slip Set
[7267]455 // --------
[7237]456 if (slip) {
[8905]457 if (preProcessing) {
[9386]458 _obsPool->setRefSatChangeRequired(sys, true);
[8905]459 }
460 else {
461 resetAmb(obs->prn(), obsVector);
462 }
[7237]463 }
464 // Check Pre-Fit Residuals
465 // -----------------------
466 else {
[9419]467 if (refPrn != t_prn()) {return success;}
[9524]468 ColumnVector AA(nPar);
469 for (unsigned iPar = 0; iPar < nPar; iPar++) {
[7237]470 const t_pppParam* par = params[iPar];
[8956]471 AA[iPar] = par->partial(_epoTime, obs, tLC, refPrn);
[7237]472 }
473 double ll = obs->obsValue(tLC) - obs->cmpValue(tLC) - DotProduct(_x0, AA);
474 double vv = DotProduct(AA, _xFlt) - ll;
475 if (fabs(vv) > SLIP) {
[9386]476 LOG << epoTimeStr << " cycle slip detected " << t_lc::toString(tLC) << ' '
477 << obs->prn().toString() << ' ' << setw(8) << setprecision(4) << vv << endl;
[8905]478 if (preProcessing) {
[9386]479 _obsPool->setRefSatChangeRequired(sys, true);
[8905]480 }
481 else {
482 resetAmb(obs->prn(), obsVector);
483 }
[7237]484 }
485 }
486 }
487 }
488 }
489 return success;
490}
491
492// Reset Ambiguity Parameter (cycle slip)
493////////////////////////////////////////////////////////////////////////////
494t_irc t_pppFilter::resetAmb(t_prn prn, const vector<t_pppSatObs*>& obsVector,
495 SymmetricMatrix* QSav, ColumnVector* xSav) {
[8965]496
[7237]497 t_irc irc = failure;
[9504]498 vector<t_pppParam*>& params = _parlist.params();
[7237]499 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
500 t_pppParam* par = params[iPar];
501 if (par->type() == t_pppParam::amb && par->prn() == prn) {
502 int ind = par->indexNew();
503 t_lc::type tLC = par->tLC();
504 LOG << string(_epoTime) << " RESET " << par->toString() << endl;
505 delete par; par = new t_pppParam(t_pppParam::amb, prn, tLC, &obsVector);
506 par->setIndex(ind);
507 params[iPar] = par;
508 for (unsigned ii = 1; ii <= params.size(); ii++) {
509 _QFlt(ii, ind+1) = 0.0;
510 if (QSav) {
511 (*QSav)(ii, ind+1) = 0.0;
512 }
513 }
514 _QFlt(ind+1,ind+1) = par->sigma0() * par->sigma0();
515 if (QSav) {
516 (*QSav)(ind+1,ind+1) = _QFlt(ind+1,ind+1);
517 }
518 _xFlt[ind] = 0.0;
519 if (xSav) {
520 (*xSav)[ind] = _xFlt[ind];
521 }
522 _x0[ind] = par->x0();
523 irc = success;
524 }
525 }
526
527 return irc;
528}
529
[9395]530// Add infinite noise to iono
[9386]531////////////////////////////////////////////////////////////////////////////
532t_irc t_pppFilter::addNoiseToIono(char sys) {
533
534 t_irc irc = failure;
[9504]535 vector<t_pppParam*>& params = _parlist.params();
[9386]536 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
537 t_pppParam* par = params[iPar];
538 if (par->type() == t_pppParam::ion && par->prn().system() == sys) {
539 int ind = par->indexNew();
540 LOG << string(_epoTime) << " ADD IONO_NOISE TO " << par->prn().toString() << endl;
541 par->setIndex(ind);
542 _QFlt(ind+1,ind+1) += par->sigma0() * par->sigma0();
543 irc = success;
544 }
545 }
546
547 return irc;
548}
549
[7237]550// Compute various DOP Values
551////////////////////////////////////////////////////////////////////////////
[9521]552void t_pppFilter::cmpDOP(const vector<t_pppSatObs*>& obsVector,
[9508]553 const QMap<char, t_pppRefSat*>& refSatMap) {
[7237]554
555 _dop.reset();
556
557 try {
558 const unsigned numPar = 4;
559 Matrix AA(obsVector.size(), numPar);
560 _numSat = 0;
561 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
562 t_pppSatObs* obs = obsVector[ii];
[9508]563 char sys = obs->prn().system();
[8956]564 t_prn refPrn = t_prn();
565 if (OPT->_refSatRequired) {
[9508]566 refPrn = refSatMap[sys]->prn();
[8956]567 }
[7237]568 if (obs->isValid() && !obs->outlier()) {
569 ++_numSat;
570 for (unsigned iPar = 0; iPar < numPar; iPar++) {
[9504]571 const t_pppParam* par = _parlist.params()[iPar];
[8956]572 AA[_numSat-1][iPar] = par->partial(_epoTime, obs, t_lc::c1, refPrn);
[7237]573 }
574 }
575 }
576 if (_numSat < 4) {
577 return;
578 }
579 AA = AA.Rows(1, _numSat);
[7267]580 SymmetricMatrix NN; NN << AA.t() * AA;
[7237]581 SymmetricMatrix QQ = NN.i();
[7267]582
[7928]583 _dop.H = sqrt(QQ(1,1) + QQ(2,2));
584 _dop.V = sqrt(QQ(3,3));
[7237]585 _dop.P = sqrt(QQ(1,1) + QQ(2,2) + QQ(3,3));
586 _dop.T = sqrt(QQ(4,4));
587 _dop.G = sqrt(QQ(1,1) + QQ(2,2) + QQ(3,3) + QQ(4,4));
588 }
589 catch (...) {
590 }
591}
592
[9526]593//
[7237]594////////////////////////////////////////////////////////////////////////////
595void t_pppFilter::predictCovCrdPart(const SymmetricMatrix& QFltOld) {
596
[9504]597 const vector<t_pppParam*>& params = _parlist.params();
[7237]598 if (params.size() < 3) {
599 return;
600 }
601
602 bool first = (params[0]->indexOld() < 0);
603
604 SymmetricMatrix Qneu(3); Qneu = 0.0;
605 for (unsigned ii = 0; ii < 3; ii++) {
606 const t_pppParam* par = params[ii];
607 if (first) {
608 Qneu[ii][ii] = par->sigma0() * par->sigma0();
609 }
610 else {
611 Qneu[ii][ii] = par->noise() * par->noise();
612 }
613 }
614
615 const t_pppStation* sta = PPP_CLIENT->staRover();
616 SymmetricMatrix Qxyz(3);
617 covariNEU_XYZ(Qneu, sta->ellApr().data(), Qxyz);
618
619 if (first) {
620 _QFlt.SymSubMatrix(1,3) = Qxyz;
621 }
622 else {
623 double dt = _epoTime - _firstEpoTime;
624 if (dt < OPT->_seedingTime) {
625 _QFlt.SymSubMatrix(1,3) = QFltOld.SymSubMatrix(1,3);
626 }
627 else {
628 _QFlt.SymSubMatrix(1,3) = QFltOld.SymSubMatrix(1,3) + Qxyz;
629 }
630 }
631}
[8912]632
[9526]633//
634////////////////////////////////////////////////////////////////////////////
635void t_pppFilter::setStateVectorAndVarCovMatrix(const ColumnVector& xFltOld,
636 const SymmetricMatrix& QFltOld) {
637
638 const vector<t_pppParam*>& params = _parlist.params();
639 unsigned nPar = params.size();
640
641 _QFlt.ReSize(nPar); _QFlt = 0.0;
642 _xFlt.ReSize(nPar); _xFlt = 0.0;
643 _x0.ReSize(nPar); _x0 = 0.0;
644
645 for (unsigned ii = 0; ii < nPar; ii++) {
646 t_pppParam* par1 = params[ii];
647 if (QFltOld.size() == 0) {
648 par1->resetIndex();
649 }
650 _x0[ii] = par1->x0();
651 int iOld = par1->indexOld();
652 if (iOld < 0) {
653 _QFlt[ii][ii] = par1->sigma0() * par1->sigma0(); // new parameter
654 }
655 else {
656 _QFlt[ii][ii] = QFltOld[iOld][iOld] + par1->noise() * par1->noise();
657 _xFlt[ii] = xFltOld[iOld];
658 for (unsigned jj = 0; jj < ii; jj++) {
659 t_pppParam* par2 = params[jj];
660 int jOld = par2->indexOld();
661 if (jOld >= 0) {
662 _QFlt[ii][jj] = QFltOld(iOld+1,jOld+1);
663 }
664 }
665 }
666 }
667 predictCovCrdPart(QFltOld);
668}
669
[8915]670// Compute datum transformation
[8912]671////////////////////////////////////////////////////////////////////////////
[9508]672t_irc t_pppFilter::datumTransformation(const QMap<char, t_pppRefSat*>& refSatMap) {
673
[9419]674 // get last epoch
[9386]675 t_pppObsPool::t_epoch* epoch = _obsPool->lastEpoch();
[9419]676 if (!epoch) {
[9508]677 LOG << "t_pppFilter::datumTransformation: !lastEpoch" << endl;
[9386]678 return failure;
679 }
[9508]680 _epoTime = epoch->epoTime();
681 LOG.setf(ios::fixed);
682 LOG << string(_epoTime) << " DATUM TRANSFORMATION " << endl;
[9419]683
[9386]684 vector<t_pppSatObs*>& allObs = epoch->obsVector();
685
[9508]686 const QMap<char, t_pppRefSat*>& refSatMapLastEpoch = epoch->refSatMap();
687
[9548]688 bool pseudoObsIono = epoch->pseudoObsIono();
[9508]689
[9419]690 // reset old and set new refSats in last epoch (ambiguities/GIM)
691 // =============================================================
[9508]692 if (resetRefSatellitesLastEpoch(allObs, refSatMap, refSatMapLastEpoch) != true) {
[9548]693 LOG << "datumTransformation: resetRefSatellitesLastEpoch != success" << endl;
694 return failure;
[9386]695 }
696
[9419]697 if (OPT->_obsModelType == OPT->UncombPPP) {
[9548]698 _obsPool->putEpoch(_epoTime, allObs, pseudoObsIono, refSatMap);
[9419]699 return success;
700 }
[9537]701 //LOG << "datumTransformation: printParams before set" << endl;
702 //_parlist.printParams(_epoTime);
[9419]703
[9386]704 // set AA2
705 // =======
[9508]706 if (_parlist.set(_epoTime, allObs, refSatMap) != success) {
[9419]707 return failure;
708 }
[9526]709
[9386]710#ifdef BNC_DEBUG_PPP
[9534]711 _parlist.printParams(_epoTime);
[9386]712#endif
[9526]713
[9504]714 const QList<char>& usedSystems = _parlist.usedSystems();
[9431]715 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
716 char sys = usedSystems[iSys];
[9508]717 t_prn refPrn = refSatMap[sys]->prn();
[9386]718 vector<t_pppSatObs*> obsVector;
719 for (unsigned jj = 0; jj < allObs.size(); jj++) {
720 if (allObs[jj]->prn().system() == sys) {
721 obsVector.push_back(allObs[jj]);
722 }
723 }
[9431]724 if (iSys == 0) {
725 _datumTrafo->setFirstSystem(sys);
[9419]726 }
[9386]727 vector<t_lc::type> LCs = OPT->LCs(sys);
728 unsigned usedLCs = LCs.size();
[9548]729 if (OPT->_pseudoObsIono && !pseudoObsIono) {
[9386]730 usedLCs -= 1; // GIM not used
731 }
732 // max Obs
[9538]733 unsigned maxObs = obsVector.size() * usedLCs;
[9419]734
[9548]735 if (OPT->_pseudoObsIono && pseudoObsIono) {
[9386]736 maxObs -= 1; // pseudo obs iono with respect to refSat
737 }
[9526]738
739 const vector<t_pppParam*>& params = _parlist.params();
740 unsigned nPar = _parlist.nPar();
741
[9419]742 Matrix AA(maxObs, nPar);
[9524]743
[9386]744 // Real Observations
745 // -----------------
746 int iObs = -1;
747 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
748 t_pppSatObs* obs = obsVector[ii];
[9419]749 for (unsigned jj = 0; jj < usedLCs; jj++) {
750 const t_lc::type tLC = LCs[jj];
751 if (tLC == t_lc::GIM) {continue;}
752 ++iObs;
[9524]753 for (unsigned iPar = 0; iPar < nPar; iPar++) {
754 const t_pppParam* par = params[iPar];
[9419]755 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
[9386]756 }
757 }
758 }
[9538]759
[9419]760 if (!iObs) {
761 continue;
762 }
[9508]763 _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;
764 if(_datumTrafo->prepareAA(AA.SubMatrix(1, iObs+1 , 1, nPar), 2) != success) {
765 return failure;
766 }
[9386]767 }
[9419]768 _datumTrafo->updateNumObs();
[9386]769
770 // Datum Transformation
771 // ====================
772#ifdef BNC_DEBUG_PPP
[9548]773 //LOG << "AA1\n"; _datumTrafo->printMatrix(_datumTrafo->AA1(), _datumTrafo->numObs(), _datumTrafo->numPar());
774 //LOG << "AA2\n"; _datumTrafo->printMatrix(_datumTrafo->AA2(), _datumTrafo->numObs(), _datumTrafo->numPar());
[9386]775#endif
[9419]776 if(_datumTrafo->computeTrafoMatrix() != success) {
777 return failure;
778 }
[9386]779#ifdef BNC_DEBUG_PPP
[9548]780 //LOG << "D21" << endl; _datumTrafo->printMatrix(_datumTrafo->D21(), _datumTrafo->numObs(), _datumTrafo->numPar());
[9386]781#endif
782 ColumnVector xFltOld = _xFlt;
783 SymmetricMatrix QFltOld = _QFlt;
784
[9419]785 _QFlt << _datumTrafo->D21() * QFltOld * _datumTrafo->D21().t();
786 _xFlt = _datumTrafo->D21() * xFltOld;
[9386]787
[9562]788//#ifdef BNC_DEBUG_PPP
789 LOG << "xFltOld:\n" << xFltOld << endl;
790 LOG << "xFlt :\n" << _xFlt << endl;
791//#endif
[9386]792
793 // Reset Ambiguities after Datum Transformation
794 // ============================================
[9431]795 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
796 char sys = usedSystems[iSys];
[9508]797 t_prn refPrnOld = refSatMapLastEpoch[sys]->prn();
798 t_prn refPrnNew = refSatMap[sys]->prn();
[9419]799 if (refPrnNew != refPrnOld) {
[9508]800 t_irc irc = resetAmb(refPrnOld, allObs);
[9419]801 if (OPT->_obsModelType == OPT->DCMcodeBias) {
802 if (irc == success) {
803 addNoiseToIono(sys);
804 }
805 }
[9386]806 }
807 }
808
809 // switch AA2 to AA1
810 // =================
811 _datumTrafo->switchAA();
812
[9548]813 _obsPool->putEpoch(_epoTime, allObs, pseudoObsIono, refSatMap);
[9508]814
[9386]815 return success;
[8912]816}
817
[9386]818// Init datum transformation
[8956]819////////////////////////////////////////////////////////////////////////////
[9419]820void t_pppFilter::initDatumTransformation(const std::vector<t_pppSatObs*>& allObs,
821 bool pseudoObsIono) {
[9395]822 unsigned trafoObs = 0;
[9504]823 const QList<char>& usedSystems = _parlist. usedSystems();
[9431]824 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
825 char sys = usedSystems[iSys];
[9386]826 int satNum = 0;
827 for (unsigned jj = 0; jj < allObs.size(); jj++) {
[9419]828 if (allObs[jj]->prn().system() == sys) {
[9386]829 satNum++;
[8956]830 }
831 }
[9386]832 // all LCs
[9419]833 unsigned realUsedLCs = OPT->LCs(sys).size();
[9386]834 // exclude pseudo obs GIM
[9419]835 if (OPT->_pseudoObsIono && !pseudoObsIono) {
[9386]836 realUsedLCs -= 1;
837 }
[9538]838
[9395]839 trafoObs += satNum * realUsedLCs;
840
[9419]841 if (OPT->_pseudoObsIono && pseudoObsIono) {
842 trafoObs -= 1; // pseudo obs iono with respect to refSat
843 }
[8956]844 }
[9419]845 _datumTrafo->setNumObs(trafoObs);
[9504]846 _datumTrafo->setNumPar(_parlist.nPar());
[9386]847 _datumTrafo->initAA();
[8956]848}
[9386]849
850//
851//////////////////////////////////////////////////////////////////////////////
[9508]852bool t_pppFilter::resetRefSatellitesLastEpoch(std::vector<t_pppSatObs*>& obsVector,
853 const QMap<char, t_pppRefSat*>& refSatMap,
854 const QMap<char, t_pppRefSat*>& refSatMapLastEpoch) {
[9431]855 bool resetRefSat;
[9386]856 // reference satellite definition per system
[9504]857 const QList<char>& usedSystems = _parlist.usedSystems();
[9431]858 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
859 resetRefSat = false;
860 char sys = usedSystems[iSys];
[9508]861 t_prn newPrn = refSatMap[sys]->prn();
862 t_prn oldPrn = refSatMapLastEpoch[sys]->prn();
[9386]863#ifdef BNC_DEBUG_PPP
[9508]864 if (oldPrn != newPrn) {
865 LOG << "oldRef: " << oldPrn.toString() << " => newRef " << newPrn.toString() << endl;
866 }
[9386]867#endif
868 vector<t_pppSatObs*>::iterator it = obsVector.begin();
869 while (it != obsVector.end()) {
870 t_pppSatObs* satObs = *it;
871 if (satObs->prn() == newPrn) {
872 resetRefSat = true;
873 satObs->setAsReference();
[9508]874 } else if (satObs->prn() == oldPrn) {
[9386]875 satObs->resetReference();
876 }
877 it++;
878 }
[9431]879 if (!resetRefSat) {
880 _obsPool->setRefSatChangeRequired(sys, true);
881 return resetRefSat;
882 }
[9386]883 }
884 return resetRefSat;
885}
Note: See TracBrowser for help on using the repository browser.