AngularAzEl.java

  1. /* Copyright 2002-2023 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 org.hipparchus.analysis.differentiation.Gradient;
  20. import org.hipparchus.analysis.differentiation.GradientField;
  21. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  22. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  23. import org.hipparchus.util.FastMath;
  24. import org.hipparchus.util.MathUtils;
  25. import org.orekit.frames.Frame;
  26. import org.orekit.propagation.SpacecraftState;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.utils.ParameterDriver;
  29. import org.orekit.utils.TimeSpanMap.Span;
  30. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  31. import org.orekit.utils.TimeStampedPVCoordinates;

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

  41.     /** Type of the measurement. */
  42.     public static final String MEASUREMENT_TYPE = "AngularAzEl";

  43.     /** Simple constructor.
  44.      * @param station ground station from which measurement is performed
  45.      * @param date date of the measurement
  46.      * @param angular observed value
  47.      * @param sigma theoretical standard deviation
  48.      * @param baseWeight base weight
  49.      * @param satellite satellite related to this measurement
  50.      * @since 9.3
  51.      */
  52.     public AngularAzEl(final GroundStation station, final AbsoluteDate date,
  53.                        final double[] angular, final double[] sigma, final double[] baseWeight,
  54.                        final ObservableSatellite satellite) {
  55.         super(station, false, date, angular, sigma, baseWeight, satellite);
  56.     }

  57.     /** {@inheritDoc} */
  58.     @Override
  59.     protected EstimatedMeasurementBase<AngularAzEl> theoreticalEvaluationWithoutDerivatives(final int iteration,
  60.                                                                                             final int evaluation,
  61.                                                                                             final SpacecraftState[] states) {

  62.         final GroundReceiverCommonParametersWithoutDerivatives common = computeCommonParametersWithout(states[0]);
  63.         final TimeStampedPVCoordinates transitPV = common.getTransitPV();

  64.         // Station topocentric frame (east-north-zenith) in inertial frame expressed as Gradient
  65.         final Vector3D east   = common.getOffsetToInertialDownlink().transformVector(Vector3D.PLUS_I);
  66.         final Vector3D north  = common.getOffsetToInertialDownlink().transformVector(Vector3D.PLUS_J);
  67.         final Vector3D zenith = common.getOffsetToInertialDownlink().transformVector(Vector3D.PLUS_K);

  68.         // Station-satellite vector expressed in inertial frame
  69.         final Vector3D staSat = transitPV.getPosition().subtract(common.getStationDownlink().getPosition());

  70.         // Compute azimuth/elevation
  71.         final double baseAzimuth = FastMath.atan2(staSat.dotProduct(east), staSat.dotProduct(north));
  72.         final double twoPiWrap   = MathUtils.normalizeAngle(baseAzimuth, getObservedValue()[0]) - baseAzimuth;
  73.         final double azimuth     = baseAzimuth + twoPiWrap;
  74.         final double elevation   = FastMath.asin(staSat.dotProduct(zenith) / staSat.getNorm());

  75.         // Prepare the estimation
  76.         final EstimatedMeasurementBase<AngularAzEl> estimated =
  77.                         new EstimatedMeasurementBase<>(this, iteration, evaluation,
  78.                                                        new SpacecraftState[] {
  79.                                                            common.getTransitState()
  80.                                                        }, new TimeStampedPVCoordinates[] {
  81.                                                            transitPV,
  82.                                                            common.getStationDownlink()
  83.                                                        });

  84.         // azimuth - elevation values
  85.         estimated.setEstimatedValue(azimuth, elevation);

  86.         return estimated;

  87.     }

  88.     /** {@inheritDoc} */
  89.     @Override
  90.     protected EstimatedMeasurement<AngularAzEl> theoreticalEvaluation(final int iteration, final int evaluation,
  91.                                                                       final SpacecraftState[] states) {

  92.         final SpacecraftState state = states[0];

  93.         // Azimuth/elevation derivatives are computed with respect to spacecraft state in inertial frame
  94.         // and station parameters
  95.         // ----------------------
  96.         //
  97.         // Parameters:
  98.         //  - 0..2 - Position of the spacecraft in inertial frame
  99.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  100.         //  - 6..n - station parameters (clock offset, station offsets, pole, prime meridian...)
  101.         final GroundReceiverCommonParametersWithDerivatives common = computeCommonParametersWithDerivatives(state);
  102.         final TimeStampedFieldPVCoordinates<Gradient> transitPV = common.getTransitPV();

  103.         // Station topocentric frame (east-north-zenith) in inertial frame expressed as Gradient
  104.         final GradientField field = common.getTauD().getField();
  105.         final FieldVector3D<Gradient> east   = common.getOffsetToInertialDownlink().transformVector(FieldVector3D.getPlusI(field));
  106.         final FieldVector3D<Gradient> north  = common.getOffsetToInertialDownlink().transformVector(FieldVector3D.getPlusJ(field));
  107.         final FieldVector3D<Gradient> zenith = common.getOffsetToInertialDownlink().transformVector(FieldVector3D.getPlusK(field));

  108.         // Station-satellite vector expressed in inertial frame
  109.         final FieldVector3D<Gradient> staSat = transitPV.getPosition().subtract(common.getStationDownlink().getPosition());

  110.         // Compute azimuth/elevation
  111.         final Gradient baseAzimuth = staSat.dotProduct(east).atan2(staSat.dotProduct(north));
  112.         final double   twoPiWrap   = MathUtils.normalizeAngle(baseAzimuth.getReal(), getObservedValue()[0]) -
  113.                                                 baseAzimuth.getReal();
  114.         final Gradient azimuth     = baseAzimuth.add(twoPiWrap);
  115.         final Gradient elevation   = staSat.dotProduct(zenith).divide(staSat.getNorm()).asin();

  116.         // Prepare the estimation
  117.         final EstimatedMeasurement<AngularAzEl> estimated =
  118.                         new EstimatedMeasurement<>(this, iteration, evaluation,
  119.                                                    new SpacecraftState[] {
  120.                                                        common.getTransitState()
  121.                                                    }, new TimeStampedPVCoordinates[] {
  122.                                                        transitPV.toTimeStampedPVCoordinates(),
  123.                                                        common.getStationDownlink().toTimeStampedPVCoordinates()
  124.                                                    });

  125.         // azimuth - elevation values
  126.         estimated.setEstimatedValue(azimuth.getValue(), elevation.getValue());

  127.         // Partial derivatives of azimuth/elevation with respect to state
  128.         // (beware element at index 0 is the value, not a derivative)
  129.         final double[] azDerivatives = azimuth.getGradient();
  130.         final double[] elDerivatives = elevation.getGradient();
  131.         estimated.setStateDerivatives(0,
  132.                                       Arrays.copyOfRange(azDerivatives, 0, 6), Arrays.copyOfRange(elDerivatives, 0, 6));

  133.         // Set partial derivatives with respect to parameters
  134.         // (beware element at index 0 is the value, not a derivative)
  135.         for (final ParameterDriver driver : getParametersDrivers()) {

  136.             for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  137.                 final Integer index = common.getIndices().get(span.getData());
  138.                 if (index != null) {
  139.                     estimated.setParameterDerivatives(driver, span.getStart(), azDerivatives[index], elDerivatives[index]);
  140.                 }
  141.             }
  142.         }

  143.         return estimated;

  144.     }

  145.     /** Calculate the Line Of Sight of the given measurement.
  146.      * @param outputFrame output frame of the line of sight vector
  147.      * @return Vector3D the line of Sight of the measurement
  148.      */
  149.     public Vector3D getObservedLineOfSight(final Frame outputFrame) {
  150.         return getStation().getBaseFrame().getStaticTransformTo(outputFrame, getDate())
  151.             .transformVector(new Vector3D(MathUtils.SEMI_PI - getObservedValue()[0], getObservedValue()[1]));
  152.     }

  153. }