MeasurementHandler.java

  1. /* Copyright 2002-2017 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.             if (next.getDate().compareTo(interpolators.get(0).getCurrentState().getDate()) > 0) {
  64.                 // the next date is past the end of the interpolator,
  65.                 // it will be picked-up in a future step
  66.                 if (isLast) {
  67.                     // this should never happen
  68.                     throw new OrekitInternalError(null);
  69.                 }
  70.                 return;
  71.             }

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

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

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

  85.             // prepare handling of next measurement
  86.             ++number;
  87.             index += observed.getDimension();

  88.         }

  89.     }

  90. }