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.     /** Name for ambiguity driver. */
  54.     public static final String AMBIGUITY_NAME = "ambiguity";

  55.     /** Driver for ambiguity. */
  56.     private final ParameterDriver ambiguityDriver;

  57.     /** Ground station from which measurement is performed. */
  58.     private final GroundStation station;

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

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

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

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

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

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

  117.         final SpacecraftState state = states[0];

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

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

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

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

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

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

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

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

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

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

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

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

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

  185.         return estimated;

  186.     }

  187. }