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

Last change on this file since 10021 was 10021, checked in by stuerze, 13 months ago

reset ambiguitis as soon as an outier appears

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