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

Last change on this file since 10020 was 10020, 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: 27.0 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 }
[10020]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 // ----------------------------
[10020]277 if (iObs == -1) {
278 LOG << " number of 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 }
[9642]373 } else { // fin-processing
[10020]374 LOG << epoTimeStr << " Outlier " << t_lc::toString(maxOutlierLC) << ' '
375 << obs->prn().toString() << ' ' << setw(8) << setprecision(4)
376 << maxOutlier << endl;
377 if (par) {
378 if (par->ambResetCandidate() ||
379 OPT->_obsModelType == OPT->DCMcodeBias ||
380 OPT->_obsModelType == OPT->DCMphaseBias) {
[10018]381 resetAmb(par->prn(), obsVector, maxOutlierLC, &QSav, &xSav);
382 }
383 else {
[10020]384 par->setAmbResetCandidate();
[10018]385 obs->setOutlier();
386 }
[9704]387 }
[10020]388 else {
389 obs->setOutlier();
390 }
[7237]391 }
392 }
393 // Print Residuals
394 // ---------------
395 else {
[8905]396 if (!preProcessing) {
397 for (unsigned jj = 0; jj < LCs.size(); jj++) {
398 for (unsigned ii = 0; ii < usedObs.size(); ii++) {
399 const t_lc::type tLC = usedTypes[ii];
[9642]400 t_pppSatObs *obs = usedObs[ii];
[8905]401 if (tLC == LCs[jj]) {
402 obs->setRes(tLC, vv[ii]);
[9642]403 LOG << epoTimeStr << " RES " << left << setw(3)
[9699]404 << t_lc::toString(tLC) << right << ' '
405 << obs->prn().toString();
[9435]406 LOG << setw(9) << setprecision(4) << vv[ii] << endl;
[8905]407 }
[7237]408 }
409 }
410 }
411 break;
412 }
413 }
414 return success;
415}
416
417// Cycle-Slip Detection
418////////////////////////////////////////////////////////////////////////////
[9642]419t_irc t_pppFilter::detectCycleSlips(const vector<t_lc::type> &LCs,
420 const vector<t_pppSatObs*> &obsVector, const t_prn &refPrn,
421 bool preProcessing) {
[10014]422 const double SLIP = 50.0;
[9386]423 char sys = refPrn.system();
424 string epoTimeStr = string(_epoTime);
[9642]425 const vector<t_pppParam*> &params = _parlist.params();
[9524]426 unsigned nPar = _parlist.nPar();
[7237]427
428 for (unsigned ii = 0; ii < LCs.size(); ii++) {
[9642]429 const t_lc::type &tLC = LCs[ii];
[7237]430 if (t_lc::includesPhase(tLC)) {
431 for (unsigned iObs = 0; iObs < obsVector.size(); iObs++) {
[9642]432 const t_pppSatObs *obs = obsVector[iObs];
[7237]433
[7267]434 // Check set Slips and Jump Counters
[7237]435 // ---------------------------------
436 bool slip = false;
[9386]437
438 // in pre-processing only the reference satellite has to be checked
439 if (preProcessing && obs->prn() != refPrn) {
440 continue;
441 }
442
[7237]443 if (obs->slip()) {
[9642]444 LOG << epoTimeStr << "cycle slip set (obs) " << obs->prn().toString()
445 << endl;
[7237]446 slip = true;
447 }
448
[9642]449 if (_slips[obs->prn()]._obsSlipCounter != -1
450 && _slips[obs->prn()]._obsSlipCounter != obs->slipCounter()) {
451 LOG << epoTimeStr << "cycle slip set (obsSlipCounter) "
452 << obs->prn().toString() << endl;
[7237]453 slip = true;
454 }
[8956]455 if (!preProcessing) {
456 _slips[obs->prn()]._obsSlipCounter = obs->slipCounter();
457 }
[9642]458 if (_slips[obs->prn()]._biasJumpCounter != -1
459 && _slips[obs->prn()]._biasJumpCounter != obs->biasJumpCounter()) {
460 LOG << epoTimeStr << "cycle slip set (biasJumpCounter) "
461 << obs->prn().toString() << endl;
[7237]462 slip = true;
463 }
[8956]464 if (!preProcessing) {
465 _slips[obs->prn()]._biasJumpCounter = obs->biasJumpCounter();
466 }
[7237]467 // Slip Set
[7267]468 // --------
[7237]469 if (slip) {
[8905]470 if (preProcessing) {
[9386]471 _obsPool->setRefSatChangeRequired(sys, true);
[9642]472 } else {
[10008]473 resetAmb(obs->prn(), obsVector, tLC);
[8905]474 }
[7237]475 }
[10002]476 // Check Pre-Fit Residuals
[9982]477 // -----------------------
[7237]478 else {
[9982]479 ColumnVector AA(nPar);
480 for (unsigned iPar = 0; iPar < nPar; iPar++) {
481 const t_pppParam *par = params[iPar];
482 AA[iPar] = par->partial(_epoTime, obs, tLC, refPrn);
483 }
484 double ll = obs->obsValue(tLC) - obs->cmpValue(tLC)
485 - DotProduct(_x0, AA);
486 double vv = DotProduct(AA, _xFlt) - ll;
487 if (fabs(vv) > SLIP) {
488 LOG << epoTimeStr << " cycle slip detected " << t_lc::toString(tLC)
489 << ' ' << obs->prn().toString() << ' ' << setw(8)
490 << setprecision(4) << vv << endl;
491 if (preProcessing) {
[9386]492 _obsPool->setRefSatChangeRequired(sys, true);
[9982]493 } else {
[10008]494 resetAmb(obs->prn(), obsVector, tLC);
[8905]495 }
[7237]496 }
[10002]497 }
[7237]498 }
499 }
500 }
501 return success;
502}
503
504// Reset Ambiguity Parameter (cycle slip)
505////////////////////////////////////////////////////////////////////////////
[9642]506t_irc t_pppFilter::resetAmb(t_prn prn, const vector<t_pppSatObs*> &obsVector,
[10008]507 t_lc::type lc, SymmetricMatrix *QSav, ColumnVector *xSav) {
[8965]508
[7237]509 t_irc irc = failure;
[9642]510 vector<t_pppParam*> &params = _parlist.params();
[7237]511 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
[9642]512 t_pppParam *par = params[iPar];
[7237]513 if (par->type() == t_pppParam::amb && par->prn() == prn) {
514 int ind = par->indexNew();
515 t_lc::type tLC = par->tLC();
[10014]516 if (tLC != lc) {
517 continue;
518 }
[7237]519 LOG << string(_epoTime) << " RESET " << par->toString() << endl;
[9642]520 delete par;
521 par = new t_pppParam(t_pppParam::amb, prn, tLC, &obsVector);
[7237]522 par->setIndex(ind);
523 params[iPar] = par;
524 for (unsigned ii = 1; ii <= params.size(); ii++) {
[9642]525 _QFlt(ii, ind + 1) = 0.0;
[7237]526 if (QSav) {
[9642]527 (*QSav)(ii, ind + 1) = 0.0;
[7237]528 }
529 }
[9642]530 _QFlt(ind + 1, ind + 1) = par->sigma0() * par->sigma0();
[7237]531 if (QSav) {
[9642]532 (*QSav)(ind + 1, ind + 1) = _QFlt(ind + 1, ind + 1);
[7237]533 }
534 _xFlt[ind] = 0.0;
535 if (xSav) {
536 (*xSav)[ind] = _xFlt[ind];
537 }
538 _x0[ind] = par->x0();
539 irc = success;
540 }
541 }
542
543 return irc;
544}
545
[9395]546// Add infinite noise to iono
[9386]547////////////////////////////////////////////////////////////////////////////
[9642]548t_irc t_pppFilter::addNoiseToPar(t_pppParam::e_type parType, char sys) {
[9386]549 t_irc irc = failure;
[9642]550 vector<t_pppParam*> &params = _parlist.params();
[9386]551 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
[9642]552 t_pppParam *par = params[iPar];
553 if (par->type() == parType && par->prn().system() == sys) {
[9386]554 int ind = par->indexNew();
[9659]555 LOG << string(_epoTime) << " ADD NOISE TO " << par->toString() << endl;
[9386]556 par->setIndex(ind);
[9642]557 _QFlt(ind + 1, ind + 1) = par->sigma0() * par->sigma0();
[9386]558 irc = success;
559 }
560 }
561
562 return irc;
563}
564
[7237]565// Compute various DOP Values
566////////////////////////////////////////////////////////////////////////////
[9642]567void t_pppFilter::cmpDOP(const vector<t_pppSatObs*> &obsVector,
568 const QMap<char, t_pppRefSat*> &refSatMap) {
[7237]569
570 _dop.reset();
571
572 try {
573 const unsigned numPar = 4;
574 Matrix AA(obsVector.size(), numPar);
575 _numSat = 0;
576 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
[9642]577 t_pppSatObs *obs = obsVector[ii];
[9508]578 char sys = obs->prn().system();
[8956]579 t_prn refPrn = t_prn();
580 if (OPT->_refSatRequired) {
[9508]581 refPrn = refSatMap[sys]->prn();
[8956]582 }
[7237]583 if (obs->isValid() && !obs->outlier()) {
584 ++_numSat;
585 for (unsigned iPar = 0; iPar < numPar; iPar++) {
[9642]586 const t_pppParam *par = _parlist.params()[iPar];
587 AA[_numSat - 1][iPar] = par->partial(_epoTime, obs, t_lc::c1, refPrn);
[7237]588 }
589 }
590 }
591 if (_numSat < 4) {
592 return;
593 }
594 AA = AA.Rows(1, _numSat);
[9642]595 SymmetricMatrix NN;
596 NN << AA.t() * AA;
[7237]597 SymmetricMatrix QQ = NN.i();
[7267]598
[9642]599 _dop.H = sqrt(QQ(1, 1) + QQ(2, 2));
600 _dop.V = sqrt(QQ(3, 3));
601 _dop.P = sqrt(QQ(1, 1) + QQ(2, 2) + QQ(3, 3));
602 _dop.T = sqrt(QQ(4, 4));
603 _dop.G = sqrt(QQ(1, 1) + QQ(2, 2) + QQ(3, 3) + QQ(4, 4));
604 } catch (...) {
[7237]605 }
606}
607
[9526]608//
[7237]609////////////////////////////////////////////////////////////////////////////
[10010]610void t_pppFilter::predictCovCrdPart(const SymmetricMatrix &QFltOld, bool setNeuNoiseToZero) {
[7237]611
[9642]612 const vector<t_pppParam*> &params = _parlist.params();
[7237]613 if (params.size() < 3) {
614 return;
615 }
616
617 bool first = (params[0]->indexOld() < 0);
618
[9642]619 SymmetricMatrix Qneu(3);
620 Qneu = 0.0;
[7237]621 for (unsigned ii = 0; ii < 3; ii++) {
[9642]622 const t_pppParam *par = params[ii];
[7237]623 if (first) {
624 Qneu[ii][ii] = par->sigma0() * par->sigma0();
[9642]625 } else {
[7237]626 Qneu[ii][ii] = par->noise() * par->noise();
627 }
628 }
629
[9642]630 const t_pppStation *sta = PPP_CLIENT->staRover();
[7237]631 SymmetricMatrix Qxyz(3);
632 covariNEU_XYZ(Qneu, sta->ellApr().data(), Qxyz);
633
634 if (first) {
[9642]635 _QFlt.SymSubMatrix(1, 3) = Qxyz;
636 } else {
[7237]637 double dt = _epoTime - _firstEpoTime;
[10010]638 if (dt < OPT->_seedingTime || setNeuNoiseToZero) {
[9642]639 _QFlt.SymSubMatrix(1, 3) = QFltOld.SymSubMatrix(1, 3);
640 } else {
641 _QFlt.SymSubMatrix(1, 3) = QFltOld.SymSubMatrix(1, 3) + Qxyz;
[7237]642 }
643 }
644}
[8912]645
[9526]646//
647////////////////////////////////////////////////////////////////////////////
[9642]648void t_pppFilter::setStateVectorAndVarCovMatrix(const ColumnVector &xFltOld,
[10010]649 const SymmetricMatrix &QFltOld, bool setNeuNoiseToZero) {
[9526]650
[9642]651 const vector<t_pppParam*> &params = _parlist.params();
[9526]652 unsigned nPar = params.size();
653
[9642]654 _QFlt.ReSize(nPar);
655 _QFlt = 0.0;
656 _xFlt.ReSize(nPar);
657 _xFlt = 0.0;
658 _x0.ReSize(nPar);
659 _x0 = 0.0;
[9526]660
661 for (unsigned ii = 0; ii < nPar; ii++) {
[9642]662 t_pppParam *par1 = params[ii];
[9526]663 if (QFltOld.size() == 0) {
664 par1->resetIndex();
665 }
666 _x0[ii] = par1->x0();
667 int iOld = par1->indexOld();
668 if (iOld < 0) {
669 _QFlt[ii][ii] = par1->sigma0() * par1->sigma0(); // new parameter
[9642]670 } else {
[9526]671 _QFlt[ii][ii] = QFltOld[iOld][iOld] + par1->noise() * par1->noise();
[9642]672 _xFlt[ii] = xFltOld[iOld];
[9526]673 for (unsigned jj = 0; jj < ii; jj++) {
[9642]674 t_pppParam *par2 = params[jj];
675 int jOld = par2->indexOld();
[9526]676 if (jOld >= 0) {
[9642]677 _QFlt[ii][jj] = QFltOld(iOld + 1, jOld + 1);
[9526]678 }
679 }
680 }
681 }
[10010]682 predictCovCrdPart(QFltOld, setNeuNoiseToZero);
[9526]683}
684
[8915]685// Compute datum transformation
[8912]686////////////////////////////////////////////////////////////////////////////
[9642]687t_irc t_pppFilter::datumTransformation(
688 const QMap<char, t_pppRefSat*> &refSatMap) {
[9508]689
[9419]690 // get last epoch
[9642]691 t_pppObsPool::t_epoch *epoch = _obsPool->lastEpoch();
[9419]692 if (!epoch) {
[9508]693 LOG << "t_pppFilter::datumTransformation: !lastEpoch" << endl;
[9386]694 return failure;
695 }
[9508]696 _epoTime = epoch->epoTime();
697 LOG.setf(ios::fixed);
[10015]698 LOG << string(_epoTime) << "\nDATUM TRANSFORMATION " << endl;
[9419]699
[9642]700 vector<t_pppSatObs*> &allObs = epoch->obsVector();
[9386]701
[9642]702 const QMap<char, t_pppRefSat*> &refSatMapLastEpoch = epoch->refSatMap();
[9508]703
[9548]704 bool pseudoObsIono = epoch->pseudoObsIono();
[9508]705
[9419]706 // reset old and set new refSats in last epoch (ambiguities/GIM)
707 // =============================================================
[10008]708 if (resetRefSatellitesLastEpoch(allObs, refSatMap, refSatMapLastEpoch) != true) {
709 LOG << "datumTransformation: resetRefSatellitesLastEpoch != success" << endl;
[9548]710 return failure;
[9386]711 }
712
[9419]713 if (OPT->_obsModelType == OPT->UncombPPP) {
[9548]714 _obsPool->putEpoch(_epoTime, allObs, pseudoObsIono, refSatMap);
[9419]715 return success;
716 }
717
[9386]718 // set AA2
719 // =======
[9508]720 if (_parlist.set(_epoTime, allObs, refSatMap) != success) {
[9419]721 return failure;
722 }
[10015]723#ifdef BNC_DEBUG_PPP
[10018]724 //_parlist.printParams(_epoTime);
[10015]725#endif
[9526]726
[9642]727 const QList<char> &usedSystems = _parlist.usedSystems();
[9431]728 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
729 char sys = usedSystems[iSys];
[9508]730 t_prn refPrn = refSatMap[sys]->prn();
[9386]731 vector<t_pppSatObs*> obsVector;
732 for (unsigned jj = 0; jj < allObs.size(); jj++) {
733 if (allObs[jj]->prn().system() == sys) {
[9618]734 allObs[jj]->resetOutlier();
[9386]735 obsVector.push_back(allObs[jj]);
736 }
737 }
[9431]738 if (iSys == 0) {
739 _datumTrafo->setFirstSystem(sys);
[9419]740 }
[9386]741 vector<t_lc::type> LCs = OPT->LCs(sys);
742 unsigned usedLCs = LCs.size();
[9548]743 if (OPT->_pseudoObsIono && !pseudoObsIono) {
[9642]744 usedLCs -= 1; // GIM not used
[9386]745 }
746 // max Obs
[9538]747 unsigned maxObs = obsVector.size() * usedLCs;
[9419]748
[9548]749 if (OPT->_pseudoObsIono && pseudoObsIono) {
[9386]750 maxObs -= 1; // pseudo obs iono with respect to refSat
751 }
[9526]752
[9642]753 const vector<t_pppParam*> &params = _parlist.params();
[9526]754 unsigned nPar = _parlist.nPar();
755
[10017]756 Matrix AA(maxObs, nPar); AA = 0.0;
[9524]757
[9386]758 // Real Observations
759 // -----------------
760 int iObs = -1;
761 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
[9642]762 t_pppSatObs *obs = obsVector[ii];
[9419]763 for (unsigned jj = 0; jj < usedLCs; jj++) {
764 const t_lc::type tLC = LCs[jj];
[9642]765 if (tLC == t_lc::GIM) {
766 continue;
767 }
[9419]768 ++iObs;
[9524]769 for (unsigned iPar = 0; iPar < nPar; iPar++) {
[9642]770 const t_pppParam *par = params[iPar];
[9419]771 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
[9386]772 }
773 }
774 }
[9538]775
[9999]776 if (!(iObs+1)) {
[9419]777 continue;
778 }
[10002]779 _datumTrafo->updateIndices(sys, iObs + 1);
[10013]780
[10008]781 if (_datumTrafo->prepareAA(AA.SubMatrix(1, iObs + 1, 1, nPar), 2) != success) {
[9508]782 return failure;
783 }
[9386]784 }
[9419]785 _datumTrafo->updateNumObs();
[9386]786
787 // Datum Transformation
788 // ====================
[9642]789 if (_datumTrafo->computeTrafoMatrix() != success) {
[9419]790 return failure;
791 }
[10008]792
[9642]793 ColumnVector xFltOld = _xFlt;
[9386]794 SymmetricMatrix QFltOld = _QFlt;
795
[9419]796 _QFlt << _datumTrafo->D21() * QFltOld * _datumTrafo->D21().t();
[9642]797 _xFlt = _datumTrafo->D21() * xFltOld;
[9386]798
[9579]799#ifdef BNC_DEBUG_PPP
[10015]800 //LOG << "xFltOld:\n" << xFltOld << endl;
801 //LOG << "xFlt :\n" << _xFlt << endl;
[9579]802#endif
[9386]803
804 // Reset Ambiguities after Datum Transformation
805 // ============================================
[9431]806 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
807 char sys = usedSystems[iSys];
[10008]808 vector<t_lc::type> LCs = OPT->LCs(sys);
809 unsigned usedLCs = LCs.size();
810 if (OPT->_pseudoObsIono && !pseudoObsIono) {
811 usedLCs -= 1; // GIM not used
812 }
[9508]813 t_prn refPrnOld = refSatMapLastEpoch[sys]->prn();
814 t_prn refPrnNew = refSatMap[sys]->prn();
[9419]815 if (refPrnNew != refPrnOld) {
[10008]816 for (unsigned jj = 0; jj < usedLCs; jj++) {
817 const t_lc::type tLC = LCs[jj];
818 if (tLC == t_lc::GIM) {
819 continue;
[9642]820 }
[10008]821 resetAmb(refPrnOld, allObs, tLC);
822 }
[9386]823 }
824 }
825
826 // switch AA2 to AA1
827 // =================
828 _datumTrafo->switchAA();
829
[9548]830 _obsPool->putEpoch(_epoTime, allObs, pseudoObsIono, refSatMap);
[9508]831
[9386]832 return success;
[8912]833}
834
[9386]835// Init datum transformation
[8956]836////////////////////////////////////////////////////////////////////////////
[9642]837void t_pppFilter::initDatumTransformation(
838 const std::vector<t_pppSatObs*> &allObs, bool pseudoObsIono) {
[9395]839 unsigned trafoObs = 0;
[9642]840 const QList<char> &usedSystems = _parlist.usedSystems();
[9431]841 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
842 char sys = usedSystems[iSys];
[9386]843 int satNum = 0;
844 for (unsigned jj = 0; jj < allObs.size(); jj++) {
[9419]845 if (allObs[jj]->prn().system() == sys) {
[9386]846 satNum++;
[8956]847 }
848 }
[9386]849 // all LCs
[9419]850 unsigned realUsedLCs = OPT->LCs(sys).size();
[9386]851 // exclude pseudo obs GIM
[9419]852 if (OPT->_pseudoObsIono && !pseudoObsIono) {
[9386]853 realUsedLCs -= 1;
854 }
[9538]855
[9395]856 trafoObs += satNum * realUsedLCs;
857
[9419]858 if (OPT->_pseudoObsIono && pseudoObsIono) {
859 trafoObs -= 1; // pseudo obs iono with respect to refSat
860 }
[8956]861 }
[9419]862 _datumTrafo->setNumObs(trafoObs);
[9504]863 _datumTrafo->setNumPar(_parlist.nPar());
[9386]864 _datumTrafo->initAA();
[8956]865}
[9386]866
867//
868//////////////////////////////////////////////////////////////////////////////
[9642]869bool t_pppFilter::resetRefSatellitesLastEpoch(
870 std::vector<t_pppSatObs*> &obsVector,
871 const QMap<char, t_pppRefSat*> &refSatMap,
872 const QMap<char, t_pppRefSat*> &refSatMapLastEpoch) {
[9431]873 bool resetRefSat;
[9386]874 // reference satellite definition per system
[9642]875 const QList<char> &usedSystems = _parlist.usedSystems();
[9431]876 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
877 resetRefSat = false;
878 char sys = usedSystems[iSys];
[9508]879 t_prn newPrn = refSatMap[sys]->prn();
880 t_prn oldPrn = refSatMapLastEpoch[sys]->prn();
[9386]881#ifdef BNC_DEBUG_PPP
[9508]882 if (oldPrn != newPrn) {
883 LOG << "oldRef: " << oldPrn.toString() << " => newRef " << newPrn.toString() << endl;
884 }
[9386]885#endif
886 vector<t_pppSatObs*>::iterator it = obsVector.begin();
887 while (it != obsVector.end()) {
[9642]888 t_pppSatObs *satObs = *it;
889 if (satObs->prn() == newPrn) {
[9386]890 resetRefSat = true;
891 satObs->setAsReference();
[9508]892 } else if (satObs->prn() == oldPrn) {
[9386]893 satObs->resetReference();
894 }
[9642]895 it++;
[9386]896 }
[9431]897 if (!resetRefSat) {
898 _obsPool->setRefSatChangeRequired(sys, true);
899 return resetRefSat;
900 }
[9386]901 }
902 return resetRefSat;
903}
Note: See TracBrowser for help on using the repository browser.