AngularAzEl.java

  1. /* Copyright 2002-2022 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;

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

  22. import org.hipparchus.Field;
  23. import org.hipparchus.analysis.differentiation.Gradient;
  24. import org.hipparchus.analysis.differentiation.GradientField;
  25. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  26. import org.hipparchus.util.MathUtils;
  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.     /** Type of the measurement. */
  44.     public static final String MEASUREMENT_TYPE = "AngularAzEl";

  45.     /** Ground station from which measurement is performed. */
  46.     private final GroundStation station;

  47.     /** Simple constructor.
  48.      * @param station ground station from which measurement is performed
  49.      * @param date date of the measurement
  50.      * @param angular observed value
  51.      * @param sigma theoretical standard deviation
  52.      * @param baseWeight base weight
  53.      * @param satellite satellite related to this measurement
  54.      * @since 9.3
  55.      */
  56.     public AngularAzEl(final GroundStation station, final AbsoluteDate date,
  57.                        final double[] angular, final double[] sigma, final double[] baseWeight,
  58.                        final ObservableSatellite satellite) {
  59.         super(date, angular, sigma, baseWeight, Collections.singletonList(satellite));
  60.         addParameterDriver(station.getClockOffsetDriver());
  61.         addParameterDriver(station.getEastOffsetDriver());
  62.         addParameterDriver(station.getNorthOffsetDriver());
  63.         addParameterDriver(station.getZenithOffsetDriver());
  64.         addParameterDriver(station.getPrimeMeridianOffsetDriver());
  65.         addParameterDriver(station.getPrimeMeridianDriftDriver());
  66.         addParameterDriver(station.getPolarOffsetXDriver());
  67.         addParameterDriver(station.getPolarDriftXDriver());
  68.         addParameterDriver(station.getPolarOffsetYDriver());
  69.         addParameterDriver(station.getPolarDriftYDriver());
  70.         this.station = station;
  71.     }

  72.     /** Get the ground station from which measurement is performed.
  73.      * @return ground station from which measurement is performed
  74.      */
  75.     public GroundStation getStation() {
  76.         return station;
  77.     }

  78.     /** {@inheritDoc} */
  79.     @Override
  80.     protected EstimatedMeasurement<AngularAzEl> theoreticalEvaluation(final int iteration, final int evaluation,
  81.                                                                       final SpacecraftState[] states) {

  82.         final SpacecraftState state = states[0];

  83.         // Azimuth/elevation derivatives are computed with respect to spacecraft state in inertial frame
  84.         // and station parameters
  85.         // ----------------------
  86.         //
  87.         // Parameters:
  88.         //  - 0..2 - Position of the spacecraft in inertial frame
  89.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  90.         //  - 6..n - station parameters (clock offset, station offsets, pole, prime meridian...)

  91.         // Get the number of parameters used for derivation
  92.         // Place the selected drivers into a map
  93.         int nbParams = 6;
  94.         final Map<String, Integer> indices = new HashMap<>();
  95.         for (ParameterDriver driver : getParametersDrivers()) {
  96.             if (driver.isSelected()) {
  97.                 indices.put(driver.getName(), nbParams++);
  98.             }
  99.         }
  100.         final Field<Gradient>         field   = GradientField.getField(nbParams);
  101.         final FieldVector3D<Gradient> zero    = FieldVector3D.getZero(field);

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

  104.         // Transform between station and inertial frame, expressed as a gradient
  105.         // The components of station's position in offset frame are the 3 last derivative parameters
  106.         final FieldTransform<Gradient> offsetToInertialDownlink =
  107.                         station.getOffsetToInertial(state.getFrame(), getDate(), nbParams, indices);
  108.         final FieldAbsoluteDate<Gradient> downlinkDateDS =
  109.                         offsetToInertialDownlink.getFieldDate();

  110.         // Station position/velocity in inertial frame at end of the downlink leg
  111.         final TimeStampedFieldPVCoordinates<Gradient> stationDownlink =
  112.                         offsetToInertialDownlink.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(downlinkDateDS,
  113.                                                                                                             zero, zero, zero));
  114.         // Station topocentric frame (east-north-zenith) in inertial frame expressed as Gradient
  115.         final FieldVector3D<Gradient> east   = offsetToInertialDownlink.transformVector(FieldVector3D.getPlusI(field));
  116.         final FieldVector3D<Gradient> north  = offsetToInertialDownlink.transformVector(FieldVector3D.getPlusJ(field));
  117.         final FieldVector3D<Gradient> zenith = offsetToInertialDownlink.transformVector(FieldVector3D.getPlusK(field));

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

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

  123.         // Transit state
  124.         final Gradient        delta        = downlinkDateDS.durationFrom(state.getDate());
  125.         final Gradient        deltaMTauD   = tauD.negate().add(delta);
  126.         final SpacecraftState transitState = state.shiftedBy(deltaMTauD.getValue());

  127.         // Transit state (re)computed with derivative structures
  128.         final TimeStampedFieldPVCoordinates<Gradient> transitStateDS = pvaDS.shiftedBy(deltaMTauD);

  129.         // Station-satellite vector expressed in inertial frame
  130.         final FieldVector3D<Gradient> staSat = transitStateDS.getPosition().subtract(stationDownlink.getPosition());

  131.         // Compute azimuth/elevation
  132.         final Gradient baseAzimuth = staSat.dotProduct(east).atan2(staSat.dotProduct(north));
  133.         final double   twoPiWrap   = MathUtils.normalizeAngle(baseAzimuth.getReal(), getObservedValue()[0]) -
  134.                                                 baseAzimuth.getReal();
  135.         final Gradient azimuth     = baseAzimuth.add(twoPiWrap);
  136.         final Gradient elevation   = staSat.dotProduct(zenith).divide(staSat.getNorm()).asin();

  137.         // Prepare the estimation
  138.         final EstimatedMeasurement<AngularAzEl> estimated =
  139.                         new EstimatedMeasurement<>(this, iteration, evaluation,
  140.                                                    new SpacecraftState[] {
  141.                                                        transitState
  142.                                                    }, new TimeStampedPVCoordinates[] {
  143.                                                        transitStateDS.toTimeStampedPVCoordinates(),
  144.                                                        stationDownlink.toTimeStampedPVCoordinates()
  145.                                                    });

  146.         // azimuth - elevation values
  147.         estimated.setEstimatedValue(azimuth.getValue(), elevation.getValue());

  148.         // Partial derivatives of azimuth/elevation with respect to state
  149.         // (beware element at index 0 is the value, not a derivative)
  150.         final double[] azDerivatives = azimuth.getGradient();
  151.         final double[] elDerivatives = elevation.getGradient();
  152.         estimated.setStateDerivatives(0,
  153.                                       Arrays.copyOfRange(azDerivatives, 0, 6), Arrays.copyOfRange(elDerivatives, 0, 6));

  154.         // Set partial derivatives with respect to parameters
  155.         // (beware element at index 0 is the value, not a derivative)
  156.         for (final ParameterDriver driver : getParametersDrivers()) {
  157.             final Integer index = indices.get(driver.getName());
  158.             if (index != null) {
  159.                 estimated.setParameterDerivatives(driver, azDerivatives[index], elDerivatives[index]);
  160.             }
  161.         }

  162.         return estimated;
  163.     }
  164. }