AngularRaDec.java

  1. /* Copyright 2002-2025 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.geometry.euclidean.threed.FieldVector3D;
  21. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  22. import org.hipparchus.util.MathUtils;
  23. import org.orekit.frames.FieldStaticTransform;
  24. import org.orekit.frames.Frame;
  25. import org.orekit.frames.StaticTransform;
  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 a Right Ascension - Declination measurement from a ground point (station, telescope).
  33.  * The angles are given in an inertial reference frame.
  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.  * @author Maxime Journot
  40.  * @since 9.0
  41.  */
  42. public class AngularRaDec extends GroundReceiverMeasurement<AngularRaDec> {

  43.     /** Type of the measurement. */
  44.     public static final String MEASUREMENT_TYPE = "AngularRaDec";

  45.     /** Reference frame in which the right ascension - declination angles are given. */
  46.     private final Frame referenceFrame;

  47.     /** Simple constructor.
  48.      * @param station ground station from which measurement is performed
  49.      * @param referenceFrame Reference frame in which the right ascension - declination angles are given
  50.      * @param date date of the measurement
  51.      * @param angular observed value
  52.      * @param sigma theoretical standard deviation
  53.      * @param baseWeight base weight
  54.      * @param satellite satellite related to this measurement
  55.      * @since 9.3
  56.      */
  57.     public AngularRaDec(final GroundStation station, final Frame referenceFrame, final AbsoluteDate date,
  58.                         final double[] angular, final double[] sigma, final double[] baseWeight,
  59.                         final ObservableSatellite satellite) {
  60.         super(station, false, date, angular, sigma, baseWeight, satellite);
  61.         this.referenceFrame = referenceFrame;
  62.     }

  63.     /** Get the reference frame in which the right ascension - declination angles are given.
  64.      * @return reference frame in which the right ascension - declination angles are given
  65.      */
  66.     public Frame getReferenceFrame() {
  67.         return referenceFrame;
  68.     }

  69.     /** {@inheritDoc} */
  70.     @Override
  71.     protected EstimatedMeasurementBase<AngularRaDec> theoreticalEvaluationWithoutDerivatives(final int iteration,
  72.                                                                                              final int evaluation,
  73.                                                                                              final SpacecraftState[] states) {

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

  76.         // Station-satellite vector expressed in inertial frame
  77.         final Vector3D staSatInertial = transitPV.getPosition().subtract(common.getStationDownlink().getPosition());

  78.         // Field transform from inertial to reference frame at station's reception date
  79.         final StaticTransform inertialToReferenceDownlink = common.getState().getFrame().
  80.                                                             getStaticTransformTo(referenceFrame, common.getStationDownlink().getDate());

  81.         // Station-satellite vector in reference frame
  82.         final Vector3D staSatReference = inertialToReferenceDownlink.transformVector(staSatInertial);

  83.         // Compute right ascension and declination
  84.         final double baseRightAscension = staSatReference.getAlpha();
  85.         final double twoPiWrap          = MathUtils.normalizeAngle(baseRightAscension, getObservedValue()[0]) - baseRightAscension;
  86.         final double rightAscension     = baseRightAscension + twoPiWrap;
  87.         final double declination        = staSatReference.getDelta();

  88.         // Prepare the estimation
  89.         final EstimatedMeasurementBase<AngularRaDec> estimated =
  90.                         new EstimatedMeasurementBase<>(this, iteration, evaluation,
  91.                                                        new SpacecraftState[] {
  92.                                                            common.getTransitState()
  93.                                                        }, new TimeStampedPVCoordinates[] {
  94.                                                            transitPV,
  95.                                                            common.getStationDownlink()
  96.                                                        });

  97.         // azimuth - elevation values
  98.         estimated.setEstimatedValue(rightAscension, declination);

  99.         return estimated;

  100.     }

  101.     /** {@inheritDoc} */
  102.     @Override
  103.     protected EstimatedMeasurement<AngularRaDec> theoreticalEvaluation(final int iteration, final int evaluation,
  104.                                                                        final SpacecraftState[] states) {

  105.         final SpacecraftState state = states[0];

  106.         // Right Ascension/elevation (in reference frame )derivatives are computed with respect to spacecraft state in inertial frame
  107.         // and station parameters
  108.         // ----------------------
  109.         //
  110.         // Parameters:
  111.         //  - 0..2 - Position of the spacecraft in inertial frame
  112.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  113.         //  - 6..n - station parameters (clock offset, station offsets, pole, prime meridian...)
  114.         final GroundReceiverCommonParametersWithDerivatives common = computeCommonParametersWithDerivatives(state);
  115.         final TimeStampedFieldPVCoordinates<Gradient> transitPV = common.getTransitPV();

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

  118.         // Field transform from inertial to reference frame at station's reception date
  119.         final FieldStaticTransform<Gradient> inertialToReferenceDownlink =
  120.                         state.getFrame().getStaticTransformTo(referenceFrame, common.getStationDownlink().getDate());

  121.         // Station-satellite vector in reference frame
  122.         final FieldVector3D<Gradient> staSatReference = inertialToReferenceDownlink.transformVector(staSatInertial);

  123.         // Compute right ascension and declination
  124.         final Gradient baseRightAscension = staSatReference.getAlpha();
  125.         final double   twoPiWrap          = MathUtils.normalizeAngle(baseRightAscension.getReal(),
  126.                                                                                 getObservedValue()[0]) - baseRightAscension.getReal();
  127.         final Gradient rightAscension     = baseRightAscension.add(twoPiWrap);
  128.         final Gradient declination        = staSatReference.getDelta();

  129.         // Prepare the estimation
  130.         final EstimatedMeasurement<AngularRaDec> estimated =
  131.                         new EstimatedMeasurement<>(this, iteration, evaluation,
  132.                                                    new SpacecraftState[] {
  133.                                                        common.getTransitState()
  134.                                                    }, new TimeStampedPVCoordinates[] {
  135.                                                        transitPV.toTimeStampedPVCoordinates(),
  136.                                                        common.getStationDownlink().toTimeStampedPVCoordinates()
  137.                                                    });

  138.         // azimuth - elevation values
  139.         estimated.setEstimatedValue(rightAscension.getValue(), declination.getValue());

  140.         // Partial derivatives of right ascension/declination in reference frame with respect to state
  141.         final double[] raDerivatives  = rightAscension.getGradient();
  142.         final double[] decDerivatives = declination.getGradient();
  143.         estimated.setStateDerivatives(0,
  144.                                       Arrays.copyOfRange(raDerivatives, 0, 6), Arrays.copyOfRange(decDerivatives, 0, 6));

  145.         // Partial derivatives with respect to parameters
  146.         for (final ParameterDriver driver : getParametersDrivers()) {
  147.             for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  148.                 final Integer index = common.getIndices().get(span.getData());
  149.                 if (index != null) {
  150.                     estimated.setParameterDerivatives(driver, span.getStart(), raDerivatives[index], decDerivatives[index]);
  151.                 }
  152.             }
  153.         }

  154.         return estimated;

  155.     }

  156.     /** Calculate the Line Of Sight of the given measurement.
  157.      * @param outputFrame output frame of the line of sight vector
  158.      * @return Vector3D the line of Sight of the measurement
  159.      * @since 12.0
  160.      */
  161.     public Vector3D getObservedLineOfSight(final Frame outputFrame) {
  162.         return referenceFrame.getStaticTransformTo(outputFrame, getDate())
  163.             .transformVector(new Vector3D(getObservedValue()[0], getObservedValue()[1]));
  164.     }
  165. }