Phase.java

  1. /* Copyright 2002-2018 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.errors.OrekitException;
  26. import org.orekit.frames.FieldTransform;
  27. import org.orekit.propagation.SpacecraftState;
  28. import org.orekit.time.AbsoluteDate;
  29. import org.orekit.time.FieldAbsoluteDate;
  30. import org.orekit.utils.Constants;
  31. import org.orekit.utils.ParameterDriver;
  32. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  33. import org.orekit.utils.TimeStampedPVCoordinates;

  34. /** Class modeling a phase measurement from a ground station.
  35.  * <p>
  36.  * The measurement is considered to be a signal emitted from
  37.  * a spacecraft and received on a ground station.
  38.  * Its value is the number of cycles between emission and
  39.  * reception. The motion of both the station and the
  40.  * spacecraft during the signal flight time are taken into
  41.  * account. The date of the measurement corresponds to the
  42.  * reception on ground of the emitted signal.
  43.  * </p>
  44.  * <p>
  45.  * WARNING: as of release 9.2, this feature is still considered experimental
  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.     /** Ground station from which measurement is performed. */
  54.     private final GroundStation station;

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

  57.     /** Simple constructor.
  58.      * <p>
  59.      * This constructor uses 0 as the index of the propagator related
  60.      * to this measurement, thus being well suited for mono-satellite
  61.      * orbit determination.
  62.      * </p>
  63.      * @param station ground station from which measurement is performed
  64.      * @param date date of the measurement
  65.      * @param phase observed value
  66.      * @param wavelength phase observed value wavelength
  67.      * @param sigma theoretical standard deviation
  68.      * @param baseWeight base weight
  69.      * @exception OrekitException if a {@link org.orekit.utils.ParameterDriver}
  70.      * name conflict occurs
  71.      */
  72.     public Phase(final GroundStation station, final AbsoluteDate date,
  73.                  final double phase, final double wavelength, final double sigma,
  74.                  final double baseWeight)
  75.         throws OrekitException {
  76.         this(station, date, phase, wavelength, sigma, baseWeight, 0);
  77.     }

  78.     /** Simple constructor.
  79.      * @param station ground station from which measurement is performed
  80.      * @param date date of the measurement
  81.      * @param phase observed value
  82.      * @param wavelength phase observed value wavelength
  83.      * @param sigma theoretical standard deviation
  84.      * @param baseWeight base weight
  85.      * @param propagatorIndex index of the propagator related to this measurement
  86.      * @exception OrekitException if a {@link org.orekit.utils.ParameterDriver}
  87.      * name conflict occurs
  88.      */
  89.     public Phase(final GroundStation station, final AbsoluteDate date,
  90.                  final double phase, final double wavelength, final double sigma,
  91.                  final double baseWeight, final int propagatorIndex)
  92.         throws OrekitException {
  93.         super(date, phase, sigma, baseWeight, Arrays.asList(propagatorIndex),
  94.               station.getEastOffsetDriver(),
  95.               station.getNorthOffsetDriver(),
  96.               station.getZenithOffsetDriver(),
  97.               station.getPrimeMeridianOffsetDriver(),
  98.               station.getPrimeMeridianDriftDriver(),
  99.               station.getPolarOffsetXDriver(),
  100.               station.getPolarDriftXDriver(),
  101.               station.getPolarOffsetYDriver(),
  102.               station.getPolarDriftYDriver());
  103.         this.station    = station;
  104.         this.wavelength = wavelength;
  105.     }

  106.     /** Get the ground station from which measurement is performed.
  107.      * @return ground station from which measurement is performed
  108.      */
  109.     public GroundStation getStation() {
  110.         return station;
  111.     }

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

  118.         final SpacecraftState state = states[getPropagatorsIndices().get(0)];

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

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

  139.         // transform between station and inertial frame, expressed as a derivative structure
  140.         // The components of station's position in offset frame are the 3 last derivative parameters
  141.         final AbsoluteDate downlinkDate = getDate();
  142.         final FieldAbsoluteDate<DerivativeStructure> downlinkDateDS =
  143.                         new FieldAbsoluteDate<>(field, downlinkDate);
  144.         final FieldTransform<DerivativeStructure> offsetToInertialDownlink =
  145.                         station.getOffsetToInertial(state.getFrame(), downlinkDateDS, factory, indices);

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

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

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

  155.         // Transit state & Transit state (re)computed with derivative structures
  156.         final double                delta        = downlinkDate.durationFrom(state.getDate());
  157.         final DerivativeStructure   deltaMTauD   = tauD.negate().add(delta);
  158.         final SpacecraftState       transitState = state.shiftedBy(deltaMTauD.getValue());
  159.         final TimeStampedFieldPVCoordinates<DerivativeStructure> transitStateDS = pvaDS.shiftedBy(deltaMTauD);

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

  169.         // Phase value
  170.         final double              cOverLambda = Constants.SPEED_OF_LIGHT / wavelength;
  171.         final DerivativeStructure phase       = tauD.multiply(cOverLambda);

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

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

  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 + 1]);
  182.             }
  183.         }

  184.         return estimated;

  185.     }

  186. }