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

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