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

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