Phase.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.Arrays;

  19. import org.hipparchus.analysis.differentiation.Gradient;
  20. import org.orekit.estimation.measurements.EstimatedMeasurement;
  21. import org.orekit.estimation.measurements.EstimatedMeasurementBase;
  22. import org.orekit.estimation.measurements.GroundReceiverCommonParametersWithDerivatives;
  23. import org.orekit.estimation.measurements.GroundReceiverCommonParametersWithoutDerivatives;
  24. import org.orekit.estimation.measurements.GroundReceiverMeasurement;
  25. import org.orekit.estimation.measurements.GroundStation;
  26. import org.orekit.estimation.measurements.ObservableSatellite;
  27. import org.orekit.propagation.SpacecraftState;
  28. import org.orekit.time.AbsoluteDate;
  29. import org.orekit.utils.Constants;
  30. import org.orekit.utils.ParameterDriver;
  31. import org.orekit.utils.TimeSpanMap.Span;
  32. import org.orekit.utils.TimeStampedPVCoordinates;

  33. /** Class modeling a phase measurement from a ground station.
  34.  * <p>
  35.  * The measurement is considered to be a signal emitted from
  36.  * a spacecraft and received on a ground station.
  37.  * Its value is the number of cycles between emission and
  38.  * reception. The motion of both the station and the
  39.  * spacecraft during the signal flight time are taken into
  40.  * account. The date of the measurement corresponds to the
  41.  * reception on ground of the emitted signal.
  42.  * </p>
  43.  * @author Thierry Ceolin
  44.  * @author Luc Maisonobe
  45.  * @author Maxime Journot
  46.  * @since 9.2
  47.  */
  48. public class Phase extends GroundReceiverMeasurement<Phase> {

  49.     /** Type of the measurement. */
  50.     public static final String MEASUREMENT_TYPE = "Phase";

  51.     /** Driver for ambiguity. */
  52.     private final AmbiguityDriver ambiguityDriver;

  53.     /** Wavelength of the phase observed value [m]. */
  54.     private final double wavelength;

  55.     /** Simple constructor.
  56.      * @param station ground station from which measurement is performed
  57.      * @param date date of the measurement
  58.      * @param phase observed value (cycles)
  59.      * @param wavelength phase observed value wavelength (m)
  60.      * @param sigma theoretical standard deviation
  61.      * @param baseWeight base weight
  62.      * @param satellite satellite related to this measurement
  63.      * @param cache from which ambiguity drive should come
  64.      * @since 12.1
  65.      */
  66.     public Phase(final GroundStation station, final AbsoluteDate date,
  67.                  final double phase, final double wavelength, final double sigma,
  68.                  final double baseWeight, final ObservableSatellite satellite,
  69.                  final AmbiguityCache cache) {
  70.         super(station, false, date, phase, sigma, baseWeight, satellite);
  71.         ambiguityDriver = cache.getAmbiguity(satellite.getName(),
  72.                                              station.getBaseFrame().getName(),
  73.                                              wavelength);
  74.         addParameterDriver(ambiguityDriver);
  75.         this.wavelength = wavelength;
  76.     }

  77.     /** Get the wavelength.
  78.      * @return wavelength (m)
  79.      */
  80.     public double getWavelength() {
  81.         return wavelength;
  82.     }

  83.     /** Get the driver for phase ambiguity.
  84.      * @return the driver for phase ambiguity
  85.      * @since 10.3
  86.      */
  87.     public AmbiguityDriver getAmbiguityDriver() {
  88.         return ambiguityDriver;
  89.     }

  90.     /** {@inheritDoc} */
  91.     @Override
  92.     protected EstimatedMeasurementBase<Phase> theoreticalEvaluationWithoutDerivatives(final int iteration,
  93.                                                                                       final int evaluation,
  94.                                                                                       final SpacecraftState[] states) {

  95.         final GroundReceiverCommonParametersWithoutDerivatives common = computeCommonParametersWithout(states[0]);

  96.         // prepare the evaluation
  97.         final EstimatedMeasurementBase<Phase> estimated =
  98.                         new EstimatedMeasurementBase<>(this, iteration, evaluation,
  99.                                                        new SpacecraftState[] {
  100.                                                            common.getTransitState()
  101.                                                        }, new TimeStampedPVCoordinates[] {
  102.                                                            common.getTransitPV(),
  103.                                                            common.getStationDownlink()
  104.                                                        });

  105.         // Clock offsets
  106.         final ObservableSatellite satellite = getSatellites().get(0);
  107.         final double              dts       = satellite.getClockOffsetDriver().getValue(common.getState().getDate());
  108.         final double              dtg       = getStation().getClockOffsetDriver().getValue(getDate());

  109.         // Phase value
  110.         final double cOverLambda = Constants.SPEED_OF_LIGHT / wavelength;
  111.         final double ambiguity   = ambiguityDriver.getValue(common.getState().getDate());
  112.         final double phase       = (common.getTauD() + dtg - dts) * cOverLambda + ambiguity;

  113.         estimated.setEstimatedValue(phase);

  114.         return estimated;

  115.     }

  116.     /** {@inheritDoc} */
  117.     @Override
  118.     protected EstimatedMeasurement<Phase> theoreticalEvaluation(final int iteration,
  119.                                                                 final int evaluation,
  120.                                                                 final SpacecraftState[] states) {

  121.         final SpacecraftState state = states[0];

  122.         // Phase derivatives are computed with respect to spacecraft state in inertial frame
  123.         // and station parameters
  124.         // ----------------------
  125.         //
  126.         // Parameters:
  127.         //  - 0..2 - Position of the spacecraft in inertial frame
  128.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  129.         //  - 6..n - station parameters (ambiguity, clock offset, station offsets, pole, prime meridian...)
  130.         final GroundReceiverCommonParametersWithDerivatives common = computeCommonParametersWithDerivatives(state);
  131.         final int nbParams = common.getTauD().getFreeParameters();

  132.         // prepare the evaluation
  133.         final EstimatedMeasurement<Phase> estimated =
  134.                         new EstimatedMeasurement<>(this, iteration, evaluation,
  135.                                                    new SpacecraftState[] {
  136.                                                        common.getTransitState()
  137.                                                    }, new TimeStampedPVCoordinates[] {
  138.                                                        common.getTransitPV().toTimeStampedPVCoordinates(),
  139.                                                        common.getStationDownlink().toTimeStampedPVCoordinates()
  140.                                                    });

  141.         // Clock offsets
  142.         final ObservableSatellite satellite = getSatellites().get(0);
  143.         final Gradient            dts       = satellite.getClockOffsetDriver().getValue(nbParams, common.getIndices(), state.getDate());
  144.         final Gradient            dtg       = getStation().getClockOffsetDriver().getValue(nbParams, common.getIndices(), getDate());

  145.         // Phase value
  146.         final double   cOverLambda = Constants.SPEED_OF_LIGHT / wavelength;
  147.         final Gradient ambiguity   = ambiguityDriver.getValue(nbParams, common.getIndices(), state.getDate());
  148.         final Gradient phase       = common.getTauD().add(dtg).subtract(dts).multiply(cOverLambda).add(ambiguity);

  149.         estimated.setEstimatedValue(phase.getValue());

  150.         // Phase first order derivatives with respect to state
  151.         final double[] derivatives = phase.getGradient();
  152.         estimated.setStateDerivatives(0, Arrays.copyOfRange(derivatives, 0, 6));

  153.         // Set first order derivatives with respect to parameters
  154.         for (final ParameterDriver driver : getParametersDrivers()) {
  155.             for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {

  156.                 final Integer index = common.getIndices().get(span.getData());
  157.                 if (index != null) {
  158.                     estimated.setParameterDerivatives(driver, span.getStart(), derivatives[index]);
  159.                 }
  160.             }
  161.         }

  162.         return estimated;

  163.     }

  164. }