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

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