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

Last change on this file since 9979 was 9979, checked in by stuerze, 14 months ago

minor changes for test

  • 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() || !_lastEpoTimeOK.valid()
67 || (maxSolGap > 0.0 && _epoTime - _lastEpoTimeOK > maxSolGap)) {
68 _firstEpoTime = _epoTime;
69 }
70
71 string epoTimeStr = string(_epoTime);
72
73 const QMap<char, t_pppRefSat*> &refSatMap = epoch->refSatMap();
74
75 //--
76 // Set Parameters
77 if (_parlist.set(_epoTime, allObs, refSatMap) != success) {
78 return failure;
79 }
80
81 if (OPT->_obsModelType == OPT->DCMcodeBias ||
82 OPT->_obsModelType == OPT->DCMphaseBias) {
83#ifdef BNC_DEBUG_PPP
84 _parlist.printParams(_epoTime);
85#endif
86 }
87 // Status Vector, Variance-Covariance Matrix
88 // -----------------------------------------
89 ColumnVector xFltOld = _xFlt;
90 SymmetricMatrix QFltOld = _QFlt;
91 setStateVectorAndVarCovMatrix(xFltOld, QFltOld);
92
93 // Pre-Process Satellite Systems separately
94 // ----------------------------------------
95 bool preProcessing = false;
96 if (OPT->_obsModelType == OPT->DCMcodeBias ||
97 OPT->_obsModelType == OPT->DCMphaseBias) {
98 preProcessing = true;
99 const QList<char> &usedSystems = _parlist.usedSystems();
100 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
101 char sys = usedSystems[iSys];
102 _refPrn.set(sys, 0);
103 if (OPT->_refSatRequired) {
104 _refPrn = refSatMap[sys]->prn();
105 }
106 vector<t_pppSatObs*> obsVector;
107 for (unsigned jj = 0; jj < allObs.size(); jj++) {
108 if (allObs[jj]->prn().system() == sys) {
109 obsVector.push_back(allObs[jj]);
110 }
111 }
112 if (iSys == 0) {
113 _datumTrafo->setFirstSystem(sys);
114 }
115 if (processSystem(OPT->LCs(sys), obsVector, _refPrn,
116 epoch->pseudoObsIono(), preProcessing) != success) {
117 LOG << sys << ": processSystem != success (pre-processing)" << endl;
118 _xFlt = xFltOld;
119 _QFlt = QFltOld;
120 _obsPool->deleteLastEpoch();
121 restoreState(2);
122 return failure;
123 }
124 }
125 // refSat change required?
126 // -----------------------
127 if (_obsPool->refSatChangeRequired()) {
128 _xFlt = xFltOld;
129 _QFlt = QFltOld;
130 return success;
131 } else if (!_obsPool->refSatChangeRequired()) {
132 initDatumTransformation(allObs, epoch->pseudoObsIono());
133 }
134 }
135
136 // Process Satellite Systems separately
137 // ------------------------------------
138 preProcessing = false;
139 const QList<char> &usedSystems = _parlist.usedSystems();
140 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
141 char sys = usedSystems[iSys];
142 _refPrn.set(sys, 0);
143 if (OPT->_refSatRequired) {
144 _refPrn = refSatMap[sys]->prn();
145 }
146 unsigned int num = 0;
147 vector<t_pppSatObs*> obsVector;
148 for (unsigned jj = 0; jj < allObs.size(); jj++) {
149 if (allObs[jj]->prn().system() == sys) {
150 obsVector.push_back(allObs[jj]);
151 ++num;
152 }
153 }
154 if (iSys == 0 && OPT->_obsModelType == OPT->UncombPPP) {
155 _datumTrafo->setFirstSystem(sys);
156 }
157 LOG << epoTimeStr << " SATNUM " << sys << ' ' << right << setw(2) << num
158 << endl;
159 if (processSystem(OPT->LCs(sys), obsVector, _refPrn, epoch->pseudoObsIono(),
160 preProcessing) != success) {
161 LOG << "processSystem != success (fin-processing)" << endl;
162 if (OPT->_obsModelType == OPT->DCMcodeBias ||
163 OPT->_obsModelType == OPT->DCMphaseBias) {
164 _xFlt = xFltOld;
165 _QFlt = QFltOld;
166 _obsPool->deleteLastEpoch();
167 restoreState(3);
168 }
169 return failure;
170 }
171 }
172
173 // close epoch processing
174 // ----------------------
175 cmpDOP(allObs, refSatMap);
176 _parlist.printResult(_epoTime, _QFlt, _xFlt);
177 _lastEpoTimeOK = _epoTime; // remember time of last successful epoch processing
178 return success;
179}
180
181// Process Selected LCs
182////////////////////////////////////////////////////////////////////////////
183t_irc t_pppFilter::processSystem(const vector<t_lc::type> &LCs,
184 const vector<t_pppSatObs*> &obsVector, const t_prn &refPrn,
185 bool pseudoObsIonoAvailable, bool preProcessing) {
186 LOG.setf(ios::fixed);
187 char sys = refPrn.system();
188
189 // Detect Cycle Slips
190 // ------------------
191 if (detectCycleSlips(LCs, obsVector, refPrn, preProcessing) != success) {
192 return failure;
193 }
194 if (preProcessing && _obsPool->refSatChangeRequired(sys)) {
195 return success;
196 }
197
198 ColumnVector xSav = _xFlt;
199 SymmetricMatrix QSav = _QFlt;
200 string epoTimeStr = string(_epoTime);
201 const vector<t_pppParam*> &params = _parlist.params();
202 unsigned nPar = _parlist.nPar();
203
204 unsigned usedLCs = LCs.size();
205 if (OPT->_pseudoObsIono && !pseudoObsIonoAvailable) {
206 usedLCs -= 1; // GIM not used
207 }
208 // max Obs
209 unsigned maxObs = obsVector.size() * usedLCs;
210
211 if (OPT->_pseudoObsIono && pseudoObsIonoAvailable) {
212 maxObs -= 1; // pseudo obs iono with respect to refSat
213 }
214
215 // Outlier Detection Loop
216 // ----------------------
217 for (unsigned iOutlier = 0; iOutlier < maxObs; iOutlier++) {
218
219 if (iOutlier > 0) {
220 _xFlt = xSav;
221 _QFlt = QSav;
222 }
223
224 // First-Design Matrix, Terms Observed-Computed, Weight Matrix
225 // -----------------------------------------------------------
226 Matrix AA(maxObs, nPar);
227 ColumnVector ll(maxObs);
228 DiagonalMatrix PP(maxObs);
229 PP = 0.0;
230
231 int iObs = -1;
232 vector<t_pppSatObs*> usedObs;
233 vector<t_lc::type> usedTypes;
234
235 // Real Observations
236 // =================
237 double nSat = 0;
238 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
239 t_pppSatObs *obs = obsVector[ii];
240 if (iOutlier == 0 && !preProcessing) {
241 obs->resetOutlier();
242 }
243 if (!obs->outlier()) {
244 nSat++;
245 for (unsigned jj = 0; jj < usedLCs; jj++) {
246 const t_lc::type tLC = LCs[jj];
247 if (tLC == t_lc::GIM) {
248 continue;
249 }
250 ++iObs;
251 usedObs.push_back(obs);
252 usedTypes.push_back(tLC);
253 for (unsigned iPar = 0; iPar < nPar; iPar++) {
254 const t_pppParam *par = params[iPar];
255 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
256 }
257 ll[iObs] = obs->obsValue(tLC) - obs->cmpValue(tLC)
258 - 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) {
267 LOG << " number of observations == -1\n";
268 return failure;
269 }
270
271 if ((!iOutlier) &&
272 (OPT->_obsModelType == OPT->DCMcodeBias ||
273 OPT->_obsModelType == OPT->DCMphaseBias) && (!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 {
289 continue;
290 }
291 usedObs.push_back(obs);
292 usedTypes.push_back(tLC);
293 for (unsigned iPar = 0; iPar < nPar; iPar++) {
294 const t_pppParam *par = params[iPar];
295 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
296 }
297 ll[iObs] = obs->obsValue(tLC) - obs->cmpValue(tLC)
298 - DotProduct(_x0, AA.Row(iObs + 1));
299 PP[iObs] = 1.0 / (obs->sigma(tLC) * obs->sigma(tLC));
300 }
301 }
302 }
303 }
304
305 // Truncate matrices
306 // -----------------
307 AA = AA.Rows(1, iObs + 1);
308 ll = ll.Rows(1, iObs + 1);
309 PP = PP.SymSubMatrix(1, iObs + 1);
310
311 // Kalman update step
312 // ------------------
313 kalman(AA, ll, PP, _QFlt, _xFlt);
314
315 // Check Residuals
316 // ---------------
317 ColumnVector vv = AA * _xFlt - ll;
318 double maxOutlier = 0.0;
319 int maxOutlierIndex = -1;
320 t_lc::type maxOutlierLC = t_lc::dummy;
321 for (unsigned ii = 0; ii < usedObs.size(); ii++) {
322 const t_lc::type tLC = usedTypes[ii];
323 double res = fabs(vv[ii]);
324 if (res > usedObs[ii]->maxRes(tLC)) {
325 if (res > fabs(maxOutlier)) {
326 maxOutlier = vv[ii];
327 maxOutlierIndex = ii;
328 maxOutlierLC = tLC;
329 }
330 }
331 }
332
333 // Mark outlier or break outlier detection loop
334 // --------------------------------------------
335 if (maxOutlierIndex > -1) {
336 t_pppSatObs *obs = usedObs[maxOutlierIndex];
337 t_pppParam *par = 0;
338 for (unsigned iPar = 0; iPar < nPar; iPar++) {
339 t_pppParam *hlp = params[iPar];
340 if (hlp->type() == t_pppParam::amb && hlp->prn() == obs->prn()
341 && hlp->tLC() == usedTypes[maxOutlierIndex]) {
342 par = hlp;
343 }
344 }
345 if (preProcessing) {
346 // for refSats no ambiguity parameters exist
347 if ((obs->prn() == refPrn)
348 && (t_lc::toString(maxOutlierLC) == "l1" ||
349 t_lc::toString(maxOutlierLC) == "l2")) {
350 _obsPool->setRefSatChangeRequired(sys, true);
351 LOG << epoTimeStr << " Outlier ("
352 << ((preProcessing) ? "pre-processing) " : "fin-processing) ")
353 << t_lc::toString(maxOutlierLC) << ' ' << obs->prn().toString()
354 << ' ' << setw(8) << setprecision(4) << maxOutlier << endl;
355 break;
356 } //else {obs->setOutlier();}
357 } else { // fin-processing
358 LOG << epoTimeStr << " Outlier " << t_lc::toString(maxOutlierLC) << ' '
359 << obs->prn().toString() << ' ' << setw(8) << setprecision(4)
360 << maxOutlier << endl;
361 if (par) {
362 resetAmb(par->prn(), obsVector, &QSav, &xSav);
363 }
364 else {
365 obs->setOutlier();
366 }
367 }
368 }
369 // Print Residuals
370 // ---------------
371 else {
372 if (!preProcessing) {
373 for (unsigned jj = 0; jj < LCs.size(); jj++) {
374 for (unsigned ii = 0; ii < usedObs.size(); ii++) {
375 const t_lc::type tLC = usedTypes[ii];
376 t_pppSatObs *obs = usedObs[ii];
377 if (tLC == LCs[jj]) {
378 obs->setRes(tLC, vv[ii]);
379 LOG << epoTimeStr << " RES " << left << setw(3)
380 << t_lc::toString(tLC) << right << ' '
381 << obs->prn().toString();
382 LOG << setw(9) << setprecision(4) << vv[ii] << endl;
383 }
384 }
385 }
386 }
387 break;
388 }
389 }
390 return success;
391}
392
393// Cycle-Slip Detection
394////////////////////////////////////////////////////////////////////////////
395t_irc t_pppFilter::detectCycleSlips(const vector<t_lc::type> &LCs,
396 const vector<t_pppSatObs*> &obsVector, const t_prn &refPrn,
397 bool preProcessing) {
398 const double SLIP = 100.0;
399 char sys = refPrn.system();
400 string epoTimeStr = string(_epoTime);
401 const vector<t_pppParam*> &params = _parlist.params();
402 unsigned nPar = _parlist.nPar();
403
404 for (unsigned ii = 0; ii < LCs.size(); ii++) {
405 const t_lc::type &tLC = LCs[ii];
406 if (t_lc::includesPhase(tLC)) {
407 for (unsigned iObs = 0; iObs < obsVector.size(); iObs++) {
408 const t_pppSatObs *obs = obsVector[iObs];
409
410 // Check set Slips and Jump Counters
411 // ---------------------------------
412 bool slip = false;
413
414 // in pre-processing only the reference satellite has to be checked
415 if (preProcessing && obs->prn() != refPrn) {
416 continue;
417 }
418
419 if (obs->slip()) {
420 LOG << epoTimeStr << "cycle slip set (obs) " << obs->prn().toString()
421 << endl;
422 slip = true;
423 }
424
425 if (_slips[obs->prn()]._obsSlipCounter != -1
426 && _slips[obs->prn()]._obsSlipCounter != obs->slipCounter()) {
427 LOG << epoTimeStr << "cycle slip set (obsSlipCounter) "
428 << obs->prn().toString() << endl;
429 slip = true;
430 }
431 if (!preProcessing) {
432 _slips[obs->prn()]._obsSlipCounter = obs->slipCounter();
433 }
434 if (_slips[obs->prn()]._biasJumpCounter != -1
435 && _slips[obs->prn()]._biasJumpCounter != obs->biasJumpCounter()) {
436 LOG << epoTimeStr << "cycle slip set (biasJumpCounter) "
437 << obs->prn().toString() << endl;
438 slip = true;
439 }
440 if (!preProcessing) {
441 _slips[obs->prn()]._biasJumpCounter = obs->biasJumpCounter();
442 }
443 // Slip Set
444 // --------
445 if (slip) {
446 if (preProcessing) {
447 _obsPool->setRefSatChangeRequired(sys, true);
448 } else {
449 resetAmb(obs->prn(), obsVector);
450 }
451 }
452 // Check Pre-Fit Residuals
453 /* -----------------------
454 else {
455 if (OPT->_obsModelType == OPT->DCMcodeBias || OPT->_obsModelType == OPT->DCMphaseBias) {
456 if (!preProcessing || refPrn != t_prn()) {
457 return success;
458 }
459 ColumnVector AA(nPar);
460 for (unsigned iPar = 0; iPar < nPar; iPar++) {
461 const t_pppParam *par = params[iPar];
462 AA[iPar] = par->partial(_epoTime, obs, tLC, refPrn);
463 }
464 double ll = obs->obsValue(tLC) - obs->cmpValue(tLC) - DotProduct(_x0, AA);
465 double vv = DotProduct(AA, _xFlt) - ll;
466 if (fabs(vv) > SLIP) {
467 LOG << epoTimeStr << " cycle slip detected " << t_lc::toString(tLC)
468 << ' ' << obs->prn().toString() << ' ' << setw(8)
469 << setprecision(4) << vv << endl;
470 _obsPool->setRefSatChangeRequired(sys, true);
471 }
472 }
473 }*/
474 }
475 }
476 }
477 return success;
478}
479
480// Reset Ambiguity Parameter (cycle slip)
481////////////////////////////////////////////////////////////////////////////
482t_irc t_pppFilter::resetAmb(t_prn prn, const vector<t_pppSatObs*> &obsVector,
483 SymmetricMatrix *QSav, ColumnVector *xSav) {
484
485 t_irc irc = failure;
486 vector<t_pppParam*> &params = _parlist.params();
487 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
488 t_pppParam *par = params[iPar];
489 if (par->type() == t_pppParam::amb && par->prn() == prn) {
490 int ind = par->indexNew();
491 t_lc::type tLC = par->tLC();
492 LOG << string(_epoTime) << " RESET " << par->toString() << endl;
493 delete par;
494 par = new t_pppParam(t_pppParam::amb, prn, tLC, &obsVector);
495 par->setIndex(ind);
496 params[iPar] = par;
497 for (unsigned ii = 1; ii <= params.size(); ii++) {
498 _QFlt(ii, ind + 1) = 0.0;
499 if (QSav) {
500 (*QSav)(ii, ind + 1) = 0.0;
501 }
502 }
503 _QFlt(ind + 1, ind + 1) = par->sigma0() * par->sigma0();
504 if (QSav) {
505 (*QSav)(ind + 1, ind + 1) = _QFlt(ind + 1, ind + 1);
506 }
507 _xFlt[ind] = 0.0;
508 if (xSav) {
509 (*xSav)[ind] = _xFlt[ind];
510 }
511 _x0[ind] = par->x0();
512 irc = success;
513 }
514 }
515
516 return irc;
517}
518
519// Add infinite noise to iono
520////////////////////////////////////////////////////////////////////////////
521t_irc t_pppFilter::addNoiseToPar(t_pppParam::e_type parType, char sys) {
522 t_irc irc = failure;
523 vector<t_pppParam*> &params = _parlist.params();
524 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
525 t_pppParam *par = params[iPar];
526 if (par->type() == parType && par->prn().system() == sys) {
527 int ind = par->indexNew();
528 LOG << string(_epoTime) << " ADD NOISE TO " << par->toString() << endl;
529 par->setIndex(ind);
530 _QFlt(ind + 1, ind + 1) = par->sigma0() * par->sigma0();
531 irc = success;
532 }
533 }
534
535 return irc;
536}
537
538// Compute various DOP Values
539////////////////////////////////////////////////////////////////////////////
540void t_pppFilter::cmpDOP(const vector<t_pppSatObs*> &obsVector,
541 const QMap<char, t_pppRefSat*> &refSatMap) {
542
543 _dop.reset();
544
545 try {
546 const unsigned numPar = 4;
547 Matrix AA(obsVector.size(), numPar);
548 _numSat = 0;
549 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
550 t_pppSatObs *obs = obsVector[ii];
551 char sys = obs->prn().system();
552 t_prn refPrn = t_prn();
553 if (OPT->_refSatRequired) {
554 refPrn = refSatMap[sys]->prn();
555 }
556 if (obs->isValid() && !obs->outlier()) {
557 ++_numSat;
558 for (unsigned iPar = 0; iPar < numPar; iPar++) {
559 const t_pppParam *par = _parlist.params()[iPar];
560 AA[_numSat - 1][iPar] = par->partial(_epoTime, obs, t_lc::c1, refPrn);
561 }
562 }
563 }
564 if (_numSat < 4) {
565 return;
566 }
567 AA = AA.Rows(1, _numSat);
568 SymmetricMatrix NN;
569 NN << AA.t() * AA;
570 SymmetricMatrix QQ = NN.i();
571
572 _dop.H = sqrt(QQ(1, 1) + QQ(2, 2));
573 _dop.V = sqrt(QQ(3, 3));
574 _dop.P = sqrt(QQ(1, 1) + QQ(2, 2) + QQ(3, 3));
575 _dop.T = sqrt(QQ(4, 4));
576 _dop.G = sqrt(QQ(1, 1) + QQ(2, 2) + QQ(3, 3) + QQ(4, 4));
577 } catch (...) {
578 }
579}
580
581//
582////////////////////////////////////////////////////////////////////////////
583void t_pppFilter::predictCovCrdPart(const SymmetricMatrix &QFltOld) {
584
585 const vector<t_pppParam*> &params = _parlist.params();
586 if (params.size() < 3) {
587 return;
588 }
589
590 bool first = (params[0]->indexOld() < 0);
591
592 SymmetricMatrix Qneu(3);
593 Qneu = 0.0;
594 for (unsigned ii = 0; ii < 3; ii++) {
595 const t_pppParam *par = params[ii];
596 if (first) {
597 Qneu[ii][ii] = par->sigma0() * par->sigma0();
598 } else {
599 Qneu[ii][ii] = par->noise() * par->noise();
600 }
601 }
602
603 const t_pppStation *sta = PPP_CLIENT->staRover();
604 SymmetricMatrix Qxyz(3);
605 covariNEU_XYZ(Qneu, sta->ellApr().data(), Qxyz);
606
607 if (first) {
608 _QFlt.SymSubMatrix(1, 3) = Qxyz;
609 } else {
610 double dt = _epoTime - _firstEpoTime;
611 if (dt < OPT->_seedingTime) {
612 _QFlt.SymSubMatrix(1, 3) = QFltOld.SymSubMatrix(1, 3);
613 } else {
614 _QFlt.SymSubMatrix(1, 3) = QFltOld.SymSubMatrix(1, 3) + Qxyz;
615 }
616 }
617}
618
619//
620////////////////////////////////////////////////////////////////////////////
621void t_pppFilter::setStateVectorAndVarCovMatrix(const ColumnVector &xFltOld,
622 const SymmetricMatrix &QFltOld) {
623
624 const vector<t_pppParam*> &params = _parlist.params();
625 unsigned nPar = params.size();
626
627 _QFlt.ReSize(nPar);
628 _QFlt = 0.0;
629 _xFlt.ReSize(nPar);
630 _xFlt = 0.0;
631 _x0.ReSize(nPar);
632 _x0 = 0.0;
633
634 for (unsigned ii = 0; ii < nPar; ii++) {
635 t_pppParam *par1 = params[ii];
636 if (QFltOld.size() == 0) {
637 par1->resetIndex();
638 }
639 _x0[ii] = par1->x0();
640 int iOld = par1->indexOld();
641 if (iOld < 0) {
642 _QFlt[ii][ii] = par1->sigma0() * par1->sigma0(); // new parameter
643 } else {
644 _QFlt[ii][ii] = QFltOld[iOld][iOld] + par1->noise() * par1->noise();
645 _xFlt[ii] = xFltOld[iOld];
646 for (unsigned jj = 0; jj < ii; jj++) {
647 t_pppParam *par2 = params[jj];
648 int jOld = par2->indexOld();
649 if (jOld >= 0) {
650 _QFlt[ii][jj] = QFltOld(iOld + 1, jOld + 1);
651 }
652 }
653 }
654 }
655 predictCovCrdPart(QFltOld);
656}
657
658// Compute datum transformation
659////////////////////////////////////////////////////////////////////////////
660t_irc t_pppFilter::datumTransformation(
661 const QMap<char, t_pppRefSat*> &refSatMap) {
662
663 // get last epoch
664 t_pppObsPool::t_epoch *epoch = _obsPool->lastEpoch();
665 if (!epoch) {
666 LOG << "t_pppFilter::datumTransformation: !lastEpoch" << endl;
667 return failure;
668 }
669 _epoTime = epoch->epoTime();
670 LOG.setf(ios::fixed);
671 LOG << string(_epoTime) << " DATUM TRANSFORMATION " << endl;
672
673 vector<t_pppSatObs*> &allObs = epoch->obsVector();
674
675 const QMap<char, t_pppRefSat*> &refSatMapLastEpoch = epoch->refSatMap();
676
677 bool pseudoObsIono = epoch->pseudoObsIono();
678
679 // reset old and set new refSats in last epoch (ambiguities/GIM)
680 // =============================================================
681 if (resetRefSatellitesLastEpoch(allObs, refSatMap, refSatMapLastEpoch)
682 != true) {
683 LOG << "datumTransformation: resetRefSatellitesLastEpoch != success"
684 << endl;
685 return failure;
686 }
687
688 if (OPT->_obsModelType == OPT->UncombPPP) {
689 _obsPool->putEpoch(_epoTime, allObs, pseudoObsIono, refSatMap);
690 return success;
691 }
692
693 // set AA2
694 // =======
695 if (_parlist.set(_epoTime, allObs, refSatMap) != success) {
696 return failure;
697 }
698
699#ifdef BNC_DEBUG_PPP
700 _parlist.printParams(_epoTime);
701#endif
702
703 const QList<char> &usedSystems = _parlist.usedSystems();
704 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
705 char sys = usedSystems[iSys];
706 t_prn refPrn = refSatMap[sys]->prn();
707 vector<t_pppSatObs*> obsVector;
708 for (unsigned jj = 0; jj < allObs.size(); jj++) {
709 if (allObs[jj]->prn().system() == sys) {
710 allObs[jj]->resetOutlier();
711 obsVector.push_back(allObs[jj]);
712 }
713 }
714 if (iSys == 0) {
715 _datumTrafo->setFirstSystem(sys);
716 }
717 vector<t_lc::type> LCs = OPT->LCs(sys);
718 unsigned usedLCs = LCs.size();
719 if (OPT->_pseudoObsIono && !pseudoObsIono) {
720 usedLCs -= 1; // GIM not used
721 }
722 // max Obs
723 unsigned maxObs = obsVector.size() * usedLCs;
724
725 if (OPT->_pseudoObsIono && pseudoObsIono) {
726 maxObs -= 1; // pseudo obs iono with respect to refSat
727 }
728
729 const vector<t_pppParam*> &params = _parlist.params();
730 unsigned nPar = _parlist.nPar();
731
732 Matrix AA(maxObs, nPar);
733
734 // Real Observations
735 // -----------------
736 int iObs = -1;
737 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
738 t_pppSatObs *obs = obsVector[ii];
739 for (unsigned jj = 0; jj < usedLCs; jj++) {
740 const t_lc::type tLC = LCs[jj];
741 if (tLC == t_lc::GIM) {
742 continue;
743 }
744 ++iObs;
745 for (unsigned iPar = 0; iPar < nPar; iPar++) {
746 const t_pppParam *par = params[iPar];
747 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
748 }
749 }
750 }
751
752 if (!iObs) {
753 continue;
754 }
755 _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;
756 if (_datumTrafo->prepareAA(AA.SubMatrix(1, iObs + 1, 1, nPar), 2)
757 != success) {
758 return failure;
759 }
760 }
761 _datumTrafo->updateNumObs();
762
763 // Datum Transformation
764 // ====================
765#ifdef BNC_DEBUG_PPP
766 //LOG << "AA1\n"; _datumTrafo->printMatrix(_datumTrafo->AA1(), _datumTrafo->numObs(), _datumTrafo->numPar());
767 //LOG << "AA2\n"; _datumTrafo->printMatrix(_datumTrafo->AA2(), _datumTrafo->numObs(), _datumTrafo->numPar());
768#endif
769 if (_datumTrafo->computeTrafoMatrix() != success) {
770 return failure;
771 }
772#ifdef BNC_DEBUG_PPP
773 //LOG << "D21" << endl; _datumTrafo->printMatrix(_datumTrafo->D21(), _datumTrafo->numObs(), _datumTrafo->numPar());
774#endif
775 ColumnVector xFltOld = _xFlt;
776 SymmetricMatrix QFltOld = _QFlt;
777
778 _QFlt << _datumTrafo->D21() * QFltOld * _datumTrafo->D21().t();
779 _xFlt = _datumTrafo->D21() * xFltOld;
780
781#ifdef BNC_DEBUG_PPP
782 LOG << "xFltOld:\n" << xFltOld << endl;
783 LOG << "xFlt :\n" << _xFlt << endl;
784#endif
785
786 // Reset Ambiguities after Datum Transformation
787 // ============================================
788 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
789 char sys = usedSystems[iSys];
790 t_prn refPrnOld = refSatMapLastEpoch[sys]->prn();
791 t_prn refPrnNew = refSatMap[sys]->prn();
792 if (refPrnNew != refPrnOld) {
793 resetAmb(refPrnOld, allObs);/*
794 if (resetAmb(refPrnOld, allObs) == success) {
795 if (OPT->_obsModelType == OPT->DCMcodeBias) {
796 addNoiseToPar(t_pppParam::ion, sys);
797 } else if (OPT->_obsModelType == OPT->DCMphaseBias) {
798 if (sys == 'G') {
799 addNoiseToPar(t_pppParam::pBiasG1, sys);
800 addNoiseToPar(t_pppParam::pBiasG2, sys);
801 } else if (sys == 'R') {
802 addNoiseToPar(t_pppParam::pBiasR1, sys);
803 addNoiseToPar(t_pppParam::pBiasR2, sys);
804 } else if (sys == 'E') {
805 addNoiseToPar(t_pppParam::pBiasE1, sys);
806 addNoiseToPar(t_pppParam::pBiasE2, sys);
807 } else if (sys == 'C') {
808 addNoiseToPar(t_pppParam::pBiasC1, sys);
809 addNoiseToPar(t_pppParam::pBiasC2, sys);
810 }
811 }
812 }*/
813 }
814 }
815
816 // switch AA2 to AA1
817 // =================
818 _datumTrafo->switchAA();
819
820 _obsPool->putEpoch(_epoTime, allObs, pseudoObsIono, refSatMap);
821
822 return success;
823}
824
825// Init datum transformation
826////////////////////////////////////////////////////////////////////////////
827void t_pppFilter::initDatumTransformation(
828 const std::vector<t_pppSatObs*> &allObs, bool pseudoObsIono) {
829 unsigned trafoObs = 0;
830 const QList<char> &usedSystems = _parlist.usedSystems();
831 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
832 char sys = usedSystems[iSys];
833 int satNum = 0;
834 for (unsigned jj = 0; jj < allObs.size(); jj++) {
835 if (allObs[jj]->prn().system() == sys) {
836 satNum++;
837 }
838 }
839 // all LCs
840 unsigned realUsedLCs = OPT->LCs(sys).size();
841 // exclude pseudo obs GIM
842 if (OPT->_pseudoObsIono && !pseudoObsIono) {
843 realUsedLCs -= 1;
844 }
845
846 trafoObs += satNum * realUsedLCs;
847
848 if (OPT->_pseudoObsIono && pseudoObsIono) {
849 trafoObs -= 1; // pseudo obs iono with respect to refSat
850 }
851 }
852 _datumTrafo->setNumObs(trafoObs);
853 _datumTrafo->setNumPar(_parlist.nPar());
854 _datumTrafo->initAA();
855}
856
857//
858//////////////////////////////////////////////////////////////////////////////
859bool t_pppFilter::resetRefSatellitesLastEpoch(
860 std::vector<t_pppSatObs*> &obsVector,
861 const QMap<char, t_pppRefSat*> &refSatMap,
862 const QMap<char, t_pppRefSat*> &refSatMapLastEpoch) {
863 bool resetRefSat;
864 // reference satellite definition per system
865 const QList<char> &usedSystems = _parlist.usedSystems();
866 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
867 resetRefSat = false;
868 char sys = usedSystems[iSys];
869 t_prn newPrn = refSatMap[sys]->prn();
870 t_prn oldPrn = refSatMapLastEpoch[sys]->prn();
871#ifdef BNC_DEBUG_PPP
872 if (oldPrn != newPrn) {
873 LOG << "oldRef: " << oldPrn.toString() << " => newRef " << newPrn.toString() << endl;
874 }
875#endif
876 vector<t_pppSatObs*>::iterator it = obsVector.begin();
877 while (it != obsVector.end()) {
878 t_pppSatObs *satObs = *it;
879 if (satObs->prn() == newPrn) {
880 resetRefSat = true;
881 satObs->setAsReference();
882 } else if (satObs->prn() == oldPrn) {
883 satObs->resetReference();
884 }
885 it++;
886 }
887 if (!resetRefSat) {
888 _obsPool->setRefSatChangeRequired(sys, true);
889 return resetRefSat;
890 }
891 }
892 return resetRefSat;
893}
Note: See TracBrowser for help on using the repository browser.