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

Last change on this file since 10014 was 10014, checked in by stuerze, 13 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.9 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 const QList<char> &usedSystems = _parlist.usedSystems();
75 //--
76 // Set Parameters
77 if (_parlist.set(_epoTime, allObs, refSatMap) != success) {
78 return failure;
79 }
80
81 // Status Vector, Variance-Covariance Matrix
82 // -----------------------------------------
83 ColumnVector xFltOld = _xFlt;
84 SymmetricMatrix QFltOld = _QFlt;
85 bool setNeuNoiseToZero = false;
86 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
87 char sys = usedSystems[iSys];
88 int num = 0;
89 for (unsigned jj = 0; jj < allObs.size(); jj++) {
90 if (allObs[jj]->prn().system() == sys) {
91 ++num;
92 }
93 }
94 if (num < OPT->_minObs) {
95 setNeuNoiseToZero = true;
96 }
97 }
98 setStateVectorAndVarCovMatrix(xFltOld, QFltOld, setNeuNoiseToZero);
99
100 // Pre-Process Satellite Systems separately
101 // ----------------------------------------
102 bool preProcessing = false;
103 if (OPT->_obsModelType == OPT->DCMcodeBias ||
104 OPT->_obsModelType == OPT->DCMphaseBias) {
105 preProcessing = true;
106 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
107 char sys = usedSystems[iSys];
108 _refPrn.set(sys, 0);
109 if (OPT->_refSatRequired) {
110 _refPrn = refSatMap[sys]->prn();
111 }
112 vector<t_pppSatObs*> obsVector;
113 for (unsigned jj = 0; jj < allObs.size(); jj++) {
114 if (allObs[jj]->prn().system() == sys) {
115 obsVector.push_back(allObs[jj]);
116 }
117 }
118 if (iSys == 0) {
119 _datumTrafo->setFirstSystem(sys);
120 }
121 if (processSystem(OPT->LCs(sys), obsVector, _refPrn,
122 epoch->pseudoObsIono(), preProcessing) != success) {
123 LOG << sys << ": processSystem != success (pre-processing)" << endl;
124 _xFlt = xFltOld;
125 _QFlt = QFltOld;
126 _obsPool->deleteLastEpoch();
127 restoreState(2);
128 return failure;
129 }
130 }
131 // refSat change required?
132 // -----------------------
133 if (_obsPool->refSatChangeRequired()) {
134 _xFlt = xFltOld;
135 _QFlt = QFltOld;
136 return success;
137 } else if (!_obsPool->refSatChangeRequired()) {
138 initDatumTransformation(allObs, epoch->pseudoObsIono());
139 }
140 }
141
142 // Process Satellite Systems separately
143 // ------------------------------------
144 preProcessing = false;
145 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
146 char sys = usedSystems[iSys];
147 _refPrn.set(sys, 0);
148 if (OPT->_refSatRequired) {
149 _refPrn = refSatMap[sys]->prn();
150 }
151 unsigned int num = 0;
152 vector<t_pppSatObs*> obsVector;
153 for (unsigned jj = 0; jj < allObs.size(); jj++) {
154 if (allObs[jj]->prn().system() == sys) {
155 obsVector.push_back(allObs[jj]);
156 ++num;
157 }
158 }
159 if (iSys == 0 && OPT->_obsModelType == OPT->UncombPPP) {
160 _datumTrafo->setFirstSystem(sys);
161 }
162 LOG << epoTimeStr << " SATNUM " << sys << ' ' << right << setw(2) << num
163 << endl;
164 if (processSystem(OPT->LCs(sys), obsVector, _refPrn, epoch->pseudoObsIono(),
165 preProcessing) != success) {
166 LOG << "processSystem != success (fin-processing)" << endl;
167 if (OPT->_obsModelType == OPT->DCMcodeBias ||
168 OPT->_obsModelType == OPT->DCMphaseBias) {
169 _xFlt = xFltOld;
170 _QFlt = QFltOld;
171 _obsPool->deleteLastEpoch();
172 restoreState(3);
173 }
174 return failure;
175 }
176 }
177
178 // close epoch processing
179 // ----------------------
180 cmpDOP(allObs, refSatMap);
181 _parlist.printResult(_epoTime, _QFlt, _xFlt);
182 _lastEpoTimeOK = _epoTime; // remember time of last successful epoch processing
183 return success;
184}
185
186// Process Selected LCs
187////////////////////////////////////////////////////////////////////////////
188t_irc t_pppFilter::processSystem(const vector<t_lc::type> &LCs,
189 const vector<t_pppSatObs*> &obsVector, const t_prn &refPrn,
190 bool pseudoObsIonoAvailable, bool preProcessing) {
191 LOG.setf(ios::fixed);
192 char sys = refPrn.system();
193
194 // Detect Cycle Slips
195 // ------------------
196 if (detectCycleSlips(LCs, obsVector, refPrn, preProcessing) != success) {
197 return failure;
198 }
199 if (preProcessing && _obsPool->refSatChangeRequired(sys)) {
200 return success;
201 }
202
203 ColumnVector xSav = _xFlt;
204 SymmetricMatrix QSav = _QFlt;
205 string epoTimeStr = string(_epoTime);
206 const vector<t_pppParam*> &params = _parlist.params();
207 unsigned nPar = _parlist.nPar();
208
209 unsigned usedLCs = LCs.size();
210 if (OPT->_pseudoObsIono && !pseudoObsIonoAvailable) {
211 usedLCs -= 1; // GIM not used
212 }
213 // max Obs
214 unsigned maxObs = obsVector.size() * usedLCs;
215
216 if (OPT->_pseudoObsIono && pseudoObsIonoAvailable) {
217 maxObs -= 1; // pseudo obs iono with respect to refSat
218 }
219
220 // Outlier Detection Loop
221 // ----------------------
222 for (unsigned iOutlier = 0; iOutlier < maxObs; iOutlier++) {
223
224 if (iOutlier > 0) {
225 _xFlt = xSav;
226 _QFlt = QSav;
227 }
228
229 // First-Design Matrix, Terms Observed-Computed, Weight Matrix
230 // -----------------------------------------------------------
231 Matrix AA(maxObs, nPar);
232 ColumnVector ll(maxObs);
233 DiagonalMatrix PP(maxObs);
234 PP = 0.0;
235
236 int iObs = -1;
237 vector<t_pppSatObs*> usedObs;
238 vector<t_lc::type> usedTypes;
239
240 // Real Observations
241 // =================
242 double nSat = 0;
243 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
244 t_pppSatObs *obs = obsVector[ii];
245 if (iOutlier == 0 && !preProcessing) {
246 obs->resetOutlier();
247 }
248 if (!obs->outlier()) {
249 nSat++;
250 for (unsigned jj = 0; jj < usedLCs; jj++) {
251 const t_lc::type tLC = LCs[jj];
252 if (tLC == t_lc::GIM) {
253 continue;
254 }
255 ++iObs;
256 usedObs.push_back(obs);
257 usedTypes.push_back(tLC);
258 for (unsigned iPar = 0; iPar < nPar; iPar++) {
259 const t_pppParam *par = params[iPar];
260 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
261 }
262 ll[iObs] = obs->obsValue(tLC) - obs->cmpValue(tLC)
263 - DotProduct(_x0, AA.Row(iObs + 1));
264 PP[iObs] = 1.0 / (obs->sigma(tLC) * obs->sigma(tLC));
265 }
266 }
267 }
268
269 // Check number of observations
270 // ----------------------------
271 if (iObs == -1) {
272 LOG << " number of observations == " << iObs + 1 << "\n";
273 if (preProcessing) {
274 _obsPool->setRefSatChangeRequired(sys, true);
275 return success;
276 }
277 return failure;
278 }
279
280 if ((!iOutlier) &&
281 (OPT->_obsModelType == OPT->DCMcodeBias ||
282 OPT->_obsModelType == OPT->DCMphaseBias) && (!preProcessing)) {
283 _datumTrafo->updateIndices(sys, iObs + 1);
284 _datumTrafo->prepareAA(AA.SubMatrix(1, iObs + 1, 1, _parlist.nPar()), 1);
285 }
286
287 // Pseudo Obs Iono
288 // ================
289 if (OPT->_pseudoObsIono && pseudoObsIonoAvailable) {
290 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
291 t_pppSatObs *obs = obsVector[ii];
292 if (!obs->outlier()) {
293 for (unsigned jj = 0; jj < usedLCs; jj++) {
294 const t_lc::type tLC = LCs[jj];
295 if (tLC == t_lc::GIM && !obs->isReference()) {
296 ++iObs;
297 } else {
298 continue;
299 }
300 usedObs.push_back(obs);
301 usedTypes.push_back(tLC);
302 for (unsigned iPar = 0; iPar < nPar; iPar++) {
303 const t_pppParam *par = params[iPar];
304 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
305 }
306 ll[iObs] = obs->obsValue(tLC) - obs->cmpValue(tLC)
307 - DotProduct(_x0, AA.Row(iObs + 1));
308 PP[iObs] = 1.0 / (obs->sigma(tLC) * obs->sigma(tLC));
309 }
310 }
311 }
312 }
313
314 // Truncate matrices
315 // -----------------
316 AA = AA.Rows(1, iObs + 1);
317 ll = ll.Rows(1, iObs + 1);
318 PP = PP.SymSubMatrix(1, iObs + 1);
319
320 // Kalman update step
321 // ------------------
322 kalman(AA, ll, PP, _QFlt, _xFlt);
323
324 // Check Residuals
325 // ---------------
326 ColumnVector vv = AA * _xFlt - ll;
327 double maxOutlier = 0.0;
328 int maxOutlierIndex = -1;
329 t_lc::type maxOutlierLC = t_lc::dummy;
330 for (unsigned ii = 0; ii < usedObs.size(); ii++) {
331 const t_lc::type tLC = usedTypes[ii];
332 double res = fabs(vv[ii]);
333 if (res > usedObs[ii]->maxRes(tLC)) {
334 if (res > fabs(maxOutlier)) {
335 maxOutlier = vv[ii];
336 maxOutlierIndex = ii;
337 maxOutlierLC = tLC;
338 }
339 }
340 }
341
342 // Mark outlier or break outlier detection loop
343 // --------------------------------------------
344 if (maxOutlierIndex > -1) {
345 t_pppSatObs *obs = usedObs[maxOutlierIndex];
346 t_pppParam *par = 0;
347 for (unsigned iPar = 0; iPar < nPar; iPar++) {
348 t_pppParam *hlp = params[iPar];
349 if (hlp->type() == t_pppParam::amb &&
350 hlp->prn() == obs->prn() &&
351 hlp->tLC() == usedTypes[maxOutlierIndex]) {
352 par = hlp;
353 }
354 }
355 if (preProcessing) {
356 if (obs->prn() == refPrn) {
357 LOG << epoTimeStr << " Outlier ("
358 << ((preProcessing) ? "pre-processing) " : "fin-processing) ")
359 << t_lc::toString(maxOutlierLC) << ' ' << obs->prn().toString()
360 << ' ' << setw(8) << setprecision(4) << maxOutlier << endl;
361 _obsPool->setRefSatChangeRequired(sys, true);
362 break;
363 } else {
364 obs->setOutlier();
365 }
366 } else { // fin-processing
367 LOG << epoTimeStr << " Outlier " << t_lc::toString(maxOutlierLC) << ' '
368 << obs->prn().toString() << ' ' << setw(8) << setprecision(4)
369 << maxOutlier << endl;
370 if (par) {
371 if (par->ambResetCandidate() ||
372 OPT->_obsModelType == OPT->DCMcodeBias ||
373 OPT->_obsModelType == OPT->DCMphaseBias) {
374 resetAmb(par->prn(), obsVector, maxOutlierLC, &QSav, &xSav);
375 }
376 else {
377 par->setAmbResetCandidate();
378 obs->setOutlier();
379 }
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) << " DATUM 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
717 const QList<char> &usedSystems = _parlist.usedSystems();
718 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
719 char sys = usedSystems[iSys];
720 t_prn refPrn = refSatMap[sys]->prn();
721 vector<t_pppSatObs*> obsVector;
722 for (unsigned jj = 0; jj < allObs.size(); jj++) {
723 if (allObs[jj]->prn().system() == sys) {
724 allObs[jj]->resetOutlier();
725 obsVector.push_back(allObs[jj]);
726 }
727 }
728 if (iSys == 0) {
729 _datumTrafo->setFirstSystem(sys);
730 }
731 vector<t_lc::type> LCs = OPT->LCs(sys);
732 unsigned usedLCs = LCs.size();
733 if (OPT->_pseudoObsIono && !pseudoObsIono) {
734 usedLCs -= 1; // GIM not used
735 }
736 // max Obs
737 unsigned maxObs = obsVector.size() * usedLCs;
738
739 if (OPT->_pseudoObsIono && pseudoObsIono) {
740 maxObs -= 1; // pseudo obs iono with respect to refSat
741 }
742
743 const vector<t_pppParam*> &params = _parlist.params();
744 unsigned nPar = _parlist.nPar();
745
746 Matrix AA(maxObs, nPar); AA = 0.0; cout << "AA Ncols/Nrows: " << AA.Ncols() << "/" << AA.Nrows() << " nPar: " << nPar << endl;
747
748 // Real Observations
749 // -----------------
750 int iObs = -1;
751 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
752 t_pppSatObs *obs = obsVector[ii];
753 for (unsigned jj = 0; jj < usedLCs; jj++) {
754 const t_lc::type tLC = LCs[jj];
755 if (tLC == t_lc::GIM) {
756 continue;
757 }
758 ++iObs;
759 for (unsigned iPar = 0; iPar < nPar; iPar++) {
760 const t_pppParam *par = params[iPar];
761 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
762 }
763 }
764 }
765
766 if (!(iObs+1)) {
767 continue;
768 }
769 _datumTrafo->updateIndices(sys, iObs + 1);
770
771 if (_datumTrafo->prepareAA(AA.SubMatrix(1, iObs + 1, 1, nPar), 2) != success) {
772 return failure;
773 }
774 }
775 _datumTrafo->updateNumObs();
776
777 // Datum Transformation
778 // ====================
779 if (_datumTrafo->computeTrafoMatrix() != success) {
780 return failure;
781 }
782
783 ColumnVector xFltOld = _xFlt;
784 SymmetricMatrix QFltOld = _QFlt;
785
786 _QFlt << _datumTrafo->D21() * QFltOld * _datumTrafo->D21().t();
787 _xFlt = _datumTrafo->D21() * xFltOld;
788
789#ifdef BNC_DEBUG_PPP
790 LOG << "xFltOld:\n" << xFltOld << endl;
791 LOG << "xFlt :\n" << _xFlt << endl;
792#endif
793
794 // Reset Ambiguities after Datum Transformation
795 // ============================================
796 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
797 char sys = usedSystems[iSys];
798 vector<t_lc::type> LCs = OPT->LCs(sys);
799 unsigned usedLCs = LCs.size();
800 if (OPT->_pseudoObsIono && !pseudoObsIono) {
801 usedLCs -= 1; // GIM not used
802 }
803 t_prn refPrnOld = refSatMapLastEpoch[sys]->prn();
804 t_prn refPrnNew = refSatMap[sys]->prn();
805 if (refPrnNew != refPrnOld) {
806 for (unsigned jj = 0; jj < usedLCs; jj++) {
807 const t_lc::type tLC = LCs[jj];
808 if (tLC == t_lc::GIM) {
809 continue;
810 }
811 resetAmb(refPrnOld, allObs, tLC);
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.