Phase.java

  1. /* Copyright 2002-2022 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 java.util.Collections;
  20. import java.util.HashMap;
  21. import java.util.Map;

  22. import org.hipparchus.analysis.differentiation.Gradient;
  23. import org.hipparchus.analysis.differentiation.GradientField;
  24. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  25. import org.orekit.estimation.measurements.AbstractMeasurement;
  26. import org.orekit.estimation.measurements.EstimatedMeasurement;
  27. import org.orekit.estimation.measurements.GroundStation;
  28. import org.orekit.estimation.measurements.ObservableSatellite;
  29. import org.orekit.frames.FieldTransform;
  30. import org.orekit.propagation.SpacecraftState;
  31. import org.orekit.time.AbsoluteDate;
  32. import org.orekit.time.FieldAbsoluteDate;
  33. import org.orekit.utils.Constants;
  34. import org.orekit.utils.ParameterDriver;
  35. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  36. import org.orekit.utils.TimeStampedPVCoordinates;

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

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

  55.     /** Name for ambiguity driver. */
  56.     public static final String AMBIGUITY_NAME = "ambiguity";

  57.     /** Driver for ambiguity. */
  58.     private final ParameterDriver ambiguityDriver;

  59.     /** Ground station from which measurement is performed. */
  60.     private final GroundStation station;

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

  63.     /** Simple constructor.
  64.      * @param station ground station from which measurement is performed
  65.      * @param date date of the measurement
  66.      * @param phase observed value (cycles)
  67.      * @param wavelength phase observed value wavelength (m)
  68.      * @param sigma theoretical standard deviation
  69.      * @param baseWeight base weight
  70.      * @param satellite satellite related to this measurement
  71.      * @since 9.3
  72.      */
  73.     public Phase(final GroundStation station, final AbsoluteDate date,
  74.                  final double phase, final double wavelength, final double sigma,
  75.                  final double baseWeight, final ObservableSatellite satellite) {
  76.         super(date, phase, sigma, baseWeight, Collections.singletonList(satellite));
  77.         ambiguityDriver = new ParameterDriver(AMBIGUITY_NAME,
  78.                                                0.0, 1.0,
  79.                                                Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
  80.         addParameterDriver(ambiguityDriver);
  81.         addParameterDriver(satellite.getClockOffsetDriver());
  82.         addParameterDriver(station.getClockOffsetDriver());
  83.         addParameterDriver(station.getEastOffsetDriver());
  84.         addParameterDriver(station.getNorthOffsetDriver());
  85.         addParameterDriver(station.getZenithOffsetDriver());
  86.         addParameterDriver(station.getPrimeMeridianOffsetDriver());
  87.         addParameterDriver(station.getPrimeMeridianDriftDriver());
  88.         addParameterDriver(station.getPolarOffsetXDriver());
  89.         addParameterDriver(station.getPolarDriftXDriver());
  90.         addParameterDriver(station.getPolarOffsetYDriver());
  91.         addParameterDriver(station.getPolarDriftYDriver());
  92.         this.station    = station;
  93.         this.wavelength = wavelength;
  94.     }

  95.     /** Get the ground station from which measurement is performed.
  96.      * @return ground station from which measurement is performed
  97.      */
  98.     public GroundStation getStation() {
  99.         return station;
  100.     }

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

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

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

  119.         final SpacecraftState state = states[0];

  120.         // Phase derivatives are computed with respect to spacecraft state in inertial frame
  121.         // and station parameters
  122.         // ----------------------
  123.         //
  124.         // Parameters:
  125.         //  - 0..2 - Position of the spacecraft in inertial frame
  126.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  127.         //  - 6..n - station parameters (ambiguity, clock offset, station offsets, pole, prime meridian...)
  128.         int nbParams = 6;
  129.         final Map<String, Integer> indices = new HashMap<>();
  130.         for (ParameterDriver driver : getParametersDrivers()) {
  131.             if (driver.isSelected()) {
  132.                 indices.put(driver.getName(), nbParams++);
  133.             }
  134.         }
  135.         final FieldVector3D<Gradient> zero = FieldVector3D.getZero(GradientField.getField(nbParams));

  136.         // Coordinates of the spacecraft expressed as a gradient
  137.         final TimeStampedFieldPVCoordinates<Gradient> pvaDS = getCoordinates(state, 0, nbParams);

  138.         // transform between station and inertial frame, expressed as a gradient
  139.         // The components of station's position in offset frame are the 3 last derivative parameters
  140.         final FieldTransform<Gradient> offsetToInertialDownlink =
  141.                         station.getOffsetToInertial(state.getFrame(), getDate(), nbParams, indices);
  142.         final FieldAbsoluteDate<Gradient> downlinkDateDS =
  143.                         offsetToInertialDownlink.getFieldDate();

  144.         // Station position in inertial frame at end of the downlink leg
  145.         final TimeStampedFieldPVCoordinates<Gradient> stationDownlink =
  146.                         offsetToInertialDownlink.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(downlinkDateDS,
  147.                                                                                                             zero, zero, zero));

  148.         // Compute propagation times
  149.         // (if state has already been set up to pre-compensate propagation delay,
  150.         //  we will have delta == tauD and transitState will be the same as state)

  151.         // Downlink delay
  152.         final Gradient tauD = signalTimeOfFlight(pvaDS, stationDownlink.getPosition(), downlinkDateDS);

  153.         // Transit state & Transit state (re)computed with gradients
  154.         final Gradient        delta        = downlinkDateDS.durationFrom(state.getDate());
  155.         final Gradient        deltaMTauD   = tauD.negate().add(delta);
  156.         final SpacecraftState transitState = state.shiftedBy(deltaMTauD.getValue());
  157.         final TimeStampedFieldPVCoordinates<Gradient> transitStateDS = pvaDS.shiftedBy(deltaMTauD);

  158.         // prepare the evaluation
  159.         final EstimatedMeasurement<Phase> estimated =
  160.                         new EstimatedMeasurement<Phase>(this, iteration, evaluation,
  161.                                                         new SpacecraftState[] {
  162.                                                             transitState
  163.                                                         }, new TimeStampedPVCoordinates[] {
  164.                                                             transitStateDS.toTimeStampedPVCoordinates(),
  165.                                                             stationDownlink.toTimeStampedPVCoordinates()
  166.                                                         });

  167.         // Clock offsets
  168.         final ObservableSatellite satellite = getSatellites().get(0);
  169.         final Gradient            dts       = satellite.getClockOffsetDriver().getValue(nbParams, indices);
  170.         final Gradient            dtg       = station.getClockOffsetDriver().getValue(nbParams, indices);

  171.         // Phase value
  172.         final double   cOverLambda = Constants.SPEED_OF_LIGHT / wavelength;
  173.         final Gradient ambiguity   = ambiguityDriver.getValue(nbParams, indices);
  174.         final Gradient phase       = tauD.add(dtg).subtract(dts).multiply(cOverLambda).add(ambiguity);

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

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

  179.         // set partial derivatives with respect to parameters
  180.         // (beware element at index 0 is the value, not a derivative)
  181.         for (final ParameterDriver driver : getParametersDrivers()) {
  182.             final Integer index = indices.get(driver.getName());
  183.             if (index != null) {
  184.                 estimated.setParameterDerivatives(driver, derivatives[index]);
  185.             }
  186.         }

  187.         return estimated;

  188.     }

  189. }