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

Last change on this file since 9582 was 9582, checked in by stuerze, 8 months ago

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