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

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