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

Last change on this file since 9670 was 9670, checked in by stuerze, 2 years ago

minor changes regarding PPP

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