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.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       * @deprecated as of 12.1, replaced by {@link #TDOATroposphericDelayModifier(TroposphericModel)}
58       */
59      @Deprecated
60      public TDOATroposphericDelayModifier(final org.orekit.models.earth.troposphere.DiscreteTroposphericModel model) {
61          this(new org.orekit.models.earth.troposphere.TroposphericModelAdapter(model));
62      }
63  
64      /** Constructor.
65       *
66       * @param model tropospheric model appropriate for the current TDOA measurement method.
67       * @since 12.1
68       */
69      public TDOATroposphericDelayModifier(final TroposphericModel model) {
70          tropoModel = model;
71      }
72  
73      /** Compute the measurement error due to Troposphere on a single downlink.
74       * @param station station
75       * @param state spacecraft state
76       * @return the measurement error due to Troposphere (s)
77       */
78      private double timeErrorTroposphericModel(final GroundStation station, final SpacecraftState state) {
79          final Vector3D position = state.getPosition();
80  
81          // tracking
82          final TrackingCoordinates trackingCoordinates =
83                          station.getBaseFrame().getTrackingCoordinates(position, state.getFrame(), state.getDate());
84  
85          // only consider measurements above the horizon
86          if (trackingCoordinates.getElevation() > 0) {
87              // Delay in meters
88              final double delay = tropoModel.pathDelay(trackingCoordinates,
89                                                        station.getOffsetGeodeticPoint(state.getDate()),
90                                                        station.getPressureTemperatureHumidity(state.getDate()),
91                                                        tropoModel.getParameters(state.getDate()), state.getDate()).
92                                   getDelay();
93              // return delay in seconds
94              return delay / Constants.SPEED_OF_LIGHT;
95          }
96  
97          return 0;
98      }
99  
100     /** Compute the measurement error due to Troposphere on a single downlink.
101      * @param <T> type of the element
102      * @param station station
103      * @param state spacecraft state
104      * @param parameters tropospheric model parameters
105      * @return the measurement error due to Troposphere (s)
106      */
107     private <T extends CalculusFieldElement<T>> T timeErrorTroposphericModel(final GroundStation station,
108                                                                              final FieldSpacecraftState<T> state,
109                                                                              final T[] parameters) {
110         // Field
111         final Field<T> field = state.getDate().getField();
112         final T zero         = field.getZero();
113 
114         // tracking
115         final FieldVector3D<T> pos = state.getPosition();
116         final FieldTrackingCoordinates<T> trackingCoordinates =
117                         station.getBaseFrame().getTrackingCoordinates(pos, state.getFrame(), state.getDate());
118 
119         // only consider measurements above the horizon
120         if (trackingCoordinates.getElevation().getReal() > 0) {
121             // delay in meters
122             final T delay = tropoModel.pathDelay(trackingCoordinates,
123                                                  station.getOffsetGeodeticPoint(state.getDate()),
124                                                  station.getPressureTemperatureHumidity(state.getDate()),
125                                                  parameters, state.getDate()).
126                             getDelay();
127             // return delay in seconds
128             return delay.divide(Constants.SPEED_OF_LIGHT);
129         }
130 
131         return zero;
132     }
133 
134     /** {@inheritDoc} */
135     @Override
136     public List<ParameterDriver> getParametersDrivers() {
137         return tropoModel.getParametersDrivers();
138     }
139 
140     /** {@inheritDoc} */
141     @Override
142     public void modifyWithoutDerivatives(final EstimatedMeasurementBase<TDOA> estimated) {
143 
144         final TDOA            measurement   = estimated.getObservedMeasurement();
145         final GroundStation   primeStation  = measurement.getPrimeStation();
146         final GroundStation   secondStation = measurement.getSecondStation();
147 
148         TDOAModifierUtil.modifyWithoutDerivatives(estimated,  primeStation, secondStation,
149                                                   this::timeErrorTroposphericModel, this);
150 
151     }
152 
153     /** {@inheritDoc} */
154     @Override
155     public void modify(final EstimatedMeasurement<TDOA> estimated) {
156 
157         final TDOA            measurement   = estimated.getObservedMeasurement();
158         final GroundStation   primeStation  = measurement.getPrimeStation();
159         final GroundStation   secondStation = measurement.getSecondStation();
160         final SpacecraftState state         = estimated.getStates()[0];
161 
162         TDOAModifierUtil.modify(estimated, tropoModel,
163                                 new ModifierGradientConverter(state, 6, new FrameAlignedProvider(state.getFrame())),
164                                 primeStation, secondStation,
165                                 this::timeErrorTroposphericModel,
166                                 this::timeErrorTroposphericModel,
167                                 this);
168 
169     }
170 
171 }