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

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

some changes regarding PPP

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