Phase.java

  1. /* Copyright 2002-2024 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.     /** Name for ambiguity driver.
  52.      * @deprecated as of 12.1 not used anymore
  53.      */
  54.     @Deprecated
  55.     public static final String AMBIGUITY_NAME = "ambiguity";

  56.     /** Driver for ambiguity. */
  57.     private final AmbiguityDriver ambiguityDriver;

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

  60.     /** Simple constructor.
  61.      * @param station ground station from which measurement is performed
  62.      * @param date date of the measurement
  63.      * @param phase observed value (cycles)
  64.      * @param wavelength phase observed value wavelength (m)
  65.      * @param sigma theoretical standard deviation
  66.      * @param baseWeight base weight
  67.      * @param satellite satellite related to this measurement
  68.      * @since 9.3
  69.      * @deprecated as of 12.1, replaced by {@link #Phase(GroundStation,
  70.      * AbsoluteDate, double, double, double, double, ObservableSatellite,
  71.      * AmbiguityCache)}
  72.      */
  73.     @Deprecated
  74.     public Phase(final GroundStation station, final AbsoluteDate date,
  75.                  final double phase, final double wavelength, final double sigma,
  76.                  final double baseWeight, final ObservableSatellite satellite) {
  77.         this(station, date, phase, wavelength, sigma, baseWeight, satellite,
  78.              AmbiguityCache.DEFAULT_CACHE);
  79.     }

  80.     /** Simple constructor.
  81.      * @param station ground station from which measurement is performed
  82.      * @param date date of the measurement
  83.      * @param phase observed value (cycles)
  84.      * @param wavelength phase observed value wavelength (m)
  85.      * @param sigma theoretical standard deviation
  86.      * @param baseWeight base weight
  87.      * @param satellite satellite related to this measurement
  88.      * @param cache from which ambiguity drive should come
  89.      * @since 12.1
  90.      */
  91.     public Phase(final GroundStation station, final AbsoluteDate date,
  92.                  final double phase, final double wavelength, final double sigma,
  93.                  final double baseWeight, final ObservableSatellite satellite,
  94.                  final AmbiguityCache cache) {
  95.         super(station, false, date, phase, sigma, baseWeight, satellite);
  96.         ambiguityDriver = cache.getAmbiguity(satellite.getName(),
  97.                                              station.getBaseFrame().getName(),
  98.                                              wavelength);
  99.         addParameterDriver(ambiguityDriver);
  100.         this.wavelength = wavelength;
  101.     }

  102.     /** Get the wavelength.
  103.      * @return wavelength (m)
  104.      */
  105.     public double getWavelength() {
  106.         return wavelength;
  107.     }

  108.     /** Get the driver for phase ambiguity.
  109.      * @return the driver for phase ambiguity
  110.      * @since 10.3
  111.      */
  112.     public AmbiguityDriver getAmbiguityDriver() {
  113.         return ambiguityDriver;
  114.     }

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

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

  121.         // prepare the evaluation
  122.         final EstimatedMeasurementBase<Phase> estimated =
  123.                         new EstimatedMeasurementBase<>(this, iteration, evaluation,
  124.                                                        new SpacecraftState[] {
  125.                                                            common.getTransitState()
  126.                                                        }, new TimeStampedPVCoordinates[] {
  127.                                                            common.getTransitPV(),
  128.                                                            common.getStationDownlink()
  129.                                                        });

  130.         // Clock offsets
  131.         final ObservableSatellite satellite = getSatellites().get(0);
  132.         final double              dts       = satellite.getClockOffsetDriver().getValue(common.getState().getDate());
  133.         final double              dtg       = getStation().getClockOffsetDriver().getValue(getDate());

  134.         // Phase value
  135.         final double cOverLambda = Constants.SPEED_OF_LIGHT / wavelength;
  136.         final double ambiguity   = ambiguityDriver.getValue(common.getState().getDate());
  137.         final double phase       = (common.getTauD() + dtg - dts) * cOverLambda + ambiguity;

  138.         estimated.setEstimatedValue(phase);

  139.         return estimated;

  140.     }

  141.     /** {@inheritDoc} */
  142.     @Override
  143.     protected EstimatedMeasurement<Phase> theoreticalEvaluation(final int iteration,
  144.                                                                 final int evaluation,
  145.                                                                 final SpacecraftState[] states) {

  146.         final SpacecraftState state = states[0];

  147.         // Phase derivatives are computed with respect to spacecraft state in inertial frame
  148.         // and station parameters
  149.         // ----------------------
  150.         //
  151.         // Parameters:
  152.         //  - 0..2 - Position of the spacecraft in inertial frame
  153.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  154.         //  - 6..n - station parameters (ambiguity, clock offset, station offsets, pole, prime meridian...)
  155.         final GroundReceiverCommonParametersWithDerivatives common = computeCommonParametersWithDerivatives(state);
  156.         final int nbParams = common.getTauD().getFreeParameters();

  157.         // prepare the evaluation
  158.         final EstimatedMeasurement<Phase> estimated =
  159.                         new EstimatedMeasurement<>(this, iteration, evaluation,
  160.                                                    new SpacecraftState[] {
  161.                                                        common.getTransitState()
  162.                                                    }, new TimeStampedPVCoordinates[] {
  163.                                                        common.getTransitPV().toTimeStampedPVCoordinates(),
  164.                                                        common.getStationDownlink().toTimeStampedPVCoordinates()
  165.                                                    });

  166.         // Clock offsets
  167.         final ObservableSatellite satellite = getSatellites().get(0);
  168.         final Gradient            dts       = satellite.getClockOffsetDriver().getValue(nbParams, common.getIndices(), state.getDate());
  169.         final Gradient            dtg       = getStation().getClockOffsetDriver().getValue(nbParams, common.getIndices(), getDate());

  170.         // Phase value
  171.         final double   cOverLambda = Constants.SPEED_OF_LIGHT / wavelength;
  172.         final Gradient ambiguity   = ambiguityDriver.getValue(nbParams, common.getIndices(), state.getDate());
  173.         final Gradient phase       = common.getTauD().add(dtg).subtract(dts).multiply(cOverLambda).add(ambiguity);

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

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

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

  181.                 final Integer index = common.getIndices().get(span.getData());
  182.                 if (index != null) {
  183.                     estimated.setParameterDerivatives(driver, span.getStart(), derivatives[index]);
  184.                 }
  185.             }
  186.         }

  187.         return estimated;

  188.     }

  189. }