MeasurementHandler.java

  1. /* Copyright 2002-2024 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.estimation.measurements.EstimatedMeasurement;
  20. import org.orekit.estimation.measurements.ObservableSatellite;
  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 AbstractBatchLSModel 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 AbstractBatchLSModel model, final List<PreCompensation> precompensated) {
  45.         this.model          = model;
  46.         this.precompensated = precompensated;
  47.     }

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

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

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

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

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

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

  68.             // estimate the theoretical measurement
  69.             final SpacecraftState[] states = new SpacecraftState[observed.getSatellites().size()];
  70.             for (int i = 0; i < states.length; ++i) {
  71.                 final ObservableSatellite satellite = observed.getSatellites().get(i);
  72.                 states[i] = interpolators.get(satellite.getPropagatorIndex()).getInterpolatedState(next.getDate());
  73.             }
  74.             final EstimatedMeasurement<?> estimated = observed.estimate(model.getIterationsCount(),
  75.                                                                         model.getEvaluationsCount(),
  76.                                                                         states);

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

  79.             // prepare handling of next measurement
  80.             ++number;
  81.             index += observed.getDimension();

  82.         }

  83.     }

  84. }