OneWayGNSSPhaseBuilder.java

  1. /* Copyright 2002-2024 Luc Maisonobe
  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.measurements.generation;

  18. import java.util.Map;
  19. import java.util.function.Function;
  20. import java.util.function.ToDoubleFunction;

  21. import org.hipparchus.random.CorrelatedRandomVectorGenerator;
  22. import org.orekit.estimation.measurements.EstimationModifier;
  23. import org.orekit.estimation.measurements.ObservableSatellite;
  24. import org.orekit.estimation.measurements.QuadraticClockModel;
  25. import org.orekit.estimation.measurements.gnss.AmbiguityCache;
  26. import org.orekit.estimation.measurements.gnss.OneWayGNSSPhase;
  27. import org.orekit.propagation.SpacecraftState;
  28. import org.orekit.propagation.sampling.OrekitStepInterpolator;
  29. import org.orekit.time.AbsoluteDate;
  30. import org.orekit.utils.ParameterDriver;


  31. /** Builder for {@link OneWayGNSSPhase} measurements.
  32.  * @author Luc Maisonobe
  33.  * @since 12.0
  34.  */
  35. public class OneWayGNSSPhaseBuilder extends AbstractMeasurementBuilder<OneWayGNSSPhase> {

  36.     /** Cache for ambiguities.
  37.      * @since 12.1
  38.      */
  39.     private final AmbiguityCache cache;

  40.     /** Wavelength of the phase observed value [m]. */
  41.     private final double wavelength;

  42.     /** Satellite which receives the signal and performs the measurement. */
  43.     private final ObservableSatellite local;

  44.     /** Satellite which simply emits the signal. */
  45.     private final ObservableSatellite remote;

  46.     /** Clock model of the remote satellite that provides clock offset. */
  47.     private final QuadraticClockModel remoteClockModel;

  48.     /** Temporary builder for clock models.
  49.      * @deprecated this is a temporary field, it will be removed in Orekit 13.0
  50.      */
  51.     @Deprecated
  52.     private Function<AbsoluteDate, QuadraticClockModel> clockBuilder;

  53.     /** Simple constructor.
  54.      * @param noiseSource noise source, may be null for generating perfect measurements
  55.      * @param local satellite which receives the signal and performs the measurement
  56.      * @param remote satellite which simply emits the signal
  57.      * @param remoteClockModel clock model of the remote satellite that provides clock offset
  58.      * @param wavelength phase observed value wavelength (m)
  59.      * @param sigma theoretical standard deviation
  60.      * @param baseWeight base weight
  61.      * @deprecated as of 12.1, replaced by {@link #OneWayGNSSPhaseBuilder(CorrelatedRandomVectorGenerator,
  62.      * ObservableSatellite, ObservableSatellite, QuadraticClockModel,
  63.      * double, double, double, AmbiguityCache)}
  64.      */
  65.     @Deprecated
  66.     public OneWayGNSSPhaseBuilder(final CorrelatedRandomVectorGenerator noiseSource,
  67.                                   final ObservableSatellite local, final ObservableSatellite remote,
  68.                                   final ToDoubleFunction<AbsoluteDate> remoteClockModel,
  69.                                   final double wavelength, final double sigma, final double baseWeight) {
  70.         this(noiseSource, local, remote, null, wavelength, sigma, baseWeight,
  71.              AmbiguityCache.DEFAULT_CACHE);
  72.         this.clockBuilder = date -> {
  73.             final double cM = remoteClockModel.applyAsDouble(date.shiftedBy(-1));
  74.             final double c0 = remoteClockModel.applyAsDouble(date);
  75.             final double cP = remoteClockModel.applyAsDouble(date.shiftedBy(1));
  76.             return new QuadraticClockModel(date, c0, 0.5 * (cP - cM), 0.5 * (cP + cM) - c0);
  77.         };
  78.     }

  79.     /** Simple constructor.
  80.      * @param noiseSource noise source, may be null for generating perfect measurements
  81.      * @param local satellite which receives the signal and performs the measurement
  82.      * @param remote satellite which simply emits the signal
  83.      * @param remoteClockModel clock model of the remote satellite that provides clock offset
  84.      * @param wavelength phase observed value wavelength (m)
  85.      * @param sigma theoretical standard deviation
  86.      * @param baseWeight base weight
  87.      * @param cache from which ambiguity drive should come
  88.      * @since 12.1
  89.      */
  90.     public OneWayGNSSPhaseBuilder(final CorrelatedRandomVectorGenerator noiseSource,
  91.                                   final ObservableSatellite local, final ObservableSatellite remote,
  92.                                   final QuadraticClockModel remoteClockModel,
  93.                                   final double wavelength, final double sigma, final double baseWeight,
  94.                                   final AmbiguityCache cache) {
  95.         super(noiseSource, sigma, baseWeight, local, remote);
  96.         this.wavelength       = wavelength;
  97.         this.local            = local;
  98.         this.remote           = remote;
  99.         this.remoteClockModel = remoteClockModel;
  100.         this.cache            = cache;
  101.     }

  102.     /** {@inheritDoc} */
  103.     @Override
  104.     public OneWayGNSSPhase build(final AbsoluteDate date,
  105.                                  final Map<ObservableSatellite, OrekitStepInterpolator> interpolators) {

  106.         final double sigma               = getTheoreticalStandardDeviation()[0];
  107.         final double baseWeight          = getBaseWeight()[0];
  108.         final SpacecraftState[] relevant = new SpacecraftState[] {
  109.             interpolators.get(local).getInterpolatedState(date),
  110.             interpolators.get(remote).getInterpolatedState(date)
  111.         };

  112.         // temporary hack to build QuadraticClockModel from ToDoubleFunction<AbsoluteDate>
  113.         // for compatibility purposes
  114.         final QuadraticClockModel clockModel = remoteClockModel != null ?
  115.                                                remoteClockModel :
  116.                                                clockBuilder.apply(date);

  117.         // create a dummy measurement
  118.         final OneWayGNSSPhase dummy = new OneWayGNSSPhase(interpolators.get(remote),
  119.                                                           remote.getName(),
  120.                                                           clockModel, date,
  121.                                                           Double.NaN, wavelength,
  122.                                                           sigma, baseWeight, local,
  123.                                                           cache);
  124.         for (final EstimationModifier<OneWayGNSSPhase> modifier : getModifiers()) {
  125.             dummy.addModifier(modifier);
  126.         }

  127.         // set a reference date for parameters missing one
  128.         for (final ParameterDriver driver : dummy.getParametersDrivers()) {
  129.             if (driver.getReferenceDate() == null) {
  130.                 final AbsoluteDate start = getStart();
  131.                 final AbsoluteDate end   = getEnd();
  132.                 driver.setReferenceDate(start.durationFrom(end) <= 0 ? start : end);
  133.             }
  134.         }

  135.         // estimate the perfect value of the measurement
  136.         double phase = dummy.estimateWithoutDerivatives(relevant).getEstimatedValue()[0];

  137.         // add the noise
  138.         final double[] noise = getNoise();
  139.         if (noise != null) {
  140.             phase += noise[0];
  141.         }

  142.         // generate measurement
  143.         final OneWayGNSSPhase measurement = new OneWayGNSSPhase(interpolators.get(remote),
  144.                                                                 remote.getName(),
  145.                                                                 clockModel, date,
  146.                                                                 phase, wavelength, sigma, baseWeight, local,
  147.                                                                 cache);
  148.         for (final EstimationModifier<OneWayGNSSPhase> modifier : getModifiers()) {
  149.             measurement.addModifier(modifier);
  150.         }
  151.         return measurement;

  152.     }

  153. }