Phase.java

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

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

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

  52.     /** Name for ambiguity driver. */
  53.     public static final String AMBIGUITY_NAME = "ambiguity";

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

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

  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.      */
  70.     public Phase(final GroundStation station, final AbsoluteDate date,
  71.                  final double phase, final double wavelength, final double sigma,
  72.                  final double baseWeight, final ObservableSatellite satellite) {
  73.         super(date, phase, sigma, baseWeight, Arrays.asList(satellite));
  74.         ambiguityDriver = new ParameterDriver(AMBIGUITY_NAME,
  75.                                                0.0, 1.0,
  76.                                                Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
  77.         addParameterDriver(ambiguityDriver);
  78.         addParameterDriver(satellite.getClockOffsetDriver());
  79.         addParameterDriver(station.getClockOffsetDriver());
  80.         addParameterDriver(station.getEastOffsetDriver());
  81.         addParameterDriver(station.getNorthOffsetDriver());
  82.         addParameterDriver(station.getZenithOffsetDriver());
  83.         addParameterDriver(station.getPrimeMeridianOffsetDriver());
  84.         addParameterDriver(station.getPrimeMeridianDriftDriver());
  85.         addParameterDriver(station.getPolarOffsetXDriver());
  86.         addParameterDriver(station.getPolarDriftXDriver());
  87.         addParameterDriver(station.getPolarOffsetYDriver());
  88.         addParameterDriver(station.getPolarDriftYDriver());
  89.         this.station    = station;
  90.         this.wavelength = wavelength;
  91.     }

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

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

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

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

  116.         final SpacecraftState state = states[0];

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

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

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

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

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

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

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

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

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

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

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

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

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

  184.         return estimated;

  185.     }

  186. }