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

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