AngularAzEl.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.hipparchus.util.MathUtils;
  26. import org.orekit.errors.OrekitException;
  27. import org.orekit.frames.FieldTransform;
  28. import org.orekit.propagation.SpacecraftState;
  29. import org.orekit.time.AbsoluteDate;
  30. import org.orekit.time.FieldAbsoluteDate;
  31. import org.orekit.utils.ParameterDriver;
  32. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  33. import org.orekit.utils.TimeStampedPVCoordinates;

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

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

  45.     /** Simple constructor.
  46.      * <p>
  47.      * This constructor uses 0 as the index of the propagator related
  48.      * to this measurement, thus being well suited for mono-satellite
  49.      * orbit determination.
  50.      * </p>
  51.      * @param station ground station from which measurement is performed
  52.      * @param date date of the measurement
  53.      * @param angular observed value
  54.      * @param sigma theoretical standard deviation
  55.      * @param baseWeight base weight
  56.      * @exception OrekitException if a {@link org.orekit.utils.ParameterDriver}
  57.      * name conflict occurs
  58.      */
  59.     public AngularAzEl(final GroundStation station, final AbsoluteDate date,
  60.                        final double[] angular, final double[] sigma, final double[] baseWeight)
  61.         throws OrekitException {
  62.         this(station, date, angular, sigma, baseWeight, 0);
  63.     }

  64.     /** Simple constructor.
  65.      * @param station ground station from which measurement is performed
  66.      * @param date date of the measurement
  67.      * @param angular observed value
  68.      * @param sigma theoretical standard deviation
  69.      * @param baseWeight base weight
  70.      * @param propagatorIndex index of the propagator related to this measurement
  71.      * @exception OrekitException if a {@link org.orekit.utils.ParameterDriver}
  72.      * name conflict occurs
  73.      * @since 9.0
  74.      */
  75.     public AngularAzEl(final GroundStation station, final AbsoluteDate date,
  76.                        final double[] angular, final double[] sigma, final double[] baseWeight,
  77.                        final int propagatorIndex)
  78.         throws OrekitException {
  79.         super(date, angular, sigma, baseWeight, Arrays.asList(propagatorIndex),
  80.               station.getEastOffsetDriver(),
  81.               station.getNorthOffsetDriver(),
  82.               station.getZenithOffsetDriver(),
  83.               station.getPrimeMeridianOffsetDriver(),
  84.               station.getPrimeMeridianDriftDriver(),
  85.               station.getPolarOffsetXDriver(),
  86.               station.getPolarDriftXDriver(),
  87.               station.getPolarOffsetYDriver(),
  88.               station.getPolarDriftYDriver());
  89.         this.station = station;
  90.     }

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

  97.     /** {@inheritDoc} */
  98.     @Override
  99.     protected EstimatedMeasurement<AngularAzEl> theoreticalEvaluation(final int iteration, final int evaluation,
  100.                                                                       final SpacecraftState[] states)
  101.         throws OrekitException {

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

  103.         // Azimuth/elevation derivatives are computed with respect to spacecraft state in inertial frame
  104.         // and station parameters
  105.         // ----------------------
  106.         //
  107.         // Parameters:
  108.         //  - 0..2 - Position of the spacecraft in inertial frame
  109.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  110.         //  - 6..n - station parameters (station offsets, pole, prime meridian...)

  111.         // Get the number of parameters used for derivation
  112.         // Place the selected drivers into a map
  113.         int nbParams = 6;
  114.         final Map<String, Integer> indices = new HashMap<>();
  115.         for (ParameterDriver driver : getParametersDrivers()) {
  116.             if (driver.isSelected()) {
  117.                 indices.put(driver.getName(), nbParams++);
  118.             }
  119.         }
  120.         final DSFactory                          factory = new DSFactory(nbParams, 1);
  121.         final Field<DerivativeStructure>         field   = factory.getDerivativeField();
  122.         final FieldVector3D<DerivativeStructure> zero    = FieldVector3D.getZero(field);

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

  125.         // Transform between station and inertial frame, expressed as a derivative structure
  126.         // The components of station's position in offset frame are the 3 last derivative parameters
  127.         final AbsoluteDate downlinkDate = getDate();
  128.         final FieldAbsoluteDate<DerivativeStructure> downlinkDateDS =
  129.                         new FieldAbsoluteDate<>(field, downlinkDate);
  130.         final FieldTransform<DerivativeStructure> offsetToInertialDownlink =
  131.                         station.getOffsetToInertial(state.getFrame(), downlinkDateDS, factory, indices);

  132.         // Station position/velocity in inertial frame at end of the downlink leg
  133.         final TimeStampedFieldPVCoordinates<DerivativeStructure> stationDownlink =
  134.                         offsetToInertialDownlink.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(downlinkDateDS,
  135.                                                                                                             zero, zero, zero));
  136.         // Station topocentric frame (east-north-zenith) in inertial frame expressed as DerivativeStructures
  137.         final FieldVector3D<DerivativeStructure> east   = offsetToInertialDownlink.transformVector(FieldVector3D.getPlusI(field));
  138.         final FieldVector3D<DerivativeStructure> north  = offsetToInertialDownlink.transformVector(FieldVector3D.getPlusJ(field));
  139.         final FieldVector3D<DerivativeStructure> zenith = offsetToInertialDownlink.transformVector(FieldVector3D.getPlusK(field));

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

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

  145.         // Transit state
  146.         final double                delta        = downlinkDate.durationFrom(state.getDate());
  147.         final DerivativeStructure   deltaMTauD   = tauD.negate().add(delta);
  148.         final SpacecraftState       transitState = state.shiftedBy(deltaMTauD.getValue());

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

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

  153.         // Compute azimuth/elevation
  154.         final DerivativeStructure baseAzimuth = DerivativeStructure.atan2(staSat.dotProduct(east), staSat.dotProduct(north));
  155.         final double              twoPiWrap   = MathUtils.normalizeAngle(baseAzimuth.getReal(), getObservedValue()[0]) -
  156.                                                 baseAzimuth.getReal();
  157.         final DerivativeStructure azimuth     = baseAzimuth.add(twoPiWrap);
  158.         final DerivativeStructure elevation   = staSat.dotProduct(zenith).divide(staSat.getNorm()).asin();

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

  168.         // azimuth - elevation values
  169.         estimated.setEstimatedValue(azimuth.getValue(), elevation.getValue());

  170.         // Partial derivatives of azimuth/elevation with respect to state
  171.         // (beware element at index 0 is the value, not a derivative)
  172.         final double[] azDerivatives = azimuth.getAllDerivatives();
  173.         final double[] elDerivatives = elevation.getAllDerivatives();
  174.         estimated.setStateDerivatives(0,
  175.                                       Arrays.copyOfRange(azDerivatives, 1, 7), Arrays.copyOfRange(elDerivatives, 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, azDerivatives[index + 1], elDerivatives[index + 1]);
  182.             }
  183.         }

  184.         return estimated;
  185.     }
  186. }