Phase.java

  1. /* Copyright 2002-2019 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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;

  18. import java.util.Arrays;
  19. import java.util.HashMap;
  20. import java.util.Map;

  21. import org.hipparchus.Field;
  22. import org.hipparchus.analysis.differentiation.DSFactory;
  23. import org.hipparchus.analysis.differentiation.DerivativeStructure;
  24. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  25. import org.orekit.frames.FieldTransform;
  26. import org.orekit.propagation.SpacecraftState;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.time.FieldAbsoluteDate;
  29. import org.orekit.utils.Constants;
  30. import org.orekit.utils.ParameterDriver;
  31. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  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 AbstractMeasurement<Phase> {

  49.     /** Ground station from which measurement is performed. */
  50.     private final GroundStation station;

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

  53.     /** Simple constructor.
  54.      * <p>
  55.      * This constructor uses 0 as the index of the propagator related
  56.      * to this measurement, thus being well suited for mono-satellite
  57.      * orbit determination.
  58.      * </p>
  59.      * @param station ground station from which measurement is performed
  60.      * @param date date of the measurement
  61.      * @param phase observed value
  62.      * @param wavelength phase observed value wavelength
  63.      * @param sigma theoretical standard deviation
  64.      * @param baseWeight base weight
  65.      * @deprecated since 9.3 raplced by {@link #Phase(GroundStation, AbsoluteDate,
  66.      * double, double, double, double, ObservableSatellite)}
  67.      */
  68.     @Deprecated
  69.     public Phase(final GroundStation station, final AbsoluteDate date,
  70.                  final double phase, final double wavelength, final double sigma,
  71.                  final double baseWeight) {
  72.         this(station, date, phase, wavelength, sigma, baseWeight, new ObservableSatellite(0));
  73.     }

  74.     /** Simple constructor.
  75.      * @param station ground station from which measurement is performed
  76.      * @param date date of the measurement
  77.      * @param phase observed value
  78.      * @param wavelength phase observed value wavelength
  79.      * @param sigma theoretical standard deviation
  80.      * @param baseWeight base weight
  81.      * @param propagatorIndex index of the propagator related to this measurement
  82.      * @deprecated since 9.3 raplced by {@link #Phase(GroundStation, AbsoluteDate,
  83.      * double, double, double, double, ObservableSatellite)}
  84.      */
  85.     @Deprecated
  86.     public Phase(final GroundStation station, final AbsoluteDate date,
  87.                  final double phase, final double wavelength, final double sigma,
  88.                  final double baseWeight, final int propagatorIndex) {
  89.         this(station, date, phase, wavelength, sigma, baseWeight, new ObservableSatellite(propagatorIndex));
  90.     }

  91.     /** Simple constructor.
  92.      * @param station ground station from which measurement is performed
  93.      * @param date date of the measurement
  94.      * @param phase observed value
  95.      * @param wavelength phase observed value wavelength
  96.      * @param sigma theoretical standard deviation
  97.      * @param baseWeight base weight
  98.      * @param satellite satellite related to this measurement
  99.      * @since 9.3
  100.      */
  101.     public Phase(final GroundStation station, final AbsoluteDate date,
  102.                  final double phase, final double wavelength, final double sigma,
  103.                  final double baseWeight, final ObservableSatellite satellite) {
  104.         super(date, phase, sigma, baseWeight, Arrays.asList(satellite));
  105.         addParameterDriver(station.getClockOffsetDriver());
  106.         addParameterDriver(station.getEastOffsetDriver());
  107.         addParameterDriver(station.getNorthOffsetDriver());
  108.         addParameterDriver(station.getZenithOffsetDriver());
  109.         addParameterDriver(station.getPrimeMeridianOffsetDriver());
  110.         addParameterDriver(station.getPrimeMeridianDriftDriver());
  111.         addParameterDriver(station.getPolarOffsetXDriver());
  112.         addParameterDriver(station.getPolarDriftXDriver());
  113.         addParameterDriver(station.getPolarOffsetYDriver());
  114.         addParameterDriver(station.getPolarDriftYDriver());
  115.         this.station    = station;
  116.         this.wavelength = wavelength;
  117.     }

  118.     /** Get the ground station from which measurement is performed.
  119.      * @return ground station from which measurement is performed
  120.      */
  121.     public GroundStation getStation() {
  122.         return station;
  123.     }

  124.     /** {@inheritDoc} */
  125.     @Override
  126.     protected EstimatedMeasurement<Phase> theoreticalEvaluation(final int iteration,
  127.                                                                 final int evaluation,
  128.                                                                 final SpacecraftState[] states) {

  129.         final ObservableSatellite satellite = getSatellites().get(0);
  130.         final SpacecraftState state = states[satellite.getPropagatorIndex()];

  131.         // Phase derivatives are computed with respect to spacecraft state in inertial frame
  132.         // and station parameters
  133.         // ----------------------
  134.         //
  135.         // Parameters:
  136.         //  - 0..2 - Position of the spacecraft in inertial frame
  137.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  138.         //  - 6..n - station parameters (clock offset, station offsets, pole, prime meridian...)
  139.         int nbParams = 6;
  140.         final Map<String, Integer> indices = new HashMap<>();
  141.         for (ParameterDriver driver : getParametersDrivers()) {
  142.             if (driver.isSelected()) {
  143.                 indices.put(driver.getName(), nbParams++);
  144.             }
  145.         }
  146.         final DSFactory                          factory = new DSFactory(nbParams, 1);
  147.         final Field<DerivativeStructure>         field   = factory.getDerivativeField();
  148.         final FieldVector3D<DerivativeStructure> zero    = FieldVector3D.getZero(field);

  149.         // Coordinates of the spacecraft expressed as a derivative structure
  150.         final TimeStampedFieldPVCoordinates<DerivativeStructure> pvaDS = getCoordinates(state, 0, factory);

  151.         // transform between station and inertial frame, expressed as a derivative structure
  152.         // The components of station's position in offset frame are the 3 last derivative parameters
  153.         final FieldTransform<DerivativeStructure> offsetToInertialDownlink =
  154.                         station.getOffsetToInertial(state.getFrame(), getDate(), factory, indices);
  155.         final FieldAbsoluteDate<DerivativeStructure> downlinkDateDS =
  156.                         offsetToInertialDownlink.getFieldDate();

  157.         // Station position in inertial frame at end of the downlink leg
  158.         final TimeStampedFieldPVCoordinates<DerivativeStructure> stationDownlink =
  159.                         offsetToInertialDownlink.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(downlinkDateDS,
  160.                                                                                                             zero, zero, zero));

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

  164.         // Downlink delay
  165.         final DerivativeStructure tauD = signalTimeOfFlight(pvaDS, stationDownlink.getPosition(), downlinkDateDS);

  166.         // Transit state & Transit state (re)computed with derivative structures
  167.         final DerivativeStructure   delta        = downlinkDateDS.durationFrom(state.getDate());
  168.         final DerivativeStructure   deltaMTauD   = tauD.negate().add(delta);
  169.         final SpacecraftState       transitState = state.shiftedBy(deltaMTauD.getValue());
  170.         final TimeStampedFieldPVCoordinates<DerivativeStructure> transitStateDS = pvaDS.shiftedBy(deltaMTauD);

  171.         // prepare the evaluation
  172.         final EstimatedMeasurement<Phase> estimated =
  173.                         new EstimatedMeasurement<Phase>(this, iteration, evaluation,
  174.                                                         new SpacecraftState[] {
  175.                                                             transitState
  176.                                                         }, new TimeStampedPVCoordinates[] {
  177.                                                             transitStateDS.toTimeStampedPVCoordinates(),
  178.                                                             stationDownlink.toTimeStampedPVCoordinates()
  179.                                                         });

  180.         // Phase value
  181.         final double              cOverLambda = Constants.SPEED_OF_LIGHT / wavelength;
  182.         final DerivativeStructure phase       = tauD.multiply(cOverLambda);

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

  184.         // Phase partial derivatives with respect to state
  185.         final double[] derivatives = phase.getAllDerivatives();
  186.         estimated.setStateDerivatives(0, Arrays.copyOfRange(derivatives, 1, 7));

  187.         // set partial derivatives with respect to parameters
  188.         // (beware element at index 0 is the value, not a derivative)
  189.         for (final ParameterDriver driver : getParametersDrivers()) {
  190.             final Integer index = indices.get(driver.getName());
  191.             if (index != null) {
  192.                 estimated.setParameterDerivatives(driver, derivatives[index + 1]);
  193.             }
  194.         }

  195.         return estimated;

  196.     }

  197. }