AbstractMeasurementBuilder.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.measurements.generation;

  18. import java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.List;

  21. import org.hipparchus.random.CorrelatedRandomVectorGenerator;
  22. import org.orekit.estimation.measurements.EstimatedMeasurement;
  23. import org.orekit.estimation.measurements.EstimationModifier;
  24. import org.orekit.estimation.measurements.ObservableSatellite;
  25. import org.orekit.estimation.measurements.ObservedMeasurement;
  26. import org.orekit.time.AbsoluteDate;


  27. /** Base class for {@link MeasurementBuilder measurements builders}.
  28.  * @param <T> the type of the measurement
  29.  * @author Luc Maisonobe
  30.  * @since 9.3
  31.  */
  32. public abstract class AbstractMeasurementBuilder<T extends ObservedMeasurement<T>> implements MeasurementBuilder<T> {

  33.     /** Noise source (may be null). */
  34.     private final CorrelatedRandomVectorGenerator noiseSource;

  35.     /** Modifiers that apply to the measurement.*/
  36.     private final List<EstimationModifier<T>> modifiers;

  37.     /** Theoretical standard deviation. */
  38.     private final double[] sigma;

  39.     /** Base weight. */
  40.     private final double[] baseWeight;

  41.     /** Satellites related to this measurement. */
  42.     private final ObservableSatellite[] satellites;

  43.     /** Start of the measurements time span. */
  44.     private AbsoluteDate spanStart;

  45.     /** End of the measurements time span. */
  46.     private AbsoluteDate spanEnd;

  47.     /** Simple constructor.
  48.      * @param noiseSource noise source, may be null for generating perfect measurements
  49.      * @param sigma theoretical standard deviation
  50.      * @param baseWeight base weight
  51.      * @param satellites satellites related to this builder
  52.      */
  53.     protected AbstractMeasurementBuilder(final CorrelatedRandomVectorGenerator noiseSource,
  54.                                          final double sigma, final double baseWeight,
  55.                                          final ObservableSatellite... satellites) {
  56.         this(noiseSource,
  57.              new double[] {
  58.                  sigma
  59.              }, new double[] {
  60.                  baseWeight
  61.              }, satellites);
  62.     }

  63.     /** Simple constructor.
  64.      * @param noiseSource noise source, may be null for generating perfect measurements
  65.      * @param sigma theoretical standard deviation
  66.      * @param baseWeight base weight
  67.      * @param satellites satellites related to this builder
  68.      */
  69.     protected AbstractMeasurementBuilder(final CorrelatedRandomVectorGenerator noiseSource,
  70.                                          final double[] sigma, final double[] baseWeight,
  71.                                          final ObservableSatellite... satellites) {
  72.         this.noiseSource = noiseSource;
  73.         this.modifiers   = new ArrayList<>();
  74.         this.sigma       = sigma.clone();
  75.         this.baseWeight  = baseWeight.clone();
  76.         this.satellites  = satellites.clone();
  77.     }

  78.     /** {@inheritDoc}
  79.      * <p>
  80.      * This implementation stores the time span of the measurements generation.
  81.      * </p>
  82.      */
  83.     @Override
  84.     public void init(final AbsoluteDate start, final AbsoluteDate end) {
  85.         spanStart = start;
  86.         spanEnd   = end;
  87.     }

  88.     /** {@inheritDoc} */
  89.     @Override
  90.     public void addModifier(final EstimationModifier<T> modifier) {
  91.         modifiers.add(modifier);
  92.     }

  93.     /** {@inheritDoc} */
  94.     @Override
  95.     public List<EstimationModifier<T>> getModifiers() {
  96.         return Collections.unmodifiableList(modifiers);
  97.     }

  98.     /** Get the start of the measurements time span.
  99.      * @return start of the measurements time span
  100.      */
  101.     protected AbsoluteDate getStart() {
  102.         return spanStart;
  103.     }

  104.     /** Get the end of the measurements time span.
  105.      * @return end of the measurements time span
  106.      */
  107.     protected AbsoluteDate getEnd() {
  108.         return spanEnd;
  109.     }

  110.     /** Generate a noise vector.
  111.      * @return noise vector (null if we generate perfect measurements)
  112.      */
  113.     protected double[] getNoise() {
  114.         return noiseSource == null ? null : noiseSource.nextVector();
  115.     }

  116.     /** Get the theoretical standard deviation.
  117.      * <p>
  118.      * The theoretical standard deviation is a theoretical value
  119.      * used for normalizing the residuals. It acts as a weighting
  120.      * factor to mix appropriately measurements with different units
  121.      * and different accuracy. The value has the same dimension as
  122.      * the measurement itself (i.e. when a residual is divided by
  123.      * this value, it becomes dimensionless).
  124.      * </p>
  125.      * @return expected standard deviation
  126.      * @see #getBaseWeight()
  127.      */
  128.     protected double[] getTheoreticalStandardDeviation() {
  129.         return sigma.clone();
  130.     }

  131.     /** Get the base weight associated with the measurement
  132.      * <p>
  133.      * The base weight is used on residuals already normalized thanks to
  134.      * {@link #getTheoreticalStandardDeviation()} to increase or
  135.      * decrease relative effect of some measurements with respect to
  136.      * other measurements. It is a dimensionless value, typically between
  137.      * 0 and 1 (but it can really have any non-negative value).
  138.      * </p>
  139.      * @return base weight
  140.      * @see #getTheoreticalStandardDeviation()
  141.      * @see EstimatedMeasurement#getCurrentWeight()
  142.      */
  143.     protected double[] getBaseWeight() {
  144.         return baseWeight.clone();
  145.     }

  146.     /** Get the satellites related to this measurement.
  147.      * @return satellites related to this measurement
  148.      */
  149.     protected ObservableSatellite[] getSatellites() {
  150.         return satellites.clone();
  151.     }

  152. }