GeometryFreeCycleSlipDetector.java

  1. /* Copyright 2002-2025 CS GROUP
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.estimation.measurements.gnss;

  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import java.util.Map;

  21. import org.hipparchus.fitting.PolynomialCurveFitter;
  22. import org.hipparchus.fitting.WeightedObservedPoint;
  23. import org.hipparchus.util.FastMath;
  24. import org.orekit.files.rinex.observation.ObservationDataSet;
  25. import org.orekit.gnss.GnssSignal;
  26. import org.orekit.gnss.MeasurementType;
  27. import org.orekit.gnss.SatelliteSystem;
  28. import org.orekit.time.AbsoluteDate;


  29. /**
  30.  * Geometry free cycle slip detectors.
  31.  * The detector is based the algorithm given in <a
  32.  * href="https://gssc.esa.int/navipedia/index.php/Detector_based_in_carrier_phase_data:_The_geometry-free_combination">
  33.  * Detector based in carrier phase data: The geometry-free combination</a> by Zornoza and M. Hernández-Pajares. Within this class
  34.  * a second order polynomial is used to smooth the data. We consider a cycle-slip occurring if the current measurement is  too
  35.  * far from the one predicted with the polynomial.
  36.  * <p>
  37.  * For building the detector, one should give a threshold and a gap time limit.
  38.  * After construction of the detectors, one can have access to a List of CycleData. Each CycleDate represents
  39.  * a link between the station (define by the RINEX file) and a satellite at a specific frequency. For each cycle data,
  40.  * one has access to the begin and end of availability, and a sorted set which contains all the date at which
  41.  * cycle-slip have been detected
  42.  * </p>
  43.  * @author David Soulard
  44.  * @author Bryan Cazabonne
  45.  * @since 10.2
  46.  */
  47. public class GeometryFreeCycleSlipDetector extends AbstractCycleSlipDetector {

  48.     /** Threshold above which cycle-slip occurs. */
  49.     private final double threshold;

  50.     /**
  51.      * Constructor.
  52.      * @param dt time gap threshold between two consecutive measurement (if time between two consecutive measurement is greater than dt, a cycle slip is declared)
  53.      * @param threshold threshold above which cycle-slip occurs
  54.      * @param n number of measurement before starting
  55.      */
  56.     public GeometryFreeCycleSlipDetector(final double dt, final double threshold, final int n) {
  57.         super(dt, n);
  58.         this.threshold = threshold;
  59.     }


  60.     /** {@inheritDoc} */
  61.     @Override
  62.     protected void manageData(final ObservationDataSet observation) {

  63.         // Extract observation data
  64.         final int             prn    = observation.getSatellite().getPRN();
  65.         final AbsoluteDate    date   = observation.getDate();
  66.         final SatelliteSystem system = observation.getSatellite().getSystem();

  67.         // Geometry-free combination of measurements
  68.         final GeometryFreeCombination geometryFree = MeasurementCombinationFactory.getGeometryFreeCombination(system);
  69.         final CombinedObservationDataSet cods = geometryFree.combine(observation);

  70.         // Initialize list of measurements
  71.         final List<CombinedObservationData> phasesGF = new ArrayList<>();

  72.         // Loop on observation data to fill lists
  73.         for (final CombinedObservationData cod : cods.getObservationData()) {
  74.             if (!Double.isNaN(cod.getValue()) && cod.getMeasurementType() == MeasurementType.CARRIER_PHASE) {
  75.                 phasesGF.add(cod);
  76.             }
  77.         }

  78.         // Loop on Geometry-free phase measurements
  79.         for (CombinedObservationData cod : phasesGF) {
  80.             final String nameSat = setName(prn, observation.getSatellite().getSystem());
  81.             // Check for cycle-slip detection
  82.             final GnssSignal signal = cod.getUsedObservationData().get(0).getObservationType().getSignal(system);
  83.             final boolean slip = cycleSlipDetection(nameSat, date, cod.getValue(), signal);
  84.             if (!slip) {
  85.                 // Update cycle slip data
  86.                 cycleSlipDataSet(nameSat, date, cod.getValue(), cod.getUsedObservationData().get(0).getObservationType().getSignal(system));
  87.             }
  88.         }

  89.     }

  90.     /**
  91.      * Compute if there is a cycle slip at an specific date.
  92.      * @param nameSat name of the satellite, on the pre-defined format (e.g.: GPS - 07 for satellite 7 of GPS constellation)
  93.      * @param currentDate the date at which we check if a cycle-slip occurs
  94.      * @param valueGF geometry free measurement
  95.      * @param signal frequency used
  96.      * @return true if a cycle slip has been detected.
  97.      */
  98.     private boolean cycleSlipDetection(final String nameSat, final AbsoluteDate currentDate,
  99.                                        final double valueGF, final GnssSignal signal) {

  100.         // Access the cycle slip results to know if a cycle-slip already occurred
  101.         final List<CycleSlipDetectorResults>         data  = getResults();
  102.         final List<Map<GnssSignal, DataForDetection>> stuff = getStuffReference();

  103.         // If a cycle-slip already occurred
  104.         if (data != null) {

  105.             // Loop on cycle-slip results
  106.             for (CycleSlipDetectorResults resultGF : data) {

  107.                 // Found the right cycle data
  108.                 if (resultGF.getSatelliteName().compareTo(nameSat) == 0 && resultGF.getCycleSlipMap().containsKey(signal)) {
  109.                     final Map<GnssSignal, DataForDetection> values = stuff.get(data.indexOf(resultGF));
  110.                     final DataForDetection dataForDetection = values.get(signal);

  111.                     // Check the time gap condition
  112.                     final double deltaT = FastMath.abs(currentDate.durationFrom(dataForDetection.getFiguresReference()[dataForDetection.getWrite()].getDate()));
  113.                     if (deltaT > getMaxTimeBeetween2Measurement()) {
  114.                         resultGF.addCycleSlipDate(signal, currentDate);
  115.                         dataForDetection.resetFigures(new SlipComputationData[getMinMeasurementNumber()], valueGF, currentDate);
  116.                         resultGF.setDate(signal, currentDate);
  117.                         return true;
  118.                     }

  119.                     // Compute the fitting polynomial if there are enough measurement since last cycle-slip
  120.                     if (dataForDetection.getCanBeComputed() >= getMinMeasurementNumber()) {
  121.                         final List<WeightedObservedPoint> xy = new ArrayList<>();
  122.                         for (int i = 0; i < getMinMeasurementNumber(); i++) {
  123.                             final SlipComputationData current = dataForDetection.getFiguresReference()[i];
  124.                             xy.add(new WeightedObservedPoint(1.0, current.getDate().durationFrom(currentDate),
  125.                                                              current.getValue()));
  126.                         }

  127.                         final PolynomialCurveFitter fitting = PolynomialCurveFitter.create(2);
  128.                         // Check if there is a cycle_slip
  129.                         if (FastMath.abs(fitting.fit(xy)[0] - valueGF) > threshold) {
  130.                             resultGF.addCycleSlipDate(signal, currentDate);
  131.                             dataForDetection.resetFigures(new SlipComputationData[getMinMeasurementNumber()], valueGF, currentDate);
  132.                             resultGF.setDate(signal, currentDate);
  133.                             return true;
  134.                         }

  135.                     } else {
  136.                         break;
  137.                     }

  138.                 }

  139.             }

  140.         }

  141.         // No cycle-slip
  142.         return false;
  143.     }

  144. }