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.     /** Ground station from which measurement is performed. */
  44.     private final GroundStation station;

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

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

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

  80.         final SpacecraftState state = states[0];

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  160.         return estimated;
  161.     }
  162. }