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

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