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

Last change on this file since 9521 was 9521, 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: 29.2 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();
75
[9504]76 if (OPT->_obsModelType == OPT->DCMcodeBias ||
77 OPT->_obsModelType == OPT->DCMphaseBias) {
78 // Save parameters of epoch before
79 _parlist_sav = _parlist;
[9508]80 }
[9504]81
[8905]82 //--
[7237]83 // Set Parameters
[9508]84 if (_parlist.set(_epoTime, allObs, refSatMap) != success) {
[9419]85 return failure;
86 }
[9504]87 const vector<t_pppParam*>& params = _parlist.params();
[9386]88#ifdef BNC_DEBUG_PPP
[9508]89 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
[9521]90 LOG << "t_pppFilter::processEpoch par_cur " << params[iPar]->toString()
91 << " lastObsTime().valid() " << params[iPar]->lastObsTime().valid()
92 << " epoTime-params[iPar]->lastObsTime() " << (_epoTime - params[iPar]->lastObsTime()) << endl;
[9386]93 }
94#endif
[9419]95
[7237]96 // Status Vector, Variance-Covariance Matrix
97 // -----------------------------------------
98 ColumnVector xFltOld = _xFlt;
99 SymmetricMatrix QFltOld = _QFlt;
[8956]100
[9504]101 _QFlt.ReSize(_parlist.nPar()); _QFlt = 0.0;
102 _xFlt.ReSize(_parlist.nPar()); _xFlt = 0.0;
103 _x0.ReSize(_parlist.nPar()); _x0 = 0.0;
[9386]104
[7237]105 for (unsigned ii = 0; ii < params.size(); ii++) {
[9386]106 t_pppParam* par1 = params[ii];
107 if (QFltOld.size() == 0) {
108 par1->resetIndex();
109 }
[7237]110 _x0[ii] = par1->x0();
111 int iOld = par1->indexOld();
112 if (iOld < 0) {
113 _QFlt[ii][ii] = par1->sigma0() * par1->sigma0(); // new parameter
114 }
115 else {
116 _QFlt[ii][ii] = QFltOld[iOld][iOld] + par1->noise() * par1->noise();
117 _xFlt[ii] = xFltOld[iOld];
118 for (unsigned jj = 0; jj < ii; jj++) {
[9386]119 t_pppParam* par2 = params[jj];
120 int jOld = par2->indexOld();
[7237]121 if (jOld >= 0) {
122 _QFlt[ii][jj] = QFltOld(iOld+1,jOld+1);
123 }
124 }
125 }
126 }
127 predictCovCrdPart(QFltOld);
128
[8905]129 // Pre-Process Satellite Systems separately
130 // ----------------------------------------
131 bool preProcessing = false;
132 if (OPT->_obsModelType == OPT->DCMcodeBias ||
133 OPT->_obsModelType == OPT->DCMphaseBias) {
134 preProcessing = true;
[9504]135 const QList<char>& usedSystems = _parlist.usedSystems();
[9431]136 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
137 char sys = usedSystems[iSys];
[9508]138 _refPrn = refSatMap[sys]->prn();
[9386]139 vector<t_pppSatObs*> obsVector;
[8905]140 for (unsigned jj = 0; jj < allObs.size(); jj++) {
[9386]141 if (allObs[jj]->prn().system() == sys) {
[8905]142 obsVector.push_back(allObs[jj]);
143 }
144 }
[9431]145 if (iSys == 0) {
146 _datumTrafo->setFirstSystem(sys);
[9419]147 }
[9386]148 if (processSystem(OPT->LCs(sys), obsVector, _refPrn,
[8905]149 epoch->pseudoObsIono(), preProcessing) != success) {
[9386]150 _xFlt = xFltOld;
151 _QFlt = QFltOld;
[8905]152 return failure;
153 }
154 }
[8956]155 // refSat change required?
156 // -----------------------
157 if (_obsPool->refSatChangeRequired()) {
158 _xFlt = xFltOld;
159 _QFlt = QFltOld;
[9504]160 _parlist = _parlist_sav;
[8956]161 return success;
162 }
[9386]163 else if (!_obsPool->refSatChangeRequired()) {
[9419]164 initDatumTransformation(allObs, epoch->pseudoObsIono());
[8956]165 }
[8905]166 }
167
[7237]168 // Process Satellite Systems separately
169 // ------------------------------------
[8912]170 preProcessing = false;
[9504]171 const QList<char>& usedSystems = _parlist. usedSystems();
[9431]172 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
173 char sys = usedSystems[iSys];
[8910]174 if (OPT->_refSatRequired) {
[9508]175 _refPrn = refSatMap[sys]->prn();
[8910]176 }
[9421]177 else {
178 _refPrn.set(sys, 0);
179 }
[7267]180 unsigned int num = 0;
[7237]181 vector<t_pppSatObs*> obsVector;
182 for (unsigned jj = 0; jj < allObs.size(); jj++) {
[9419]183 if (allObs[jj]->prn().system() == sys) {
[7237]184 obsVector.push_back(allObs[jj]);
[9419]185 ++num;
[7237]186 }
187 }
[9431]188 if (iSys == 0 && OPT->_obsModelType == OPT->UncombPPP) {
189 _datumTrafo->setFirstSystem(sys);
[9419]190 }
191 LOG << epoTimeStr << " SATNUM " << sys << ' ' << right << setw(2) << num << endl;
192 if (processSystem(OPT->LCs(sys), obsVector, _refPrn,
[8905]193 epoch->pseudoObsIono(), preProcessing) != success) {
[7237]194 return failure;
195 }
196 }
[8912]197
198 // close epoch processing
199 // ----------------------
[9508]200 cmpDOP(allObs, refSatMap);
[9504]201 _parlist.printResult(_epoTime, _QFlt, _xFlt);
[8956]202 _lastEpoTimeOK = _epoTime; // remember time of last successful epoch processing
[7237]203 return success;
204}
205
206// Process Selected LCs
207////////////////////////////////////////////////////////////////////////////
[7267]208t_irc t_pppFilter::processSystem(const vector<t_lc::type>& LCs,
[8905]209 const vector<t_pppSatObs*>& obsVector,
210 const t_prn& refPrn,
211 bool pseudoObsIonoAvailable,
212 bool preProcessing) {
[7237]213 LOG.setf(ios::fixed);
[9386]214 char sys = refPrn.system();
[7237]215
216 // Detect Cycle Slips
217 // ------------------
[8905]218 if (detectCycleSlips(LCs, obsVector, refPrn, preProcessing) != success) {
[7237]219 return failure;
220 }
[9398]221 if (preProcessing && _obsPool->refSatChangeRequired(sys)) {
[9386]222 return success;
223 }
[7237]224
[8905]225 ColumnVector xSav = _xFlt;
226 SymmetricMatrix QSav = _QFlt;
227 string epoTimeStr = string(_epoTime);
[9504]228 const vector<t_pppParam*>& params = _parlist.params();
[8965]229
[9386]230 unsigned usedLCs = LCs.size();
[8965]231 if (OPT->_pseudoObsIono && !pseudoObsIonoAvailable) {
[9386]232 usedLCs -= 1; // GIM not used
[8961]233 }
[9386]234 int hlpLCs = 0;
235 if (OPT->_pseudoObsTropo) {
236 hlpLCs = -1;
[8965]237 }
[8961]238 // max Obs
[9386]239 unsigned maxObs = obsVector.size() * (usedLCs + hlpLCs);
[9419]240 if (OPT->_pseudoObsTropo && _datumTrafo->firstSystem(sys)) {
[9386]241 maxObs += 1;
242 }
[8965]243 if (OPT->_pseudoObsIono && pseudoObsIonoAvailable) {
244 maxObs -= 1; // pseudo obs iono with respect to refSat
[8905]245 }
246
[7237]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 // -----------------------------------------------------------
[9504]258 Matrix AA(maxObs, _parlist.nPar());
[7237]259 ColumnVector ll(maxObs);
260 DiagonalMatrix PP(maxObs); PP = 0.0;
[8912]261
[7237]262 int iObs = -1;
263 vector<t_pppSatObs*> usedObs;
264 vector<t_lc::type> usedTypes;
[9386]265
266 // Real Observations
267 // =================
[7237]268 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
[8956]269 t_pppSatObs* obs = obsVector[ii];
[9419]270 if (iOutlier == 0 && !preProcessing) {
271 obs->resetOutlier();
272 }
[7237]273 if (!obs->outlier()) {
[8905]274 for (unsigned jj = 0; jj < usedLCs; jj++) {
[7237]275 const t_lc::type tLC = LCs[jj];
[9386]276 if (tLC == t_lc::GIM) {continue;}
277 if (tLC == t_lc::Tz0) {continue;}
[7237]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];
[8956]283 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
[7237]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
[9395]291 // pseudo Obs Tropo
292 // ================
[9419]293 if (OPT->_pseudoObsTropo && _datumTrafo->firstSystem(sys)) {
[9421]294 bool _pseudoObsTropoConsidered = false;
[9395]295 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
[9421]296 if (_pseudoObsTropoConsidered) {break;}
[9395]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;
[9421]302 _pseudoObsTropoConsidered = true;
[9395]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
[9386]315 if ((!iOutlier) &&
316 (OPT->_obsModelType == OPT->DCMcodeBias ||
[9419]317 OPT->_obsModelType == OPT->DCMphaseBias) &&
318 (!preProcessing)) {
319 _datumTrafo->updateIndices(sys, iObs+1);
[9504]320 _datumTrafo->prepareAA(AA.SubMatrix(1, iObs+1 , 1, _parlist.nPar()), 1);
[9386]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 }
[8956]344 }
[8915]345 }
346
[7237]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;
[9386]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;
[7237]387 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
388 t_pppParam* hlp = params[iPar];
[8905]389 if (hlp->type() == t_pppParam::amb &&
390 hlp->prn() == obs->prn() &&
[7237]391 hlp->tLC() == usedTypes[maxOutlierIndex]) {
392 par = hlp;
393 }
394 }
[8956]395 if (preProcessing) {
[9491]396 // for refSats no ambiguity parameter exists
[9386]397 if ((obs->prn() == refPrn) &&
398 (t_lc::toString(maxOutlierLC) == "l1" ||
399 t_lc::toString(maxOutlierLC) == "l2") ) {
400 _obsPool->setRefSatChangeRequired(sys, true);
[9491]401 break;
[9386]402 }
403 else {
404 if (par) {
405 par->setAmbResetCandidate();
406 obs->setOutlier();
407 }
408 else {
409 obs->setOutlier();
410 }
[8905]411 }
412 }
[9386]413 else {// fin-processing
[8956]414 if (par) {
[9386]415 if (par->ambResetCandidate()) {
[8956]416 resetAmb(par->prn(), obsVector, &QSav, &xSav);
417 }
418 else {
419 par->setAmbResetCandidate();
420 obs->setOutlier();
421 }
[7237]422 }
423 else {
424 obs->setOutlier();
425 }
426 }
427 }
428 // Print Residuals
429 // ---------------
430 else {
[8905]431 if (!preProcessing) {
432 for (unsigned jj = 0; jj < LCs.size(); jj++) {
433 for (unsigned ii = 0; ii < usedObs.size(); ii++) {
434 const t_lc::type tLC = usedTypes[ii];
[9386]435 t_pppSatObs* obs = usedObs[ii];
[8905]436 if (tLC == LCs[jj]) {
437 obs->setRes(tLC, vv[ii]);
438 LOG << epoTimeStr << " RES "
[9386]439 << left << setw(3) << t_lc::toString(tLC) << right << ' ';
440 if (t_lc::toString(tLC) == "Tz0") {LOG << sys << " ";}
441 else {LOG << obs->prn().toString();}
[9435]442 LOG << setw(9) << setprecision(4) << vv[ii] << endl;
[8905]443 }
[7237]444 }
445 }
446 }
447 break;
448 }
449 }
450 return success;
451}
452
453// Cycle-Slip Detection
454////////////////////////////////////////////////////////////////////////////
[7267]455t_irc t_pppFilter::detectCycleSlips(const vector<t_lc::type>& LCs,
[8905]456 const vector<t_pppSatObs*>& obsVector,
457 const t_prn& refPrn,
458 bool preProcessing) {
[9386]459 const double SLIP = 20.0;
460 char sys = refPrn.system();
461 string epoTimeStr = string(_epoTime);
[9504]462 const vector<t_pppParam*>& params = _parlist.params();
[7237]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
[7267]470 // Check set Slips and Jump Counters
[7237]471 // ---------------------------------
472 bool slip = false;
[9386]473
474 // in pre-processing only the reference satellite has to be checked
475 if (preProcessing && obs->prn() != refPrn) {
476 continue;
477 }
478
[7237]479 if (obs->slip()) {
[8329]480 LOG << epoTimeStr << "cycle slip set (obs) " << obs->prn().toString() << endl;
[7237]481 slip = true;
482 }
483
484 if (_slips[obs->prn()]._obsSlipCounter != -1 &&
[9088]485 _slips[obs->prn()]._obsSlipCounter != obs->slipCounter()) {
[8329]486 LOG << epoTimeStr << "cycle slip set (obsSlipCounter) " << obs->prn().toString() << endl;
[7237]487 slip = true;
488 }
[8956]489 if (!preProcessing) {
490 _slips[obs->prn()]._obsSlipCounter = obs->slipCounter();
491 }
[7237]492 if (_slips[obs->prn()]._biasJumpCounter != -1 &&
493 _slips[obs->prn()]._biasJumpCounter != obs->biasJumpCounter()) {
[8329]494 LOG << epoTimeStr << "cycle slip set (biasJumpCounter) " << obs->prn().toString() << endl;
[7237]495 slip = true;
496 }
[8956]497 if (!preProcessing) {
498 _slips[obs->prn()]._biasJumpCounter = obs->biasJumpCounter();
499 }
[7237]500 // Slip Set
[7267]501 // --------
[7237]502 if (slip) {
[8905]503 if (preProcessing) {
[9386]504 _obsPool->setRefSatChangeRequired(sys, true);
[8905]505 }
506 else {
507 resetAmb(obs->prn(), obsVector);
508 }
[7237]509 }
510 // Check Pre-Fit Residuals
511 // -----------------------
512 else {
[9419]513 if (refPrn != t_prn()) {return success;}
[7237]514 ColumnVector AA(params.size());
515 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
516 const t_pppParam* par = params[iPar];
[8956]517 AA[iPar] = par->partial(_epoTime, obs, tLC, refPrn);
[7237]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) {
[9386]522 LOG << epoTimeStr << " cycle slip detected " << t_lc::toString(tLC) << ' '
523 << obs->prn().toString() << ' ' << setw(8) << setprecision(4) << vv << endl;
[8905]524 if (preProcessing) {
[9386]525 _obsPool->setRefSatChangeRequired(sys, true);
[8905]526 }
527 else {
528 resetAmb(obs->prn(), obsVector);
529 }
[7237]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) {
[8965]542
[7237]543 t_irc irc = failure;
[9504]544 vector<t_pppParam*>& params = _parlist.params();
[7237]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
[9395]576// Add infinite noise to iono
[9386]577////////////////////////////////////////////////////////////////////////////
578t_irc t_pppFilter::addNoiseToIono(char sys) {
579
580 t_irc irc = failure;
[9504]581 vector<t_pppParam*>& params = _parlist.params();
[9386]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
[7237]596// Compute various DOP Values
597////////////////////////////////////////////////////////////////////////////
[9521]598void t_pppFilter::cmpDOP(const vector<t_pppSatObs*>& obsVector,
[9508]599 const QMap<char, t_pppRefSat*>& refSatMap) {
[7237]600
601 _dop.reset();
602
603 try {
604 const unsigned numPar = 4;
605 Matrix AA(obsVector.size(), numPar);
606 _numSat = 0;
607 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
608 t_pppSatObs* obs = obsVector[ii];
[9508]609 char sys = obs->prn().system();
[8956]610 t_prn refPrn = t_prn();
611 if (OPT->_refSatRequired) {
[9508]612 refPrn = refSatMap[sys]->prn();
[8956]613 }
[7237]614 if (obs->isValid() && !obs->outlier()) {
615 ++_numSat;
616 for (unsigned iPar = 0; iPar < numPar; iPar++) {
[9504]617 const t_pppParam* par = _parlist.params()[iPar];
[8956]618 AA[_numSat-1][iPar] = par->partial(_epoTime, obs, t_lc::c1, refPrn);
[7237]619 }
620 }
621 }
622 if (_numSat < 4) {
623 return;
624 }
625 AA = AA.Rows(1, _numSat);
[7267]626 SymmetricMatrix NN; NN << AA.t() * AA;
[7237]627 SymmetricMatrix QQ = NN.i();
[7267]628
[7928]629 _dop.H = sqrt(QQ(1,1) + QQ(2,2));
630 _dop.V = sqrt(QQ(3,3));
[7237]631 _dop.P = sqrt(QQ(1,1) + QQ(2,2) + QQ(3,3));
632 _dop.T = sqrt(QQ(4,4));
633 _dop.G = sqrt(QQ(1,1) + QQ(2,2) + QQ(3,3) + QQ(4,4));
634 }
635 catch (...) {
636 }
637}
638
639// Compute various DOP Values
640////////////////////////////////////////////////////////////////////////////
641void t_pppFilter::predictCovCrdPart(const SymmetricMatrix& QFltOld) {
642
[9504]643 const vector<t_pppParam*>& params = _parlist.params();
[7237]644 if (params.size() < 3) {
645 return;
646 }
647
648 bool first = (params[0]->indexOld() < 0);
649
650 SymmetricMatrix Qneu(3); Qneu = 0.0;
651 for (unsigned ii = 0; ii < 3; ii++) {
652 const t_pppParam* par = params[ii];
653 if (first) {
654 Qneu[ii][ii] = par->sigma0() * par->sigma0();
655 }
656 else {
657 Qneu[ii][ii] = par->noise() * par->noise();
658 }
659 }
660
661 const t_pppStation* sta = PPP_CLIENT->staRover();
662 SymmetricMatrix Qxyz(3);
663 covariNEU_XYZ(Qneu, sta->ellApr().data(), Qxyz);
664
665 if (first) {
666 _QFlt.SymSubMatrix(1,3) = Qxyz;
667 }
668 else {
669 double dt = _epoTime - _firstEpoTime;
670 if (dt < OPT->_seedingTime) {
671 _QFlt.SymSubMatrix(1,3) = QFltOld.SymSubMatrix(1,3);
672 }
673 else {
674 _QFlt.SymSubMatrix(1,3) = QFltOld.SymSubMatrix(1,3) + Qxyz;
675 }
676 }
677}
[8912]678
[8915]679// Compute datum transformation
[8912]680////////////////////////////////////////////////////////////////////////////
[9508]681t_irc t_pppFilter::datumTransformation(const QMap<char, t_pppRefSat*>& refSatMap) {
682
[9419]683 // get last epoch
[9386]684 t_pppObsPool::t_epoch* epoch = _obsPool->lastEpoch();
[9419]685 if (!epoch) {
[9508]686 LOG << "t_pppFilter::datumTransformation: !lastEpoch" << endl;
[9386]687 return failure;
688 }
[9508]689 _epoTime = epoch->epoTime();
690 LOG.setf(ios::fixed);
691 LOG << string(_epoTime) << " DATUM TRANSFORMATION " << endl;
[9419]692
[9386]693 vector<t_pppSatObs*>& allObs = epoch->obsVector();
694
[9508]695 const QMap<char, t_pppRefSat*>& refSatMapLastEpoch = epoch->refSatMap();
696
697 bool peseudoObsIono = epoch->pseudoObsIono();
698
[9419]699 // reset old and set new refSats in last epoch (ambiguities/GIM)
700 // =============================================================
[9508]701 if (resetRefSatellitesLastEpoch(allObs, refSatMap, refSatMapLastEpoch) != true) {
[9431]702 LOG << "refsatChange required" << endl;
703 return success;
[9386]704 }
705
[9419]706 if (OPT->_obsModelType == OPT->UncombPPP) {
707 return success;
708 }
709
[9386]710 // set AA2
711 // =======
[9508]712 if (_parlist.set(_epoTime, allObs, refSatMap) != success) {
[9419]713 return failure;
714 }
[9508]715 vector<t_pppParam*>& _params = _parlist.params();
[9504]716 unsigned nPar = _parlist.nPar();
[9386]717#ifdef BNC_DEBUG_PPP
[9508]718 LOG << " t_pppFilter::datumTransformation par last epoch: " << _params.size() << "/" << nPar << endl;
[9431]719 for (unsigned iPar = 0; iPar < nPar; iPar++) {
[9521]720 LOG << "t_pppFilter::processEpoch par_cur " << _params[iPar]->toString()
721 << " lastObsTime().valid() " << _params[iPar]->lastObsTime().valid()
722 << " epoTime-params[iPar]->lastObsTime() " << (_epoTime - _params[iPar]->lastObsTime()) << endl;
[9386]723 }
724#endif
[9504]725 const QList<char>& usedSystems = _parlist.usedSystems();
[9431]726 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
727 char sys = usedSystems[iSys];
[9508]728 t_prn refPrn = refSatMap[sys]->prn();
[9386]729 vector<t_pppSatObs*> obsVector;
730 for (unsigned jj = 0; jj < allObs.size(); jj++) {
731 if (allObs[jj]->prn().system() == sys) {
732 obsVector.push_back(allObs[jj]);
733 }
734 }
[9431]735 if (iSys == 0) {
736 _datumTrafo->setFirstSystem(sys);
[9419]737 }
[9386]738 vector<t_lc::type> LCs = OPT->LCs(sys);
739 unsigned usedLCs = LCs.size();
[9508]740 if (OPT->_pseudoObsIono && !peseudoObsIono) {
[9386]741 usedLCs -= 1; // GIM not used
742 }
743 int hlpLCs = 0;
744 if (OPT->_pseudoObsTropo) {
745 hlpLCs = -1;
746 }
747 // max Obs
748 unsigned maxObs = obsVector.size() * (usedLCs + hlpLCs);
[9419]749
750 if (OPT->_pseudoObsTropo && _datumTrafo->firstSystem(sys)) {
[9386]751 maxObs += 1;
752 }
[9508]753 if (OPT->_pseudoObsIono && peseudoObsIono) {
[9386]754 maxObs -= 1; // pseudo obs iono with respect to refSat
755 }
[9419]756 Matrix AA(maxObs, nPar);
[9386]757 // Real Observations
758 // -----------------
759 int iObs = -1;
760 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
761 t_pppSatObs* obs = obsVector[ii];
[9419]762 for (unsigned jj = 0; jj < usedLCs; jj++) {
763 const t_lc::type tLC = LCs[jj];
764 if (tLC == t_lc::GIM) {continue;}
765 if (tLC == t_lc::Tz0) {continue;}
766 ++iObs;
[9504]767 for (unsigned iPar = 0; iPar < _params.size(); iPar++) {
768 const t_pppParam* par = _params[iPar];
[9419]769 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
[9386]770 }
771 }
772 }
[9395]773 // pseudo Obs Tropo
774 // ================
[9419]775 if (OPT->_pseudoObsTropo && _datumTrafo->firstSystem(sys)) {
[9421]776 bool pseudoObsTropoConsidered = false;
[9395]777 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
[9421]778 if (pseudoObsTropoConsidered) {break;}
[9395]779 t_pppSatObs* obs = obsVector[ii];
780 for (unsigned jj = 0; jj < usedLCs; jj++) {
781 const t_lc::type tLC = LCs[jj];
782 if (tLC != t_lc::Tz0) {continue;}
783 ++iObs;
[9421]784 pseudoObsTropoConsidered = true;
[9504]785 for (unsigned iPar = 0; iPar < _params.size(); iPar++) {
786 const t_pppParam* par = _params[iPar];
[9395]787 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
788 }
789 }
790 }
791 }
[9419]792 if (!iObs) {
793 continue;
794 }
[9508]795 _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;
796 if(_datumTrafo->prepareAA(AA.SubMatrix(1, iObs+1 , 1, nPar), 2) != success) {
797 return failure;
798 }
[9386]799 }
[9419]800 _datumTrafo->updateNumObs();
[9386]801
802 // Datum Transformation
803 // ====================
804#ifdef BNC_DEBUG_PPP
[9419]805 //LOG << "AA1\n"; _datumTrafo->printMatrix(_datumTrafo->AA1(), _datumTrafo->numObs(), _datumTrafo->numPar());
[9521]806 LOG << "AA2\n"; _datumTrafo->printMatrix(_datumTrafo->AA2(), _datumTrafo->numObs(), _datumTrafo->numPar());
[9386]807#endif
[9419]808 if(_datumTrafo->computeTrafoMatrix() != success) {
809 return failure;
810 }
[9386]811#ifdef BNC_DEBUG_PPP
[9419]812 //LOG << "D21" << endl; _datumTrafo->printMatrix(_datumTrafo->D21(), _datumTrafo->numObs(), _datumTrafo->numPar());
[9386]813#endif
814 ColumnVector xFltOld = _xFlt;
815 SymmetricMatrix QFltOld = _QFlt;
816
[9419]817 _QFlt << _datumTrafo->D21() * QFltOld * _datumTrafo->D21().t();
818 _xFlt = _datumTrafo->D21() * xFltOld;
[9386]819
820#ifdef BNC_DEBUG_PPP
821 LOG << "xFltOld:\n" << xFltOld << endl;
822 LOG << "xFlt :\n" << _xFlt << endl;
823#endif
824
825 // Reset Ambiguities after Datum Transformation
826 // ============================================
[9431]827 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
828 char sys = usedSystems[iSys];
[9508]829 t_prn refPrnOld = refSatMapLastEpoch[sys]->prn();
830 t_prn refPrnNew = refSatMap[sys]->prn();
[9419]831 if (refPrnNew != refPrnOld) {
[9508]832 t_irc irc = resetAmb(refPrnOld, allObs);
[9419]833 if (OPT->_obsModelType == OPT->DCMcodeBias) {
834 if (irc == success) {
835 addNoiseToIono(sys);
836 }
837 }
[9386]838 }
839 }
840
841 // switch AA2 to AA1
842 // =================
843 _datumTrafo->switchAA();
844
[9508]845 _obsPool->putEpoch(_epoTime, allObs, peseudoObsIono, refSatMap);
846
[9386]847 return success;
[8912]848}
849
[9386]850// Init datum transformation
[8956]851////////////////////////////////////////////////////////////////////////////
[9419]852void t_pppFilter::initDatumTransformation(const std::vector<t_pppSatObs*>& allObs,
853 bool pseudoObsIono) {
[9395]854 unsigned trafoObs = 0;
[9504]855 const QList<char>& usedSystems = _parlist. usedSystems();
[9431]856 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
857 char sys = usedSystems[iSys];
[9386]858 int satNum = 0;
859 for (unsigned jj = 0; jj < allObs.size(); jj++) {
[9419]860 if (allObs[jj]->prn().system() == sys) {
[9386]861 satNum++;
[8956]862 }
863 }
[9386]864 // all LCs
[9419]865 unsigned realUsedLCs = OPT->LCs(sys).size();
[9386]866 // exclude pseudo obs GIM
[9419]867 if (OPT->_pseudoObsIono && !pseudoObsIono) {
[9386]868 realUsedLCs -= 1;
869 }
870 if (OPT->_pseudoObsTropo) {
871 realUsedLCs -= 1;
872 }
[9395]873 trafoObs += satNum * realUsedLCs;
874
[9419]875 if (OPT->_pseudoObsTropo && _datumTrafo->firstSystem(sys)) {
[9395]876 trafoObs += 1;
877 }
[9419]878 if (OPT->_pseudoObsIono && pseudoObsIono) {
879 trafoObs -= 1; // pseudo obs iono with respect to refSat
880 }
[8956]881 }
[9419]882 _datumTrafo->setNumObs(trafoObs);
[9504]883 _datumTrafo->setNumPar(_parlist.nPar());
[9386]884 _datumTrafo->initAA();
[8956]885}
[9386]886
887//
888//////////////////////////////////////////////////////////////////////////////
[9508]889bool t_pppFilter::resetRefSatellitesLastEpoch(std::vector<t_pppSatObs*>& obsVector,
890 const QMap<char, t_pppRefSat*>& refSatMap,
891 const QMap<char, t_pppRefSat*>& refSatMapLastEpoch) {
[9431]892 bool resetRefSat;
[9386]893 // reference satellite definition per system
[9504]894 const QList<char>& usedSystems = _parlist.usedSystems();
[9431]895 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
896 resetRefSat = false;
897 char sys = usedSystems[iSys];
[9508]898 t_prn newPrn = refSatMap[sys]->prn();
899 t_prn oldPrn = refSatMapLastEpoch[sys]->prn();
[9386]900#ifdef BNC_DEBUG_PPP
[9508]901 if (oldPrn != newPrn) {
902 LOG << "oldRef: " << oldPrn.toString() << " => newRef " << newPrn.toString() << endl;
903 }
[9386]904#endif
905 vector<t_pppSatObs*>::iterator it = obsVector.begin();
906 while (it != obsVector.end()) {
907 t_pppSatObs* satObs = *it;
908 if (satObs->prn() == newPrn) {
909 resetRefSat = true;
910 satObs->setAsReference();
[9508]911 } else if (satObs->prn() == oldPrn) {
[9386]912 satObs->resetReference();
913 }
914 it++;
915 }
[9431]916 if (!resetRefSat) {
917 _obsPool->setRefSatChangeRequired(sys, true);
918 return resetRefSat;
919 }
[9386]920 }
921 return resetRefSat;
922}
Note: See TracBrowser for help on using the repository browser.