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

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