AngularRaDec.java

  1. /* Copyright 2002-2019 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.DSFactory;
  23. import org.hipparchus.analysis.differentiation.DerivativeStructure;
  24. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  25. import org.hipparchus.util.MathUtils;
  26. import org.orekit.frames.FieldTransform;
  27. import org.orekit.frames.Frame;
  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 Right Ascension - Declination measurement from a ground point (station, telescope).
  35.  * The angles are given in an inertial reference frame.
  36.  * The motion of the spacecraft during the signal flight time is taken into
  37.  * account. The date of the measurement corresponds to the reception on
  38.  * ground of the reflected signal.
  39.  *
  40.  * @author Thierry Ceolin
  41.  * @author Maxime Journot
  42.  * @since 9.0
  43.  */
  44. public class AngularRaDec extends AbstractMeasurement<AngularRaDec> {

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

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

  49.     /** Simple constructor.
  50.      * <p>
  51.      * This constructor uses 0 as the index of the propagator related
  52.      * to this measurement, thus being well suited for mono-satellite
  53.      * orbit determination.
  54.      * </p>
  55.      * @param station ground station from which measurement is performed
  56.      * @param referenceFrame Reference frame in which the right ascension - declination angles are given
  57.      * @param date date of the measurement
  58.      * @param angular observed value
  59.      * @param sigma theoretical standard deviation
  60.      * @param baseWeight base weight
  61.      * @deprecated since 9.3, replaced by {@link #AngularRaDec(GroundStation, Frame, AbsoluteDate,
  62.      * double[], double[], double[], ObservableSatellite)}
  63.      */
  64.     @Deprecated
  65.     public AngularRaDec(final GroundStation station, final Frame referenceFrame, final AbsoluteDate date,
  66.                         final double[] angular, final double[] sigma, final double[] baseWeight) {
  67.         this(station, referenceFrame, date, angular, sigma, baseWeight, new ObservableSatellite(0));
  68.     }

  69.     /** Simple constructor.
  70.      * @param station ground station from which measurement is performed
  71.      * @param referenceFrame Reference frame in which the right ascension - declination angles are given
  72.      * @param date date of the measurement
  73.      * @param angular observed value
  74.      * @param sigma theoretical standard deviation
  75.      * @param baseWeight base weight
  76.      * @param propagatorIndex index of the propagator related to this measurement
  77.      * @since 9.0
  78.      * @deprecated since 9.3, replaced by {@link #AngularRaDec(GroundStation, Frame, AbsoluteDate,
  79.      * double[], double[], double[], ObservableSatellite)}
  80.      */
  81.     @Deprecated
  82.     public AngularRaDec(final GroundStation station, final Frame referenceFrame, final AbsoluteDate date,
  83.                         final double[] angular, final double[] sigma, final double[] baseWeight,
  84.                         final int propagatorIndex) {
  85.         this(station, referenceFrame, date, angular, sigma, baseWeight, new ObservableSatellite(propagatorIndex));
  86.     }

  87.     /** Simple constructor.
  88.      * @param station ground station from which measurement is performed
  89.      * @param referenceFrame Reference frame in which the right ascension - declination angles are given
  90.      * @param date date of the measurement
  91.      * @param angular observed value
  92.      * @param sigma theoretical standard deviation
  93.      * @param baseWeight base weight
  94.      * @param satellite satellite related to this measurement
  95.      * @since 9.3
  96.      */
  97.     public AngularRaDec(final GroundStation station, final Frame referenceFrame, final AbsoluteDate date,
  98.                         final double[] angular, final double[] sigma, final double[] baseWeight,
  99.                         final ObservableSatellite satellite) {
  100.         super(date, angular, sigma, baseWeight, Arrays.asList(satellite));
  101.         addParameterDriver(station.getClockOffsetDriver());
  102.         addParameterDriver(station.getEastOffsetDriver());
  103.         addParameterDriver(station.getNorthOffsetDriver());
  104.         addParameterDriver(station.getZenithOffsetDriver());
  105.         addParameterDriver(station.getPrimeMeridianOffsetDriver());
  106.         addParameterDriver(station.getPrimeMeridianDriftDriver());
  107.         addParameterDriver(station.getPolarOffsetXDriver());
  108.         addParameterDriver(station.getPolarDriftXDriver());
  109.         addParameterDriver(station.getPolarOffsetYDriver());
  110.         addParameterDriver(station.getPolarDriftYDriver());
  111.         this.station        = station;
  112.         this.referenceFrame = referenceFrame;
  113.     }

  114.     /** Get the ground station from which measurement is performed.
  115.      * @return ground station from which measurement is performed
  116.      */
  117.     public GroundStation getStation() {
  118.         return station;
  119.     }

  120.     /** Get the reference frame in which the right ascension - declination angles are given.
  121.      * @return reference frame in which the right ascension - declination angles are given
  122.      */
  123.     public Frame getReferenceFrame() {
  124.         return referenceFrame;
  125.     }

  126.     /** {@inheritDoc} */
  127.     @Override
  128.     protected EstimatedMeasurement<AngularRaDec> theoreticalEvaluation(final int iteration, final int evaluation,
  129.                                                                        final SpacecraftState[] states) {

  130.         final ObservableSatellite satellite = getSatellites().get(0);
  131.         final SpacecraftState     state     = states[satellite.getPropagatorIndex()];

  132.         // Right Ascension/elevation (in reference frame )derivatives are computed with respect to spacecraft state in inertial frame
  133.         // and station parameters
  134.         // ----------------------
  135.         //
  136.         // Parameters:
  137.         //  - 0..2 - Position of the spacecraft in inertial frame
  138.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  139.         //  - 6..n - station parameters (clock offset, station offsets, pole, prime meridian...)

  140.         // Get the number of parameters used for derivation
  141.         // Place the selected drivers into a map
  142.         int nbParams = 6;
  143.         final Map<String, Integer> indices = new HashMap<>();
  144.         for (ParameterDriver driver : getParametersDrivers()) {
  145.             if (driver.isSelected()) {
  146.                 indices.put(driver.getName(), nbParams++);
  147.             }
  148.         }
  149.         final DSFactory                          factory = new DSFactory(nbParams, 1);
  150.         final Field<DerivativeStructure>         field   = factory.getDerivativeField();
  151.         final FieldVector3D<DerivativeStructure> zero    = FieldVector3D.getZero(field);

  152.         // Coordinates of the spacecraft expressed as a derivative structure
  153.         final TimeStampedFieldPVCoordinates<DerivativeStructure> pvaDS = getCoordinates(state, 0, factory);

  154.         // Transform between station and inertial frame, expressed as a derivative structure
  155.         // The components of station's position in offset frame are the 3 last derivative parameters
  156.         final FieldTransform<DerivativeStructure> offsetToInertialDownlink =
  157.                         station.getOffsetToInertial(state.getFrame(), getDate(), factory, indices);
  158.         final FieldAbsoluteDate<DerivativeStructure> downlinkDateDS =
  159.                         offsetToInertialDownlink.getFieldDate();

  160.         // Station position/velocity in inertial frame at end of the downlink leg
  161.         final TimeStampedFieldPVCoordinates<DerivativeStructure> stationDownlink =
  162.                         offsetToInertialDownlink.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(downlinkDateDS,
  163.                                                                                                             zero, zero, zero));

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

  167.         // Downlink delay
  168.         final DerivativeStructure tauD = signalTimeOfFlight(pvaDS, stationDownlink.getPosition(), downlinkDateDS);

  169.         // Transit state
  170.         final DerivativeStructure   delta        = downlinkDateDS.durationFrom(state.getDate());
  171.         final DerivativeStructure   deltaMTauD   = tauD.negate().add(delta);
  172.         final SpacecraftState       transitState = state.shiftedBy(deltaMTauD.getValue());

  173.         // Transit state (re)computed with derivative structures
  174.         final TimeStampedFieldPVCoordinates<DerivativeStructure> transitStateDS = pvaDS.shiftedBy(deltaMTauD);

  175.         // Station-satellite vector expressed in inertial frame
  176.         final FieldVector3D<DerivativeStructure> staSatInertial = transitStateDS.getPosition().subtract(stationDownlink.getPosition());

  177.         // Field transform from inertial to reference frame at station's reception date
  178.         final FieldTransform<DerivativeStructure> inertialToReferenceDownlink =
  179.                         state.getFrame().getTransformTo(referenceFrame, downlinkDateDS);

  180.         // Station-satellite vector in reference frame
  181.         final FieldVector3D<DerivativeStructure> staSatReference = inertialToReferenceDownlink.transformPosition(staSatInertial);

  182.         // Compute right ascension and declination
  183.         final DerivativeStructure baseRightAscension = staSatReference.getAlpha();
  184.         final double              twoPiWrap          = MathUtils.normalizeAngle(baseRightAscension.getReal(),
  185.                                                                                 getObservedValue()[0]) - baseRightAscension.getReal();
  186.         final DerivativeStructure rightAscension     = baseRightAscension.add(twoPiWrap);
  187.         final DerivativeStructure declination        = staSatReference.getDelta();

  188.         // Prepare the estimation
  189.         final EstimatedMeasurement<AngularRaDec> estimated =
  190.                         new EstimatedMeasurement<>(this, iteration, evaluation,
  191.                                                    new SpacecraftState[] {
  192.                                                        transitState
  193.                                                    }, new TimeStampedPVCoordinates[] {
  194.                                                        transitStateDS.toTimeStampedPVCoordinates(),
  195.                                                        stationDownlink.toTimeStampedPVCoordinates()
  196.                                                    });

  197.         // azimuth - elevation values
  198.         estimated.setEstimatedValue(rightAscension.getValue(), declination.getValue());

  199.         // Partial derivatives of right ascension/declination in reference frame with respect to state
  200.         // (beware element at index 0 is the value, not a derivative)
  201.         final double[] raDerivatives  = rightAscension.getAllDerivatives();
  202.         final double[] decDerivatives = declination.getAllDerivatives();
  203.         estimated.setStateDerivatives(0,
  204.                                       Arrays.copyOfRange(raDerivatives, 1, 7), Arrays.copyOfRange(decDerivatives, 1, 7));

  205.         // Partial derivatives with respect to parameters
  206.         // (beware element at index 0 is the value, not a derivative)
  207.         for (final ParameterDriver driver : getParametersDrivers()) {
  208.             final Integer index = indices.get(driver.getName());
  209.             if (index != null) {
  210.                 estimated.setParameterDerivatives(driver, raDerivatives[index + 1], decDerivatives[index + 1]);
  211.             }
  212.         }

  213.         return estimated;
  214.     }
  215. }