EstimatedMeasurement.java

  1. /* Copyright 2002-2022 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.IdentityHashMap;
  19. import java.util.Map;
  20. import java.util.stream.Stream;

  21. import org.orekit.errors.OrekitIllegalArgumentException;
  22. import org.orekit.errors.OrekitMessages;
  23. import org.orekit.propagation.SpacecraftState;
  24. import org.orekit.time.AbsoluteDate;
  25. import org.orekit.utils.ParameterDriver;
  26. import org.orekit.utils.TimeStampedPVCoordinates;

  27. /** Class holding an estimated theoretical value associated to an {@link ObservedMeasurement observed measurement}.
  28.  * @param <T> the type of the measurement
  29.  * @author Luc Maisonobe
  30.  * @since 8.0
  31.  */
  32. public class EstimatedMeasurement<T extends ObservedMeasurement<T>> implements ComparableMeasurement {

  33.     /** Associated observed measurement. */
  34.     private final T observedMeasurement;

  35.     /** Iteration number. */
  36.     private final int iteration;

  37.     /** Evaluations counter. */
  38.     private final int count;

  39.     /** States of the spacecrafts. */
  40.     private final SpacecraftState[] states;

  41.     /** Coordinates of the participants in signal travel order. */
  42.     private final TimeStampedPVCoordinates[] participants;

  43.     /** Estimated value. */
  44.     private double[] estimatedValue;

  45.     /** Measurement status. */
  46.     private Status status;

  47.     /** Partial derivatives with respect to states. */
  48.     private double[][][] stateDerivatives;

  49.     /** Partial derivatives with respect to parameters. */
  50.     private final Map<ParameterDriver, double[]> parametersDerivatives;

  51.     /** Simple constructor.
  52.      * @param observedMeasurement associated observed measurement
  53.      * @param iteration iteration number
  54.      * @param count evaluations counter
  55.      * @param states states of the spacecrafts
  56.      * @param participants coordinates of the participants in signal travel order
  57.      * in inertial frame
  58.      */
  59.     public EstimatedMeasurement(final T observedMeasurement,
  60.                                 final int iteration, final int count,
  61.                                 final SpacecraftState[] states,
  62.                                 final TimeStampedPVCoordinates[] participants) {
  63.         this.observedMeasurement   = observedMeasurement;
  64.         this.iteration             = iteration;
  65.         this.count                 = count;
  66.         this.states                = states.clone();
  67.         this.participants          = participants.clone();
  68.         this.status                = Status.PROCESSED;
  69.         this.stateDerivatives      = new double[states.length][][];
  70.         this.parametersDerivatives = new IdentityHashMap<ParameterDriver, double[]>();
  71.     }

  72.     /** Get the associated observed measurement.
  73.      * @return associated observed measurement
  74.      */
  75.     public T getObservedMeasurement() {
  76.         return observedMeasurement;
  77.     }

  78.     /** {@inheritDoc} */
  79.     @Override
  80.     public AbsoluteDate getDate() {
  81.         return observedMeasurement.getDate();
  82.     }

  83.     /** Get the iteration number.
  84.      * @return iteration number
  85.      */
  86.     public int getIteration() {
  87.         return iteration;
  88.     }

  89.     /** Get the evaluations counter.
  90.      * @return evaluations counter
  91.      */
  92.     public int getCount() {
  93.         return count;
  94.     }

  95.     /** Get the states of the spacecrafts.
  96.      * @return states of the spacecrafts
  97.      */
  98.     public SpacecraftState[] getStates() {
  99.         return states.clone();
  100.     }

  101.     /** Get the coordinates of the measurements participants in signal travel order.
  102.      * <p>
  103.      * First participant (at index 0) emits the signal (it is for example a ground
  104.      * station for two-way range measurement). Last participant receives the signal
  105.      * (it is also the ground station for two-way range measurement, but a few
  106.      * milliseconds later). Intermediate participants relfect the signal (it is the
  107.      * spacecraft for two-way range measurement).
  108.      * </p>
  109.      * @return coordinates of the measurements participants in signal travel order
  110.      * in inertial frame
  111.      */
  112.     public TimeStampedPVCoordinates[] getParticipants() {
  113.         return participants.clone();
  114.     }

  115.     /** Get the time offset from first state date to measurement date.
  116.      * @return time offset from first state date to measurement date
  117.      */
  118.     public double getTimeOffset() {
  119.         return observedMeasurement.getDate().durationFrom(states[0].getDate());
  120.     }

  121.     /** {@inheritDoc} */
  122.     @Override
  123.     public double[] getObservedValue() {
  124.         return observedMeasurement.getObservedValue();
  125.     }

  126.     /** Get the estimated value.
  127.      * @return estimated value
  128.      */
  129.     public double[] getEstimatedValue() {
  130.         return estimatedValue.clone();
  131.     }

  132.     /** Set the estimated value.
  133.      * @param estimatedValue estimated value
  134.      */
  135.     public void setEstimatedValue(final double... estimatedValue) {
  136.         this.estimatedValue = estimatedValue.clone();
  137.     }

  138.     /** Get the status.
  139.      * <p>
  140.      * The status is set to {@link Status#PROCESSED PROCESSED} at construction, and
  141.      * can be reset to {@link Status#REJECTED REJECTED} later on, typically by
  142.      * {@link org.orekit.estimation.measurements.modifiers.OutlierFilter OutlierFilter}
  143.      * or {@link org.orekit.estimation.measurements.modifiers.DynamicOutlierFilter DynamicOutlierFilter}
  144.      * </p>
  145.      * @return status
  146.      */
  147.     public Status getStatus() {
  148.         return status;
  149.     }

  150.     /** Set the status.
  151.      * @param status status to set
  152.      */
  153.     public void setStatus(final Status status) {
  154.         this.status = status;
  155.     }

  156.     /** Get state size.
  157.      * <p>
  158.      * Warning, the {@link #setStateDerivatives(int, double[][])}
  159.      * method must have been called before this method is called.
  160.      * </p>
  161.      * @return state size
  162.      * @since 10.1
  163.      */
  164.     public int getStateSize() {
  165.         return stateDerivatives[0][0].length;
  166.     }

  167.     /** Get the partial derivatives of the {@link #getEstimatedValue()
  168.      * simulated measurement} with respect to state Cartesian coordinates.
  169.      * @param index index of the state, according to the {@code states}
  170.      * passed at construction
  171.      * @return partial derivatives of the simulated value (array of size
  172.      * {@link ObservedMeasurement#getDimension() dimension} x 6)
  173.      */
  174.     public double[][] getStateDerivatives(final int index) {
  175.         final double[][] sd = new double[observedMeasurement.getDimension()][];
  176.         for (int i = 0; i < observedMeasurement.getDimension(); ++i) {
  177.             sd[i] = stateDerivatives[index][i].clone();
  178.         }
  179.         return sd;
  180.     }

  181.     /** Set the partial derivatives of the {@link #getEstimatedValue()
  182.      * simulated measurement} with respect to state Cartesian coordinates.
  183.      * @param index index of the state, according to the {@code states}
  184.      * passed at construction
  185.      * @param derivatives partial derivatives with respect to state
  186.      */
  187.     public void setStateDerivatives(final int index, final double[]... derivatives) {
  188.         this.stateDerivatives[index] = new double[observedMeasurement.getDimension()][];
  189.         for (int i = 0; i < observedMeasurement.getDimension(); ++i) {
  190.             this.stateDerivatives[index][i] = derivatives[i].clone();
  191.         }
  192.     }

  193.     /** Get all the drivers with set derivatives.
  194.      * @return all the drivers with set derivatives
  195.      * @since 9.0
  196.      */
  197.     public Stream<ParameterDriver> getDerivativesDrivers() {
  198.         return parametersDerivatives.entrySet().stream().map(entry -> entry.getKey());
  199.     }

  200.     /** Get the partial derivatives of the {@link #getEstimatedValue()
  201.      * simulated measurement} with respect to a parameter.
  202.      * @param driver driver for the parameter
  203.      * @return partial derivatives of the simulated value
  204.      * @exception OrekitIllegalArgumentException if parameter is unknown
  205.      */
  206.     public double[] getParameterDerivatives(final ParameterDriver driver)
  207.         throws OrekitIllegalArgumentException {
  208.         final double[] p = parametersDerivatives.get(driver);
  209.         if (p == null) {
  210.             final StringBuilder builder = new StringBuilder();
  211.             for (final Map.Entry<ParameterDriver, double[]> entry : parametersDerivatives.entrySet()) {
  212.                 if (builder.length() > 0) {
  213.                     builder.append(", ");
  214.                 }
  215.                 builder.append(entry.getKey().getName());
  216.             }
  217.             throw new OrekitIllegalArgumentException(OrekitMessages.UNSUPPORTED_PARAMETER_NAME,
  218.                                                      driver.getName(),
  219.                                                      builder.length() > 0 ? builder.toString() : "<none>");
  220.         }
  221.         return p;
  222.     }

  223.     /** Set the partial derivatives of the {@link #getEstimatedValue()
  224.      * simulated measurement} with respect to parameter.
  225.      * @param driver driver for the parameter
  226.      * @param parameterDerivatives partial derivatives with respect to parameter
  227.      */
  228.     public void setParameterDerivatives(final ParameterDriver driver, final double... parameterDerivatives) {
  229.         parametersDerivatives.put(driver, parameterDerivatives);
  230.     }

  231.     /** Enumerate for the status of the measurement. */
  232.     public enum Status {

  233.         /** Status for processed measurements. */
  234.         PROCESSED,

  235.         /** Status for rejected measurements. */
  236.         REJECTED;

  237.     }

  238. }