AngularAzEl.java

  1. /* Copyright 2002-2020 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.HashMap;
  20. import java.util.Map;

  21. import org.hipparchus.Field;
  22. import org.hipparchus.analysis.differentiation.Gradient;
  23. import org.hipparchus.analysis.differentiation.GradientField;
  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.      * @param station ground station from which measurement is performed
  46.      * @param date date of the measurement
  47.      * @param angular observed value
  48.      * @param sigma theoretical standard deviation
  49.      * @param baseWeight base weight
  50.      * @param satellite satellite related to this measurement
  51.      * @since 9.3
  52.      */
  53.     public AngularAzEl(final GroundStation station, final AbsoluteDate date,
  54.                        final double[] angular, final double[] sigma, final double[] baseWeight,
  55.                        final ObservableSatellite satellite) {
  56.         super(date, angular, sigma, baseWeight, Arrays.asList(satellite));
  57.         addParameterDriver(station.getClockOffsetDriver());
  58.         addParameterDriver(station.getEastOffsetDriver());
  59.         addParameterDriver(station.getNorthOffsetDriver());
  60.         addParameterDriver(station.getZenithOffsetDriver());
  61.         addParameterDriver(station.getPrimeMeridianOffsetDriver());
  62.         addParameterDriver(station.getPrimeMeridianDriftDriver());
  63.         addParameterDriver(station.getPolarOffsetXDriver());
  64.         addParameterDriver(station.getPolarDriftXDriver());
  65.         addParameterDriver(station.getPolarOffsetYDriver());
  66.         addParameterDriver(station.getPolarDriftYDriver());
  67.         this.station = station;
  68.     }

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

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

  79.         final SpacecraftState state = states[0];

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

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

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

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

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

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

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

  120.         // Transit state
  121.         final Gradient        delta        = downlinkDateDS.durationFrom(state.getDate());
  122.         final Gradient        deltaMTauD   = tauD.negate().add(delta);
  123.         final SpacecraftState transitState = state.shiftedBy(deltaMTauD.getValue());

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

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

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

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

  143.         // azimuth - elevation values
  144.         estimated.setEstimatedValue(azimuth.getValue(), elevation.getValue());

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

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

  159.         return estimated;
  160.     }
  161. }