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.measurements.modifiers;
18  
19  import java.util.Collections;
20  import java.util.List;
21  
22  import org.hipparchus.util.FastMath;
23  import org.orekit.estimation.measurements.EstimatedMeasurement;
24  import org.orekit.estimation.measurements.EstimatedMeasurementBase;
25  import org.orekit.estimation.measurements.EstimationModifier;
26  import org.orekit.estimation.measurements.ObservedMeasurement;
27  import org.orekit.utils.ParameterDriver;
28  import org.orekit.utils.TimeSpanMap.Span;
29  
30  /**
31   * Base class for phase ambiguity modifier.
32   * @author Bryan Cazabonne
33   * @author Luc Maisonobe
34   * @since 10.3
35   * @deprecated as of 12.1 ambiguity is managed directly by raw measurements
36   * {@link org.orekit.estimation.measurements.gnss.Phase},
37   * {@link org.orekit.estimation.measurements.gnss.OneWayGNSSPhase}
38   * and {@link org.orekit.estimation.measurements.gnss.InterSatellitesPhase}
39   */
40  @Deprecated
41  public class AbstractAmbiguityModifier {
42  
43      /** Ambiguity scale factor.
44       * <p>
45       * We use a power of 2 to avoid numeric noise introduction
46       * in the multiplications/divisions sequences.
47       * </p>
48       */
49      private static final double AMBIGUITY_SCALE = FastMath.scalb(1.0, 26);
50  
51      /** Ambiguity parameter. */
52      private final ParameterDriver ambiguity;
53  
54      /** Constructor.
55       * @param key key to identify the ambiguity
56       * @param ambiguity initial value of ambiguity
57       */
58      public AbstractAmbiguityModifier(final int key, final double ambiguity) {
59          this.ambiguity = new ParameterDriver("ambiguity-" + key, ambiguity, AMBIGUITY_SCALE,
60                                               Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
61      }
62  
63      /** Get the drivers for this modifier.
64       * @return drivers for this modifier
65       */
66      protected List<ParameterDriver> getDrivers() {
67          return Collections.singletonList(ambiguity);
68      }
69  
70      /** Modify measurement.
71       * @param <T> type of the measurements
72       * @param modifier applied modifier
73       * @param estimated measurement to modify
74       * @since 12.1
75       */
76      protected <T extends ObservedMeasurement<T>> void doModifyWithoutDerivatives(final EstimationModifier<T> modifier,
77                                                                                   final EstimatedMeasurementBase<T> estimated) {
78          // Apply the ambiguity to the measurement value
79          for (Span<String> span = ambiguity.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
80              final double[] value = estimated.getEstimatedValue();
81              value[0] += ambiguity.getValue(span.getStart());
82              estimated.modifyEstimatedValue(modifier, value);
83          }
84      }
85  
86      /** Modify measurement.
87       * @param <T> type of the measurements
88       * @param modifier applied modifier
89       * @param estimated measurement to modify
90       * @since 12.1
91       */
92      protected <T extends ObservedMeasurement<T>> void doModify(final EstimationModifier<T> modifier,
93                                                                 final EstimatedMeasurement<T> estimated) {
94  
95          // apply the ambiguity to the measurement derivatives
96          for (Span<String> span = ambiguity.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
97              if (ambiguity.isSelected()) {
98              // add the partial derivatives
99                  estimated.setParameterDerivatives(ambiguity, span.getStart(), 1.0);
100             }
101         }
102 
103         // apply the ambiguity to the measurement value
104         doModifyWithoutDerivatives(modifier, estimated);
105 
106     }
107 
108 }