MeasurementHandler.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.leastsquares;

  18. import java.util.List;

  19. import org.orekit.errors.OrekitException;
  20. import org.orekit.errors.OrekitInternalError;
  21. import org.orekit.estimation.measurements.EstimatedMeasurement;
  22. import org.orekit.estimation.measurements.ObservedMeasurement;
  23. import org.orekit.propagation.SpacecraftState;
  24. import org.orekit.propagation.sampling.MultiSatStepHandler;
  25. import org.orekit.propagation.sampling.OrekitStepInterpolator;
  26. import org.orekit.time.AbsoluteDate;

  27. /** {@link org.orekit.propagation.sampling.OrekitStepHandler Step handler} picking up
  28.  * {@link ObservedMeasurement measurements}.
  29.  * @author Luc Maisonobe
  30.  * @since 8.0
  31.  */
  32. class MeasurementHandler implements MultiSatStepHandler {

  33.     /** Least squares model. */
  34.     private final Model model;

  35.     /** Underlying measurements. */
  36.     private final List<PreCompensation> precompensated;

  37.     /** Number of the next measurement. */
  38.     private int number;

  39.     /** Index of the next measurement component in the model. */
  40.     private int index;

  41.     /** Simple constructor.
  42.      * @param model least squares model
  43.      * @param precompensated underlying measurements
  44.      */
  45.     MeasurementHandler(final Model model, final List<PreCompensation> precompensated) {
  46.         this.model          = model;
  47.         this.precompensated = precompensated;
  48.     }

  49.     /**

  50.     /** {@inheritDoc} */
  51.     @Override
  52.     public void init(final List<SpacecraftState> initialStates, final AbsoluteDate target) {
  53.         number = 0;
  54.         index  = 0;
  55.     }

  56.     /** {@inheritDoc} */
  57.     @Override
  58.     public void handleStep(final List<OrekitStepInterpolator> interpolators, final boolean isLast)
  59.         throws OrekitException {

  60.         while (number < precompensated.size()) {

  61.             // Consider the next measurement to handle
  62.             final PreCompensation next = precompensated.get(number);

  63.             // Current state date for interpolator 0
  64.             final AbsoluteDate currentDate = interpolators.get(0).getCurrentState().getDate();
  65.             if ((model.isForwardPropagation()  && (next.getDate().compareTo(currentDate) > 0)) ||
  66.                 (!model.isForwardPropagation() && (next.getDate().compareTo(currentDate) < 0))) {

  67.                 // The next date is past the end of the interpolator,
  68.                 // it will be picked-up in a future step
  69.                 if (isLast) {
  70.                     // this should never happen
  71.                     throw new OrekitInternalError(null);
  72.                 }
  73.                 return;
  74.             }

  75.             // get the observed measurement
  76.             final ObservedMeasurement<?> observed = next.getMeasurement();

  77.             // estimate the theoretical measurement
  78.             final List<Integer>           indices  = observed.getPropagatorsIndices();
  79.             final SpacecraftState[]       states   = new SpacecraftState[indices.size()];
  80.             for (int i = 0; i < states.length; ++i) {
  81.                 states[i] = interpolators.get(i).getInterpolatedState(next.getDate());
  82.             }
  83.             final EstimatedMeasurement<?> estimated = observed.estimate(model.getIterationsCount(),
  84.                                                                         model.getEvaluationsCount(),
  85.                                                                         states);

  86.             // fetch the evaluated measurement to the estimator
  87.             model.fetchEvaluatedMeasurement(index, estimated);

  88.             // prepare handling of next measurement
  89.             ++number;
  90.             index += observed.getDimension();

  91.         }

  92.     }

  93. }