TurnAroundRangeTroposphericDelayModifier.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.modifiers;

  18. import java.util.Arrays;
  19. import java.util.Collections;
  20. import java.util.List;

  21. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  22. import org.orekit.errors.OrekitException;
  23. import org.orekit.errors.OrekitExceptionWrapper;
  24. import org.orekit.estimation.measurements.EstimatedMeasurement;
  25. import org.orekit.estimation.measurements.EstimationModifier;
  26. import org.orekit.estimation.measurements.GroundStation;
  27. import org.orekit.estimation.measurements.TurnAroundRange;
  28. import org.orekit.models.earth.TroposphericModel;
  29. import org.orekit.orbits.OrbitType;
  30. import org.orekit.orbits.PositionAngle;
  31. import org.orekit.propagation.Propagator;
  32. import org.orekit.propagation.SpacecraftState;
  33. import org.orekit.utils.Differentiation;
  34. import org.orekit.utils.ParameterDriver;
  35. import org.orekit.utils.ParameterFunction;
  36. import org.orekit.utils.StateFunction;

  37. /** Class modifying theoretical turn-around TurnAroundRange measurement with tropospheric delay.
  38.  * The effect of tropospheric correction on the TurnAroundRange is directly computed
  39.  * through the computation of the tropospheric delay.
  40.  *
  41.  * In general, for GNSS, VLBI, ... there is hardly any frequency dependence in the delay.
  42.  * For SLR techniques however, the frequency dependence is sensitive.
  43.  *
  44.  * @author Maxime Journot
  45.  * @since 9.0
  46.  */
  47. public class TurnAroundRangeTroposphericDelayModifier implements EstimationModifier<TurnAroundRange> {

  48.     /** Tropospheric delay model. */
  49.     private final TroposphericModel tropoModel;

  50.     /** Constructor.
  51.      *
  52.      * @param model  Tropospheric delay model appropriate for the current TurnAroundRange measurement method.
  53.      */
  54.     public TurnAroundRangeTroposphericDelayModifier(final TroposphericModel model) {
  55.         tropoModel = model;
  56.     }

  57.     /** Get the station height above mean sea level.
  58.      *
  59.      * @param station  ground station (or measuring station)
  60.      * @return the measuring station height above sea level, m
  61.      */
  62.     private double getStationHeightAMSL(final GroundStation station) {
  63.         // FIXME height should be computed with respect to geoid WGS84+GUND = EGM2008 for example
  64.         final double height = station.getBaseFrame().getPoint().getAltitude();
  65.         return height;
  66.     }

  67.     /** Compute the measurement error due to Troposphere.
  68.      * @param station station
  69.      * @param state spacecraft state
  70.      * @return the measurement error due to Troposphere
  71.      * @throws OrekitException  if frames transformations cannot be computed
  72.      */
  73.     private double rangeErrorTroposphericModel(final GroundStation station, final SpacecraftState state)
  74.         throws OrekitException {
  75.         //
  76.         final Vector3D position = state.getPVCoordinates().getPosition();

  77.         // elevation
  78.         final double elevation = station.getBaseFrame().getElevation(position,
  79.                                                                      state.getFrame(),
  80.                                                                      state.getDate());

  81.         // only consider measures above the horizon
  82.         if (elevation > 0) {
  83.             // altitude AMSL in meters
  84.             final double height = getStationHeightAMSL(station);

  85.             // Delay in meters
  86.             final double delay = tropoModel.pathDelay(elevation, height);

  87.             return delay;
  88.         }

  89.         return 0;
  90.     }

  91.     /** Compute the Jacobian of the delay term wrt state.
  92.      *
  93.      * @param station station
  94.      * @param refstate reference spacecraft state
  95.      *
  96.      * @return Jacobian of the delay wrt state
  97.      * @throws OrekitException  if frames transformations cannot be computed
  98.      */
  99.     private double[][] rangeErrorJacobianState(final GroundStation station, final SpacecraftState refstate)
  100.         throws OrekitException {
  101.         final double[][] finiteDifferencesJacobian =
  102.                         Differentiation.differentiate(new StateFunction() {
  103.                             public double[] value(final SpacecraftState state) throws OrekitException {
  104.                                 try {
  105.                                     // evaluate target's elevation with a changed target position
  106.                                     final double value = rangeErrorTroposphericModel(station, state);

  107.                                     return new double[] {value };

  108.                                 } catch (OrekitException oe) {
  109.                                     throw new OrekitExceptionWrapper(oe);
  110.                                 }
  111.                             }
  112.                         }, 1, Propagator.DEFAULT_LAW, OrbitType.CARTESIAN,
  113.                         PositionAngle.TRUE, 15.0, 3).value(refstate);

  114.         return finiteDifferencesJacobian;
  115.     }


  116.     /** Compute the derivative of the delay term wrt parameters.
  117.      *
  118.      * @param station ground station
  119.      * @param driver driver for the station offset parameter
  120.      * @param state spacecraft state
  121.      * @return derivative of the delay wrt station offset parameter
  122.      * @throws OrekitException  if frames transformations cannot be computed
  123.      */
  124.     private double rangeErrorParameterDerivative(final GroundStation station,
  125.                                                  final ParameterDriver driver,
  126.                                                  final SpacecraftState state)
  127.         throws OrekitException {

  128.         final ParameterFunction rangeError = new ParameterFunction() {
  129.             /** {@inheritDoc} */
  130.             @Override
  131.             public double value(final ParameterDriver parameterDriver) throws OrekitException {
  132.                 return rangeErrorTroposphericModel(station, state);
  133.             }
  134.         };

  135.         final ParameterFunction rangeErrorDerivative = Differentiation.differentiate(rangeError, driver, 3, 10.0);

  136.         return rangeErrorDerivative.value(driver);

  137.     }

  138.     /** {@inheritDoc} */
  139.     @Override
  140.     public List<ParameterDriver> getParametersDrivers() {
  141.         return Collections.emptyList();
  142.     }

  143.     /** {@inheritDoc} */
  144.     @Override
  145.     public void modify(final EstimatedMeasurement<TurnAroundRange> estimated)
  146.         throws OrekitException {
  147.         final TurnAroundRange measurement   = estimated.getObservedMeasurement();
  148.         final GroundStation   masterStation = measurement.getMasterStation();
  149.         final GroundStation   slaveStation  = measurement.getSlaveStation();
  150.         final SpacecraftState state         = estimated.getStates()[0];

  151.         final double[] oldValue = estimated.getEstimatedValue();

  152.         // Update estimated value taking into account the tropospheric delay.
  153.         // The tropospheric delay is directly added to the TurnAroundRange.
  154.         final double masterDelay = rangeErrorTroposphericModel(masterStation, state);
  155.         final double slaveDelay = rangeErrorTroposphericModel(slaveStation, state);
  156.         final double[] newValue = oldValue.clone();
  157.         newValue[0] = newValue[0] + masterDelay + slaveDelay;
  158.         estimated.setEstimatedValue(newValue);

  159.         // Update estimated derivatives with Jacobian of the measure wrt state
  160.         final double[][] masterDjac = rangeErrorJacobianState(masterStation, state);
  161.         final double[][] slaveDjac = rangeErrorJacobianState(slaveStation, state);
  162.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  163.         for (int irow = 0; irow < stateDerivatives.length; ++irow) {
  164.             for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  165.                 stateDerivatives[irow][jcol] += masterDjac[irow][jcol] + slaveDjac[irow][jcol];
  166.             }
  167.         }
  168.         estimated.setStateDerivatives(0, stateDerivatives);

  169.         // Update derivatives with respect to master station position
  170.         for (final ParameterDriver driver : Arrays.asList(masterStation.getEastOffsetDriver(),
  171.                                                           masterStation.getNorthOffsetDriver(),
  172.                                                           masterStation.getZenithOffsetDriver())) {
  173.             if (driver.isSelected()) {
  174.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  175.                 parameterDerivative += rangeErrorParameterDerivative(masterStation, driver, state);
  176.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  177.             }
  178.         }

  179.         // Update derivatives with respect to slave station position
  180.         for (final ParameterDriver driver : Arrays.asList(slaveStation.getEastOffsetDriver(),
  181.                                                           slaveStation.getNorthOffsetDriver(),
  182.                                                           slaveStation.getZenithOffsetDriver())) {
  183.             if (driver.isSelected()) {
  184.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  185.                 parameterDerivative += rangeErrorParameterDerivative(slaveStation, driver, state);
  186.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  187.             }
  188.         }
  189.     }

  190. }