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

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