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

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