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

Last change on this file since 9972 was 9972, checked in by stuerze, 16 months ago

minor changes

  • Property svn:keywords set to Author Date Id Rev URL;svn:eol-style=native
  • Property svn:mime-type set to text/plain
File size: 27.7 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 parameter exists
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 {
357 obs->setOutlier();
358 }
359 } else { // fin-processing
360 LOG << epoTimeStr << " Outlier " << t_lc::toString(maxOutlierLC) << ' '
361 << obs->prn().toString() << ' ' << setw(8) << setprecision(4)
362 << maxOutlier << endl;
363 if (par) {
364 if ( par->ambResetCandidate() ||
365 (OPT->_obsModelType == OPT->DCMcodeBias ||
366 OPT->_obsModelType == OPT->DCMphaseBias) ) {
367 resetAmb(par->prn(), obsVector, &QSav, &xSav);
368 }
369 else {
370 par->setAmbResetCandidate();
371 obs->setOutlier();
372 }
373 }
374 else {
375 obs->setOutlier();
376 }
377 }
378 }
379 // Print Residuals
380 // ---------------
381 else {
382 if (!preProcessing) {
383 for (unsigned jj = 0; jj < LCs.size(); jj++) {
384 for (unsigned ii = 0; ii < usedObs.size(); ii++) {
385 const t_lc::type tLC = usedTypes[ii];
386 t_pppSatObs *obs = usedObs[ii];
387 if (tLC == LCs[jj]) {
388 obs->setRes(tLC, vv[ii]);
389 LOG << epoTimeStr << " RES " << left << setw(3)
390 << t_lc::toString(tLC) << right << ' '
391 << obs->prn().toString();
392 LOG << setw(9) << setprecision(4) << vv[ii] << endl;
393 }
394 }
395 }
396 }
397 break;
398 }
399 }
400 return success;
401}
402
403// Cycle-Slip Detection
404////////////////////////////////////////////////////////////////////////////
405t_irc t_pppFilter::detectCycleSlips(const vector<t_lc::type> &LCs,
406 const vector<t_pppSatObs*> &obsVector, const t_prn &refPrn,
407 bool preProcessing) {
408 const double SLIP = 100.0;
409 char sys = refPrn.system();
410 string epoTimeStr = string(_epoTime);
411 const vector<t_pppParam*> &params = _parlist.params();
412 unsigned nPar = _parlist.nPar();
413
414 for (unsigned ii = 0; ii < LCs.size(); ii++) {
415 const t_lc::type &tLC = LCs[ii];
416 if (t_lc::includesPhase(tLC)) {
417 for (unsigned iObs = 0; iObs < obsVector.size(); iObs++) {
418 const t_pppSatObs *obs = obsVector[iObs];
419
420 // Check set Slips and Jump Counters
421 // ---------------------------------
422 bool slip = false;
423
424 // in pre-processing only the reference satellite has to be checked
425 if (preProcessing && obs->prn() != refPrn) {
426 continue;
427 }
428
429 if (obs->slip()) {
430 LOG << epoTimeStr << "cycle slip set (obs) " << obs->prn().toString()
431 << endl;
432 slip = true;
433 }
434
435 if (_slips[obs->prn()]._obsSlipCounter != -1
436 && _slips[obs->prn()]._obsSlipCounter != obs->slipCounter()) {
437 LOG << epoTimeStr << "cycle slip set (obsSlipCounter) "
438 << obs->prn().toString() << endl;
439 slip = true;
440 }
441 if (!preProcessing) {
442 _slips[obs->prn()]._obsSlipCounter = obs->slipCounter();
443 }
444 if (_slips[obs->prn()]._biasJumpCounter != -1
445 && _slips[obs->prn()]._biasJumpCounter != obs->biasJumpCounter()) {
446 LOG << epoTimeStr << "cycle slip set (biasJumpCounter) "
447 << 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 } else {
459 resetAmb(obs->prn(), obsVector);
460 }
461 }
462 // Check Pre-Fit Residuals
463 // -----------------------
464 else {
465 if (refPrn != t_prn()) {
466 return success;
467 }
468 ColumnVector AA(nPar);
469 for (unsigned iPar = 0; iPar < nPar; iPar++) {
470 const t_pppParam *par = params[iPar];
471 AA[iPar] = par->partial(_epoTime, obs, tLC, refPrn);
472 }
473 double ll = obs->obsValue(tLC) - obs->cmpValue(tLC)
474 - 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)
479 << setprecision(4) << vv << endl;
480 if (preProcessing) {
481 _obsPool->setRefSatChangeRequired(sys, true);
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;
507 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::addNoiseToPar(t_pppParam::e_type parType, char sys) {
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() == parType && par->prn().system() == sys) {
540 int ind = par->indexNew();
541 LOG << string(_epoTime) << " ADD NOISE TO " << par->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;
582 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 } 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);
606 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 } 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 } else {
623 double dt = _epoTime - _firstEpoTime;
624 if (dt < OPT->_seedingTime) {
625 _QFlt.SymSubMatrix(1, 3) = QFltOld.SymSubMatrix(1, 3);
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);
641 _QFlt = 0.0;
642 _xFlt.ReSize(nPar);
643 _xFlt = 0.0;
644 _x0.ReSize(nPar);
645 _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 } 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(
674 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)
695 != true) {
696 LOG << "datumTransformation: resetRefSatellitesLastEpoch != success"
697 << endl;
698 return failure;
699 }
700
701 if (OPT->_obsModelType == OPT->UncombPPP) {
702 _obsPool->putEpoch(_epoTime, allObs, pseudoObsIono, refSatMap);
703 return success;
704 }
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 allObs[jj]->resetOutlier();
724 obsVector.push_back(allObs[jj]);
725 }
726 }
727 if (iSys == 0) {
728 _datumTrafo->setFirstSystem(sys);
729 }
730 vector<t_lc::type> LCs = OPT->LCs(sys);
731 unsigned usedLCs = LCs.size();
732 if (OPT->_pseudoObsIono && !pseudoObsIono) {
733 usedLCs -= 1; // GIM not used
734 }
735 // max Obs
736 unsigned maxObs = obsVector.size() * usedLCs;
737
738 if (OPT->_pseudoObsIono && pseudoObsIono) {
739 maxObs -= 1; // pseudo obs iono with respect to refSat
740 }
741
742 const vector<t_pppParam*> &params = _parlist.params();
743 unsigned nPar = _parlist.nPar();
744
745 Matrix AA(maxObs, nPar);
746
747 // Real Observations
748 // -----------------
749 int iObs = -1;
750 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
751 t_pppSatObs *obs = obsVector[ii];
752 for (unsigned jj = 0; jj < usedLCs; jj++) {
753 const t_lc::type tLC = LCs[jj];
754 if (tLC == t_lc::GIM) {
755 continue;
756 }
757 ++iObs;
758 for (unsigned iPar = 0; iPar < nPar; iPar++) {
759 const t_pppParam *par = params[iPar];
760 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
761 }
762 }
763 }
764
765 if (!iObs) {
766 continue;
767 }
768 _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;
769 if (_datumTrafo->prepareAA(AA.SubMatrix(1, iObs + 1, 1, nPar), 2)
770 != success) {
771 return failure;
772 }
773 }
774 _datumTrafo->updateNumObs();
775
776 // Datum Transformation
777 // ====================
778#ifdef BNC_DEBUG_PPP
779 //LOG << "AA1\n"; _datumTrafo->printMatrix(_datumTrafo->AA1(), _datumTrafo->numObs(), _datumTrafo->numPar());
780 //LOG << "AA2\n"; _datumTrafo->printMatrix(_datumTrafo->AA2(), _datumTrafo->numObs(), _datumTrafo->numPar());
781#endif
782 if (_datumTrafo->computeTrafoMatrix() != success) {
783 return failure;
784 }
785#ifdef BNC_DEBUG_PPP
786 //LOG << "D21" << endl; _datumTrafo->printMatrix(_datumTrafo->D21(), _datumTrafo->numObs(), _datumTrafo->numPar());
787#endif
788 ColumnVector xFltOld = _xFlt;
789 SymmetricMatrix QFltOld = _QFlt;
790
791 _QFlt << _datumTrafo->D21() * QFltOld * _datumTrafo->D21().t();
792 _xFlt = _datumTrafo->D21() * xFltOld;
793
794#ifdef BNC_DEBUG_PPP
795 LOG << "xFltOld:\n" << xFltOld << endl;
796 LOG << "xFlt :\n" << _xFlt << endl;
797#endif
798
799 // Reset Ambiguities after Datum Transformation
800 // ============================================
801 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
802 char sys = usedSystems[iSys];
803 t_prn refPrnOld = refSatMapLastEpoch[sys]->prn();
804 t_prn refPrnNew = refSatMap[sys]->prn();
805 if (refPrnNew != refPrnOld) {
806 resetAmb(refPrnOld, allObs);/*
807 if (resetAmb(refPrnOld, allObs) == success) {
808 if (OPT->_obsModelType == OPT->DCMcodeBias) {
809 addNoiseToPar(t_pppParam::ion, sys);
810 } else if (OPT->_obsModelType == OPT->DCMphaseBias) {
811 if (sys == 'G') {
812 addNoiseToPar(t_pppParam::pBiasG1, sys);
813 addNoiseToPar(t_pppParam::pBiasG2, sys);
814 } else if (sys == 'R') {
815 addNoiseToPar(t_pppParam::pBiasR1, sys);
816 addNoiseToPar(t_pppParam::pBiasR2, sys);
817 } else if (sys == 'E') {
818 addNoiseToPar(t_pppParam::pBiasE1, sys);
819 addNoiseToPar(t_pppParam::pBiasE2, sys);
820 } else if (sys == 'C') {
821 addNoiseToPar(t_pppParam::pBiasC1, sys);
822 addNoiseToPar(t_pppParam::pBiasC2, sys);
823 }
824 }
825 }*/
826 }
827 }
828
829 // switch AA2 to AA1
830 // =================
831 _datumTrafo->switchAA();
832
833 _obsPool->putEpoch(_epoTime, allObs, pseudoObsIono, refSatMap);
834
835 return success;
836}
837
838// Init datum transformation
839////////////////////////////////////////////////////////////////////////////
840void t_pppFilter::initDatumTransformation(
841 const std::vector<t_pppSatObs*> &allObs, bool pseudoObsIono) {
842 unsigned trafoObs = 0;
843 const QList<char> &usedSystems = _parlist.usedSystems();
844 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
845 char sys = usedSystems[iSys];
846 int satNum = 0;
847 for (unsigned jj = 0; jj < allObs.size(); jj++) {
848 if (allObs[jj]->prn().system() == sys) {
849 satNum++;
850 }
851 }
852 // all LCs
853 unsigned realUsedLCs = OPT->LCs(sys).size();
854 // exclude pseudo obs GIM
855 if (OPT->_pseudoObsIono && !pseudoObsIono) {
856 realUsedLCs -= 1;
857 }
858
859 trafoObs += satNum * realUsedLCs;
860
861 if (OPT->_pseudoObsIono && pseudoObsIono) {
862 trafoObs -= 1; // pseudo obs iono with respect to refSat
863 }
864 }
865 _datumTrafo->setNumObs(trafoObs);
866 _datumTrafo->setNumPar(_parlist.nPar());
867 _datumTrafo->initAA();
868}
869
870//
871//////////////////////////////////////////////////////////////////////////////
872bool t_pppFilter::resetRefSatellitesLastEpoch(
873 std::vector<t_pppSatObs*> &obsVector,
874 const QMap<char, t_pppRefSat*> &refSatMap,
875 const QMap<char, t_pppRefSat*> &refSatMapLastEpoch) {
876 bool resetRefSat;
877 // reference satellite definition per system
878 const QList<char> &usedSystems = _parlist.usedSystems();
879 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
880 resetRefSat = false;
881 char sys = usedSystems[iSys];
882 t_prn newPrn = refSatMap[sys]->prn();
883 t_prn oldPrn = refSatMapLastEpoch[sys]->prn();
884#ifdef BNC_DEBUG_PPP
885 if (oldPrn != newPrn) {
886 LOG << "oldRef: " << oldPrn.toString() << " => newRef " << newPrn.toString() << endl;
887 }
888#endif
889 vector<t_pppSatObs*>::iterator it = obsVector.begin();
890 while (it != obsVector.end()) {
891 t_pppSatObs *satObs = *it;
892 if (satObs->prn() == newPrn) {
893 resetRefSat = true;
894 satObs->setAsReference();
895 } else if (satObs->prn() == oldPrn) {
896 satObs->resetReference();
897 }
898 it++;
899 }
900 if (!resetRefSat) {
901 _obsPool->setRefSatChangeRequired(sys, true);
902 return resetRefSat;
903 }
904 }
905 return resetRefSat;
906}
Note: See TracBrowser for help on using the repository browser.