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

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