AngularRaDec.java

  1. /* Copyright 2002-2018 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.errors.OrekitException;
  27. import org.orekit.frames.FieldTransform;
  28. import org.orekit.frames.Frame;
  29. import org.orekit.propagation.SpacecraftState;
  30. import org.orekit.time.AbsoluteDate;
  31. import org.orekit.time.FieldAbsoluteDate;
  32. import org.orekit.utils.ParameterDriver;
  33. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  34. import org.orekit.utils.TimeStampedPVCoordinates;

  35. /** Class modeling an Right Ascension - Declination measurement from a ground point (station, telescope).
  36.  * The angles are given in an inertial reference frame.
  37.  * The motion of the spacecraft during the signal flight time is taken into
  38.  * account. The date of the measurement corresponds to the reception on
  39.  * ground of the reflected signal.
  40.  *
  41.  * @author Thierry Ceolin
  42.  * @author Maxime Journot
  43.  * @since 9.0
  44.  */
  45. public class AngularRaDec extends AbstractMeasurement<AngularRaDec> {

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

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

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

  70.     /** Simple constructor.
  71.      * @param station ground station from which measurement is performed
  72.      * @param referenceFrame Reference frame in which the right ascension - declination angles are given
  73.      * @param date date of the measurement
  74.      * @param angular observed value
  75.      * @param sigma theoretical standard deviation
  76.      * @param baseWeight base weight
  77.      * @param propagatorIndex index of the propagator related to this measurement
  78.      * @exception OrekitException if a {@link org.orekit.utils.ParameterDriver}
  79.      * name conflict occurs
  80.      */
  81.     public AngularRaDec(final GroundStation station, final Frame referenceFrame, final AbsoluteDate date,
  82.                         final double[] angular, final double[] sigma, final double[] baseWeight,
  83.                         final int propagatorIndex)
  84.         throws OrekitException {
  85.         super(date, angular, sigma, baseWeight, Arrays.asList(propagatorIndex),
  86.               station.getEastOffsetDriver(),
  87.               station.getNorthOffsetDriver(),
  88.               station.getZenithOffsetDriver(),
  89.               station.getPrimeMeridianOffsetDriver(),
  90.               station.getPrimeMeridianDriftDriver(),
  91.               station.getPolarOffsetXDriver(),
  92.               station.getPolarDriftXDriver(),
  93.               station.getPolarOffsetYDriver(),
  94.               station.getPolarDriftYDriver());
  95.         this.station        = station;
  96.         this.referenceFrame = referenceFrame;
  97.     }

  98.     /** Get the ground station from which measurement is performed.
  99.      * @return ground station from which measurement is performed
  100.      */
  101.     public GroundStation getStation() {
  102.         return station;
  103.     }

  104.     /** Get the reference frame in which the right ascension - declination angles are given.
  105.      * @return reference frame in which the right ascension - declination angles are given
  106.      */
  107.     public Frame getReferenceFrame() {
  108.         return referenceFrame;
  109.     }

  110.     /** {@inheritDoc} */
  111.     @Override
  112.     protected EstimatedMeasurement<AngularRaDec> theoreticalEvaluation(final int iteration, final int evaluation,
  113.                                                                        final SpacecraftState[] states)
  114.         throws OrekitException {

  115.         final SpacecraftState state = states[getPropagatorsIndices().get(0)];

  116.         // Right Ascension/elevation (in reference frame )derivatives are computed with respect to spacecraft state in inertial frame
  117.         // and station parameters
  118.         // ----------------------
  119.         //
  120.         // Parameters:
  121.         //  - 0..2 - Position of the spacecraft in inertial frame
  122.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  123.         //  - 6..n - station parameters (station offsets, pole, prime meridian...)

  124.         // Get the number of parameters used for derivation
  125.         // Place the selected drivers into a map
  126.         int nbParams = 6;
  127.         final Map<String, Integer> indices = new HashMap<>();
  128.         for (ParameterDriver driver : getParametersDrivers()) {
  129.             if (driver.isSelected()) {
  130.                 indices.put(driver.getName(), nbParams++);
  131.             }
  132.         }
  133.         final DSFactory                          factory = new DSFactory(nbParams, 1);
  134.         final Field<DerivativeStructure>         field   = factory.getDerivativeField();
  135.         final FieldVector3D<DerivativeStructure> zero    = FieldVector3D.getZero(field);

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

  138.         // Transform between station and inertial frame, expressed as a derivative structure
  139.         // The components of station's position in offset frame are the 3 last derivative parameters
  140.         final AbsoluteDate downlinkDate = getDate();
  141.         final FieldAbsoluteDate<DerivativeStructure> downlinkDateDS =
  142.                         new FieldAbsoluteDate<>(field, downlinkDate);
  143.         final FieldTransform<DerivativeStructure> offsetToInertialDownlink =
  144.                         station.getOffsetToInertial(state.getFrame(), downlinkDateDS, factory, indices);

  145.         // Station position/velocity in inertial frame at end of the downlink leg
  146.         final TimeStampedFieldPVCoordinates<DerivativeStructure> stationDownlink =
  147.                         offsetToInertialDownlink.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(downlinkDateDS,
  148.                                                                                                             zero, zero, zero));

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

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

  154.         // Transit state
  155.         final double                delta        = downlinkDate.durationFrom(state.getDate());
  156.         final DerivativeStructure   deltaMTauD   = tauD.negate().add(delta);
  157.         final SpacecraftState       transitState = state.shiftedBy(deltaMTauD.getValue());

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

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

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

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

  167.         // Compute right ascension and declination
  168.         final DerivativeStructure baseRightAscension = staSatReference.getAlpha();
  169.         final double              twoPiWrap          = MathUtils.normalizeAngle(baseRightAscension.getReal(),
  170.                                                                                 getObservedValue()[0]) - baseRightAscension.getReal();
  171.         final DerivativeStructure rightAscension     = baseRightAscension.add(twoPiWrap);
  172.         final DerivativeStructure declination        = staSatReference.getDelta();

  173.         // Prepare the estimation
  174.         final EstimatedMeasurement<AngularRaDec> estimated =
  175.                         new EstimatedMeasurement<>(this, iteration, evaluation,
  176.                                                    new SpacecraftState[] {
  177.                                                        transitState
  178.                                                    }, new TimeStampedPVCoordinates[] {
  179.                                                        transitStateDS.toTimeStampedPVCoordinates(),
  180.                                                        stationDownlink.toTimeStampedPVCoordinates()
  181.                                                    });

  182.         // azimuth - elevation values
  183.         estimated.setEstimatedValue(rightAscension.getValue(), declination.getValue());

  184.         // Partial derivatives of right ascension/declination in reference frame with respect to state
  185.         // (beware element at index 0 is the value, not a derivative)
  186.         final double[] raDerivatives  = rightAscension.getAllDerivatives();
  187.         final double[] decDerivatives = declination.getAllDerivatives();
  188.         estimated.setStateDerivatives(0,
  189.                                       Arrays.copyOfRange(raDerivatives, 1, 7), Arrays.copyOfRange(decDerivatives, 1, 7));

  190.         // Partial derivatives with respect to parameters
  191.         // (beware element at index 0 is the value, not a derivative)
  192.         for (final ParameterDriver driver : getParametersDrivers()) {
  193.             final Integer index = indices.get(driver.getName());
  194.             if (index != null) {
  195.                 estimated.setParameterDerivatives(driver, raDerivatives[index + 1], decDerivatives[index + 1]);
  196.             }
  197.         }

  198.         return estimated;
  199.     }
  200. }