MeasurementHandler.java

  1. /* Copyright 2002-2019 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.OrekitInternalError;
  20. import org.orekit.estimation.measurements.EstimatedMeasurement;
  21. import org.orekit.estimation.measurements.ObservedMeasurement;
  22. import org.orekit.propagation.SpacecraftState;
  23. import org.orekit.propagation.sampling.MultiSatStepHandler;
  24. import org.orekit.propagation.sampling.OrekitStepInterpolator;
  25. import org.orekit.time.AbsoluteDate;

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

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

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

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

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

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

  48.     /**

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

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

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

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

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

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

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

  75.             // estimate the theoretical measurement
  76.             final SpacecraftState[] states = new SpacecraftState[observed.getSatellites().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. }