AngularRaDec.java

  1. /* Copyright 2002-2020 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.HashMap;
  20. import java.util.Map;

  21. import org.hipparchus.analysis.differentiation.Gradient;
  22. import org.hipparchus.analysis.differentiation.GradientField;
  23. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  24. import org.hipparchus.util.MathUtils;
  25. import org.orekit.frames.FieldTransform;
  26. import org.orekit.frames.Frame;
  27. import org.orekit.propagation.SpacecraftState;
  28. import org.orekit.time.AbsoluteDate;
  29. import org.orekit.time.FieldAbsoluteDate;
  30. import org.orekit.utils.ParameterDriver;
  31. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  32. import org.orekit.utils.TimeStampedPVCoordinates;

  33. /** Class modeling an Right Ascension - Declination measurement from a ground point (station, telescope).
  34.  * The angles are given in an inertial reference frame.
  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.  * @author Maxime Journot
  41.  * @since 9.0
  42.  */
  43. public class AngularRaDec extends AbstractMeasurement<AngularRaDec> {

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

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

  48.     /** Simple constructor.
  49.      * @param station ground station from which measurement is performed
  50.      * @param referenceFrame Reference frame in which the right ascension - declination angles are given
  51.      * @param date date of the measurement
  52.      * @param angular observed value
  53.      * @param sigma theoretical standard deviation
  54.      * @param baseWeight base weight
  55.      * @param satellite satellite related to this measurement
  56.      * @since 9.3
  57.      */
  58.     public AngularRaDec(final GroundStation station, final Frame referenceFrame, final AbsoluteDate date,
  59.                         final double[] angular, final double[] sigma, final double[] baseWeight,
  60.                         final ObservableSatellite satellite) {
  61.         super(date, angular, sigma, baseWeight, Arrays.asList(satellite));
  62.         addParameterDriver(station.getClockOffsetDriver());
  63.         addParameterDriver(station.getEastOffsetDriver());
  64.         addParameterDriver(station.getNorthOffsetDriver());
  65.         addParameterDriver(station.getZenithOffsetDriver());
  66.         addParameterDriver(station.getPrimeMeridianOffsetDriver());
  67.         addParameterDriver(station.getPrimeMeridianDriftDriver());
  68.         addParameterDriver(station.getPolarOffsetXDriver());
  69.         addParameterDriver(station.getPolarDriftXDriver());
  70.         addParameterDriver(station.getPolarOffsetYDriver());
  71.         addParameterDriver(station.getPolarDriftYDriver());
  72.         this.station        = station;
  73.         this.referenceFrame = referenceFrame;
  74.     }

  75.     /** Get the ground station from which measurement is performed.
  76.      * @return ground station from which measurement is performed
  77.      */
  78.     public GroundStation getStation() {
  79.         return station;
  80.     }

  81.     /** Get the reference frame in which the right ascension - declination angles are given.
  82.      * @return reference frame in which the right ascension - declination angles are given
  83.      */
  84.     public Frame getReferenceFrame() {
  85.         return referenceFrame;
  86.     }

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

  91.         final SpacecraftState state = states[0];

  92.         // Right Ascension/elevation (in reference frame )derivatives are computed with respect to spacecraft state in inertial frame
  93.         // and station parameters
  94.         // ----------------------
  95.         //
  96.         // Parameters:
  97.         //  - 0..2 - Position of the spacecraft in inertial frame
  98.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  99.         //  - 6..n - station parameters (clock offset, station offsets, pole, prime meridian...)

  100.         // Get the number of parameters used for derivation
  101.         // Place the selected drivers into a map
  102.         int nbParams = 6;
  103.         final Map<String, Integer> indices = new HashMap<>();
  104.         for (ParameterDriver driver : getParametersDrivers()) {
  105.             if (driver.isSelected()) {
  106.                 indices.put(driver.getName(), nbParams++);
  107.             }
  108.         }
  109.         final FieldVector3D<Gradient> zero = FieldVector3D.getZero(GradientField.getField(nbParams));

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

  112.         // Transform between station and inertial frame, expressed as a gradient
  113.         // The components of station's position in offset frame are the 3 last derivative parameters
  114.         final FieldTransform<Gradient> offsetToInertialDownlink =
  115.                         station.getOffsetToInertial(state.getFrame(), getDate(), nbParams, indices);
  116.         final FieldAbsoluteDate<Gradient> downlinkDateDS =
  117.                         offsetToInertialDownlink.getFieldDate();

  118.         // Station position/velocity in inertial frame at end of the downlink leg
  119.         final TimeStampedFieldPVCoordinates<Gradient> stationDownlink =
  120.                         offsetToInertialDownlink.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(downlinkDateDS,
  121.                                                                                                             zero, zero, zero));

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

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

  127.         // Transit state
  128.         final Gradient        delta        = downlinkDateDS.durationFrom(state.getDate());
  129.         final Gradient        deltaMTauD   = tauD.negate().add(delta);
  130.         final SpacecraftState transitState = state.shiftedBy(deltaMTauD.getValue());

  131.         // Transit state (re)computed with gradients
  132.         final TimeStampedFieldPVCoordinates<Gradient> transitStateDS = pvaDS.shiftedBy(deltaMTauD);

  133.         // Station-satellite vector expressed in inertial frame
  134.         final FieldVector3D<Gradient> staSatInertial = transitStateDS.getPosition().subtract(stationDownlink.getPosition());

  135.         // Field transform from inertial to reference frame at station's reception date
  136.         final FieldTransform<Gradient> inertialToReferenceDownlink =
  137.                         state.getFrame().getTransformTo(referenceFrame, downlinkDateDS);

  138.         // Station-satellite vector in reference frame
  139.         final FieldVector3D<Gradient> staSatReference = inertialToReferenceDownlink.transformPosition(staSatInertial);

  140.         // Compute right ascension and declination
  141.         final Gradient baseRightAscension = staSatReference.getAlpha();
  142.         final double   twoPiWrap          = MathUtils.normalizeAngle(baseRightAscension.getReal(),
  143.                                                                                 getObservedValue()[0]) - baseRightAscension.getReal();
  144.         final Gradient rightAscension     = baseRightAscension.add(twoPiWrap);
  145.         final Gradient declination        = staSatReference.getDelta();

  146.         // Prepare the estimation
  147.         final EstimatedMeasurement<AngularRaDec> estimated =
  148.                         new EstimatedMeasurement<>(this, iteration, evaluation,
  149.                                                    new SpacecraftState[] {
  150.                                                        transitState
  151.                                                    }, new TimeStampedPVCoordinates[] {
  152.                                                        transitStateDS.toTimeStampedPVCoordinates(),
  153.                                                        stationDownlink.toTimeStampedPVCoordinates()
  154.                                                    });

  155.         // azimuth - elevation values
  156.         estimated.setEstimatedValue(rightAscension.getValue(), declination.getValue());

  157.         // Partial derivatives of right ascension/declination in reference frame with respect to state
  158.         // (beware element at index 0 is the value, not a derivative)
  159.         final double[] raDerivatives  = rightAscension.getGradient();
  160.         final double[] decDerivatives = declination.getGradient();
  161.         estimated.setStateDerivatives(0,
  162.                                       Arrays.copyOfRange(raDerivatives, 0, 6), Arrays.copyOfRange(decDerivatives, 0, 6));

  163.         // Partial derivatives with respect to parameters
  164.         // (beware element at index 0 is the value, not a derivative)
  165.         for (final ParameterDriver driver : getParametersDrivers()) {
  166.             final Integer index = indices.get(driver.getName());
  167.             if (index != null) {
  168.                 estimated.setParameterDerivatives(driver, raDerivatives[index], decDerivatives[index]);
  169.             }
  170.         }

  171.         return estimated;
  172.     }
  173. }