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

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