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

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