MeasurementHandler.java

  1. /* Copyright 2002-2020 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.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.ObservableSatellite;
  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 BatchLSODModel 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 BatchLSODModel model, final List<PreCompensation> precompensated) {
  46.         this.model          = model;
  47.         this.precompensated = precompensated;
  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.                 final ObservableSatellite satellite = observed.getSatellites().get(i);
  79.                 states[i] = interpolators.get(satellite.getPropagatorIndex()).getInterpolatedState(next.getDate());
  80.             }
  81.             final EstimatedMeasurement<?> estimated = observed.estimate(model.getIterationsCount(),
  82.                                                                         model.getEvaluationsCount(),
  83.                                                                         states);

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

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

  89.         }

  90.     }

  91. }