source: ntrip/branches/BNC_2.13/src/PPP/pppFilter.cpp@ 10000

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