AngularAzEl.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.hipparchus.util.MathUtils;
  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.ParameterDriver;
  31. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  32. import org.orekit.utils.TimeStampedPVCoordinates;

  33. /** Class modeling an Azimuth-Elevation measurement from a ground station.
  34.  * The motion of the spacecraft during the signal flight time is taken into
  35.  * account. The date of the measurement corresponds to the reception on
  36.  * ground of the reflected signal.
  37.  *
  38.  * @author Thierry Ceolin
  39.  * @since 8.0
  40.  */
  41. public class AngularAzEl extends AbstractMeasurement<AngularAzEl> {

  42.     /** Ground station from which measurement is performed. */
  43.     private final GroundStation station;

  44.     /** Simple constructor.
  45.      * <p>
  46.      * This constructor uses 0 as the index of the propagator related
  47.      * to this measurement, thus being well suited for mono-satellite
  48.      * orbit determination.
  49.      * </p>
  50.      * @param station ground station from which measurement is performed
  51.      * @param date date of the measurement
  52.      * @param angular observed value
  53.      * @param sigma theoretical standard deviation
  54.      * @param baseWeight base weight
  55.      * @deprecated since 9.3, replaced by {@link #AngularAzEl(GroundStation, AbsoluteDate,
  56.      * double[], double[], double[], ObservableSatellite)}
  57.      */
  58.     @Deprecated
  59.     public AngularAzEl(final GroundStation station, final AbsoluteDate date,
  60.                        final double[] angular, final double[] sigma, final double[] baseWeight) {
  61.         this(station, date, angular, sigma, baseWeight, new ObservableSatellite(0));
  62.     }

  63.     /** Simple constructor.
  64.      * @param station ground station from which measurement is performed
  65.      * @param date date of the measurement
  66.      * @param angular observed value
  67.      * @param sigma theoretical standard deviation
  68.      * @param baseWeight base weight
  69.      * @param propagatorIndex index of the propagator related to this measurement
  70.      * @since 9.0
  71.      * @deprecated since 9.3, replaced by {@link #AngularAzEl(GroundStation, AbsoluteDate,
  72.      * double[], double[], double[], ObservableSatellite)}
  73.      */
  74.     @Deprecated
  75.     public AngularAzEl(final GroundStation station, final AbsoluteDate date,
  76.                        final double[] angular, final double[] sigma, final double[] baseWeight,
  77.                        final int propagatorIndex) {
  78.         this(station, date, angular, sigma, baseWeight, new ObservableSatellite(propagatorIndex));
  79.     }

  80.     /** Simple constructor.
  81.      * @param station ground station from which measurement is performed
  82.      * @param date date of the measurement
  83.      * @param angular observed value
  84.      * @param sigma theoretical standard deviation
  85.      * @param baseWeight base weight
  86.      * @param satellite satellite related to this measurement
  87.      * @since 9.3
  88.      */
  89.     public AngularAzEl(final GroundStation station, final AbsoluteDate date,
  90.                        final double[] angular, final double[] sigma, final double[] baseWeight,
  91.                        final ObservableSatellite satellite) {
  92.         super(date, angular, sigma, baseWeight, Arrays.asList(satellite));
  93.         addParameterDriver(station.getClockOffsetDriver());
  94.         addParameterDriver(station.getEastOffsetDriver());
  95.         addParameterDriver(station.getNorthOffsetDriver());
  96.         addParameterDriver(station.getZenithOffsetDriver());
  97.         addParameterDriver(station.getPrimeMeridianOffsetDriver());
  98.         addParameterDriver(station.getPrimeMeridianDriftDriver());
  99.         addParameterDriver(station.getPolarOffsetXDriver());
  100.         addParameterDriver(station.getPolarDriftXDriver());
  101.         addParameterDriver(station.getPolarOffsetYDriver());
  102.         addParameterDriver(station.getPolarDriftYDriver());
  103.         this.station = station;
  104.     }

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

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

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

  117.         // Azimuth/elevation 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 (clock offset, station offsets, pole, prime meridian...)

  125.         // Get the number of parameters used for derivation
  126.         // Place the selected drivers into a map
  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 FieldTransform<DerivativeStructure> offsetToInertialDownlink =
  142.                         station.getOffsetToInertial(state.getFrame(), getDate(), factory, indices);
  143.         final FieldAbsoluteDate<DerivativeStructure> downlinkDateDS =
  144.                         offsetToInertialDownlink.getFieldDate();

  145.         // Station position/velocity in inertial frame at end of the downlink leg
  146.         final TimeStampedFieldPVCoordinates<DerivativeStructure> stationDownlink =
  147.                         offsetToInertialDownlink.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(downlinkDateDS,
  148.                                                                                                             zero, zero, zero));
  149.         // Station topocentric frame (east-north-zenith) in inertial frame expressed as DerivativeStructures
  150.         final FieldVector3D<DerivativeStructure> east   = offsetToInertialDownlink.transformVector(FieldVector3D.getPlusI(field));
  151.         final FieldVector3D<DerivativeStructure> north  = offsetToInertialDownlink.transformVector(FieldVector3D.getPlusJ(field));
  152.         final FieldVector3D<DerivativeStructure> zenith = offsetToInertialDownlink.transformVector(FieldVector3D.getPlusK(field));

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

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

  158.         // Transit state
  159.         final DerivativeStructure   delta        = downlinkDateDS.durationFrom(state.getDate());
  160.         final DerivativeStructure   deltaMTauD   = tauD.negate().add(delta);
  161.         final SpacecraftState       transitState = state.shiftedBy(deltaMTauD.getValue());

  162.         // Transit state (re)computed with derivative structures
  163.         final TimeStampedFieldPVCoordinates<DerivativeStructure> transitStateDS = pvaDS.shiftedBy(deltaMTauD);

  164.         // Station-satellite vector expressed in inertial frame
  165.         final FieldVector3D<DerivativeStructure> staSat = transitStateDS.getPosition().subtract(stationDownlink.getPosition());

  166.         // Compute azimuth/elevation
  167.         final DerivativeStructure baseAzimuth = DerivativeStructure.atan2(staSat.dotProduct(east), staSat.dotProduct(north));
  168.         final double              twoPiWrap   = MathUtils.normalizeAngle(baseAzimuth.getReal(), getObservedValue()[0]) -
  169.                                                 baseAzimuth.getReal();
  170.         final DerivativeStructure azimuth     = baseAzimuth.add(twoPiWrap);
  171.         final DerivativeStructure elevation   = staSat.dotProduct(zenith).divide(staSat.getNorm()).asin();

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

  181.         // azimuth - elevation values
  182.         estimated.setEstimatedValue(azimuth.getValue(), elevation.getValue());

  183.         // Partial derivatives of azimuth/elevation with respect to state
  184.         // (beware element at index 0 is the value, not a derivative)
  185.         final double[] azDerivatives = azimuth.getAllDerivatives();
  186.         final double[] elDerivatives = elevation.getAllDerivatives();
  187.         estimated.setStateDerivatives(0,
  188.                                       Arrays.copyOfRange(azDerivatives, 1, 7), Arrays.copyOfRange(elDerivatives, 1, 7));

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

  197.         return estimated;
  198.     }
  199. }