1   /* Copyright 2002-2025 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.List;
20  
21  import org.hipparchus.CalculusFieldElement;
22  import org.hipparchus.Field;
23  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
24  import org.hipparchus.geometry.euclidean.threed.Vector3D;
25  import org.orekit.attitudes.FrameAlignedProvider;
26  import org.orekit.estimation.measurements.EstimatedMeasurement;
27  import org.orekit.estimation.measurements.EstimatedMeasurementBase;
28  import org.orekit.estimation.measurements.EstimationModifier;
29  import org.orekit.estimation.measurements.GroundStation;
30  import org.orekit.estimation.measurements.TDOA;
31  import org.orekit.models.earth.troposphere.TroposphericModel;
32  import org.orekit.propagation.FieldSpacecraftState;
33  import org.orekit.propagation.SpacecraftState;
34  import org.orekit.utils.Constants;
35  import org.orekit.utils.FieldTrackingCoordinates;
36  import org.orekit.utils.ParameterDriver;
37  import org.orekit.utils.TrackingCoordinates;
38  
39  /** Class modifying theoretical TDOA measurements with tropospheric delay.
40   * <p>
41   * The effect of tropospheric correction on the TDOA is a time delay computed
42   * directly from the difference in tropospheric delays for each downlink.
43   * </p><p>
44   * Tropospheric delay is not frequency dependent for signals up to 15 GHz.
45   * </p>
46   * @author Pascal Parraud
47   * @since 11.2
48   */
49  public class TDOATroposphericDelayModifier implements EstimationModifier<TDOA> {
50  
51      /** Tropospheric delay model. */
52      private final TroposphericModel tropoModel;
53  
54      /** Constructor.
55       *
56       * @param model tropospheric model appropriate for the current TDOA measurement method.
57       * @since 12.1
58       */
59      public TDOATroposphericDelayModifier(final TroposphericModel model) {
60          tropoModel = model;
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      public String getEffectName() {
66          return "troposphere";
67      }
68  
69      /** Compute the measurement error due to Troposphere on a single downlink.
70       * @param station station
71       * @param state spacecraft state
72       * @return the measurement error due to Troposphere (s)
73       */
74      private double timeErrorTroposphericModel(final GroundStation station, final SpacecraftState state) {
75          final Vector3D position = state.getPosition();
76  
77          // tracking
78          final TrackingCoordinates trackingCoordinates =
79                          station.getBaseFrame().getTrackingCoordinates(position, state.getFrame(), state.getDate());
80  
81          // only consider measurements above the horizon
82          if (trackingCoordinates.getElevation() > 0) {
83              // Delay in meters
84              final double delay = tropoModel.pathDelay(trackingCoordinates,
85                                                        station.getOffsetGeodeticPoint(state.getDate()),
86                                                        tropoModel.getParameters(state.getDate()), state.getDate()).
87                                   getDelay();
88              // return delay in seconds
89              return delay / Constants.SPEED_OF_LIGHT;
90          }
91  
92          return 0;
93      }
94  
95      /** Compute the measurement error due to Troposphere on a single downlink.
96       * @param <T> type of the element
97       * @param station station
98       * @param state spacecraft state
99       * @param parameters tropospheric model parameters
100      * @return the measurement error due to Troposphere (s)
101      */
102     private <T extends CalculusFieldElement<T>> T timeErrorTroposphericModel(final GroundStation station,
103                                                                              final FieldSpacecraftState<T> state,
104                                                                              final T[] parameters) {
105         // Field
106         final Field<T> field = state.getDate().getField();
107         final T zero         = field.getZero();
108 
109         // tracking
110         final FieldVector3D<T> pos = state.getPosition();
111         final FieldTrackingCoordinates<T> trackingCoordinates =
112                         station.getBaseFrame().getTrackingCoordinates(pos, state.getFrame(), state.getDate());
113 
114         // only consider measurements above the horizon
115         if (trackingCoordinates.getElevation().getReal() > 0) {
116             // delay in meters
117             final T delay = tropoModel.pathDelay(trackingCoordinates,
118                                                  station.getOffsetGeodeticPoint(state.getDate()),
119                                                  parameters, state.getDate()).
120                             getDelay();
121             // return delay in seconds
122             return delay.divide(Constants.SPEED_OF_LIGHT);
123         }
124 
125         return zero;
126     }
127 
128     /** {@inheritDoc} */
129     @Override
130     public List<ParameterDriver> getParametersDrivers() {
131         return tropoModel.getParametersDrivers();
132     }
133 
134     /** {@inheritDoc} */
135     @Override
136     public void modifyWithoutDerivatives(final EstimatedMeasurementBase<TDOA> estimated) {
137 
138         final TDOA            measurement   = estimated.getObservedMeasurement();
139         final GroundStation   primeStation  = measurement.getPrimeStation();
140         final GroundStation   secondStation = measurement.getSecondStation();
141 
142         TDOAModifierUtil.modifyWithoutDerivatives(estimated,  primeStation, secondStation,
143                                                   this::timeErrorTroposphericModel, this);
144 
145     }
146 
147     /** {@inheritDoc} */
148     @Override
149     public void modify(final EstimatedMeasurement<TDOA> estimated) {
150 
151         final TDOA            measurement   = estimated.getObservedMeasurement();
152         final GroundStation   primeStation  = measurement.getPrimeStation();
153         final GroundStation   secondStation = measurement.getSecondStation();
154         final SpacecraftState state         = estimated.getStates()[0];
155 
156         TDOAModifierUtil.modify(estimated, tropoModel,
157                                 new ModifierGradientConverter(state, 6, new FrameAlignedProvider(state.getFrame())),
158                                 primeStation, secondStation,
159                                 this::timeErrorTroposphericModel,
160                                 this::timeErrorTroposphericModel,
161                                 this);
162 
163     }
164 
165 }