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.models.earth.troposphere;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.hipparchus.CalculusFieldElement;
23 import org.hipparchus.util.MathArrays;
24 import org.orekit.annotation.DefaultDataContext;
25 import org.orekit.bodies.FieldGeodeticPoint;
26 import org.orekit.bodies.GeodeticPoint;
27 import org.orekit.time.AbsoluteDate;
28 import org.orekit.time.FieldAbsoluteDate;
29 import org.orekit.time.TimeScale;
30 import org.orekit.time.TimeScalesFactory;
31 import org.orekit.utils.ParameterDriver;
32 import org.orekit.utils.TimeSpanMap;
33 import org.orekit.utils.TimeSpanMap.Span;
34
35 /**
36 * Time span estimated tropospheric model.
37 * <p>
38 * This class is closely related to {@link org.orekit.models.earth.troposphere EstimatedTroposphericModel} class.<br>
39 * The difference is that it has a {@link TimeSpanMap} of {@link EstimatedTroposphericModel} objects as attribute. <br>
40 * The idea behind this model is to allow the user to design a tropospheric model that can see its physical parameters
41 * (total zenith delay) change with time, at dates chosen by the user. <br>
42 * </p>
43 * @author Bryan Cazabonne
44 * @since 10.2
45 * @deprecated as of 12.1, replaced by {@link TimeSpanEstimatedModel}
46 */
47 @Deprecated
48 public class TimeSpanEstimatedTroposphericModel implements DiscreteTroposphericModel {
49
50 /** Prefix for dates before in the tropospheric parameter drivers' name. */
51 public static final String DATE_BEFORE = " - Before ";
52
53 /** Prefix for dates after in the tropospheric parameter drivers' name. */
54 public static final String DATE_AFTER = " - After ";
55
56 /** Time scale for transition dates. */
57 private final TimeScale timeScale;
58
59 /** It contains all the models use for the whole period of measurements. */
60 private final TimeSpanMap<EstimatedTroposphericModel> troposphericModelMap;
61
62 /**
63 * Constructor with default UTC time scale.
64 * @param model the initial model which going to be used for all the models initialization.
65 */
66 @DefaultDataContext
67 public TimeSpanEstimatedTroposphericModel(final EstimatedTroposphericModel model) {
68 this(model, TimeScalesFactory.getUTC());
69 }
70
71 /**
72 * Constructor with default UTC time scale.
73 * @param model the initial model which going to be used for all the models initialization.
74 * @param timeScale timeScale Time scale used for the default names of the tropospheric parameter drivers
75 */
76 public TimeSpanEstimatedTroposphericModel(final EstimatedTroposphericModel model,
77 final TimeScale timeScale) {
78 this.troposphericModelMap = new TimeSpanMap<>(model);
79 this.timeScale = timeScale;
80 }
81
82 /** {@inheritDoc}
83 * <p>
84 * All the parameter drivers of all Estimated models are returned in an array.
85 * Models are ordered chronologically.
86 * </p>
87 */
88 @Override
89 public List<ParameterDriver> getParametersDrivers() {
90
91 // Get all transitions from the TimeSpanMap
92 final List<ParameterDriver> listTroposphericParameterDrivers = new ArrayList<>();
93
94 // Loop on the spans
95 for (Span<EstimatedTroposphericModel> span = getFirstSpan(); span != null; span = span.next()) {
96 // Add all the parameter drivers of each span
97 for (ParameterDriver tropoDriver : span.getData().getParametersDrivers()) {
98 // Add the driver only if the name does not exist already
99 if (!findByName(listTroposphericParameterDrivers, tropoDriver.getName())) {
100 listTroposphericParameterDrivers.add(tropoDriver);
101 }
102 }
103 }
104
105 // Return an array of parameter drivers with no duplicated name
106 return listTroposphericParameterDrivers;
107
108 }
109
110 /** Add an EstimatedTroposphericModel entry valid before a limit date.<br>
111 * Using <code>addTroposphericValidBefore(entry, t)</code> will make <code>entry</code>
112 * valid in ]-∞, t[ (note the open bracket).
113 * @param model EstimatedTroposphericModel entry
114 * @param latestValidityDate date before which the entry is valid
115 * (must be different from <b>all</b> dates already used for transitions)
116 */
117 public void addTroposphericModelValidBefore(final EstimatedTroposphericModel model, final AbsoluteDate latestValidityDate) {
118 troposphericModelMap.addValidBefore(changeTroposphericParameterDriversNames(model,
119 latestValidityDate,
120 DATE_BEFORE),
121 latestValidityDate, false);
122 }
123
124 /** Add a EstimatedTroposphericModel entry valid after a limit date.<br>
125 * Using <code>addTroposphericModelValidAfter(entry, t)</code> will make <code>entry</code>
126 * valid in [t, +∞[ (note the closed bracket).
127 * @param model EstimatedTroposphericModel entry
128 * @param earliestValidityDate date after which the entry is valid
129 * (must be different from <b>all</b> dates already used for transitions)
130 */
131 public void addTroposphericModelValidAfter(final EstimatedTroposphericModel model, final AbsoluteDate earliestValidityDate) {
132 troposphericModelMap.addValidAfter(changeTroposphericParameterDriversNames(model,
133 earliestValidityDate,
134 DATE_AFTER),
135 earliestValidityDate, false);
136 }
137
138 /** Get the {@link EstimatedTroposphericModel} model valid at a date.
139 * @param date the date of validity
140 * @return the EstimatedTroposphericModel model valid at date
141 */
142 public EstimatedTroposphericModel getTroposphericModel(final AbsoluteDate date) {
143 return troposphericModelMap.get(date);
144 }
145
146 /** Get the first {@link Span time span} of the tropospheric model time span map.
147 * @return the first {@link Span time span} of the tropospheric model time span map
148 * @since 11.1
149 */
150 public Span<EstimatedTroposphericModel> getFirstSpan() {
151 return troposphericModelMap.getFirstSpan();
152 }
153
154 /** Extract the proper parameter drivers' values from the array in input of the
155 * {@link #pathDelay(double, GeodeticPoint, double[], AbsoluteDate) pathDelay} method.
156 * Parameters are filtered given an input date.
157 * @param parameters the input parameters array
158 * @param date the date
159 * @return the parameters given the date
160 */
161 public double[] extractParameters(final double[] parameters, final AbsoluteDate date) {
162
163 // Get the tropospheric parameter drivers of the date
164 final List<ParameterDriver> troposphericParameterDriver = getTroposphericModel(date).getParametersDrivers();
165
166 // Find out the indexes of the parameters in the whole array of parameters
167 final List<ParameterDriver> allTroposphericParameters = getParametersDrivers();
168 final double[] outParameters = new double[troposphericParameterDriver.size()];
169 int index = 0;
170 for (int i = 0; i < allTroposphericParameters.size(); i++) {
171 final String driverName = allTroposphericParameters.get(i).getName();
172 for (ParameterDriver tropoDriver : troposphericParameterDriver) {
173 if (tropoDriver.getName().equals(driverName)) {
174 outParameters[index++] = parameters[i];
175 }
176 }
177 }
178 return outParameters;
179 }
180
181 /** Extract the proper parameter drivers' values from the array in input of the
182 * {@link #pathDelay(double, GeodeticPoint, double[], AbsoluteDate) pathDelay} method.
183 * Parameters are filtered given an input date.
184 * @param parameters the input parameters array
185 * @param date the date
186 * @param <T> extends CalculusFieldElements
187 * @return the parameters given the date
188 */
189 public <T extends CalculusFieldElement<T>> T[] extractParameters(final T[] parameters,
190 final FieldAbsoluteDate<T> date) {
191
192 // Get the tropospheric parameter drivers of the date
193 final List<ParameterDriver> troposphericParameterDriver = getTroposphericModel(date.toAbsoluteDate()).getParametersDrivers();
194
195 // Find out the indexes of the parameters in the whole array of parameters
196 final List<ParameterDriver> allTroposphericParameters = getParametersDrivers();
197 final T[] outParameters = MathArrays.buildArray(date.getField(), troposphericParameterDriver.size());
198 int index = 0;
199 for (int i = 0; i < allTroposphericParameters.size(); i++) {
200 final String driverName = allTroposphericParameters.get(i).getName();
201 for (ParameterDriver tropoDriver : troposphericParameterDriver) {
202 if (tropoDriver.getName().equals(driverName)) {
203 outParameters[index++] = parameters[i];
204 }
205 }
206 }
207 return outParameters;
208 }
209
210 /** {@inheritDoc} */
211 @Override
212 public double pathDelay(final double elevation, final GeodeticPoint point,
213 final double[] parameters, final AbsoluteDate date) {
214 // Extract the proper parameters valid at date from the input array
215 final double[] extractedParameters = extractParameters(parameters, date);
216 // Compute and return the path delay
217 return getTroposphericModel(date).pathDelay(elevation, point,
218 extractedParameters, date);
219 }
220
221 /** {@inheritDoc} */
222 @Override
223 public <T extends CalculusFieldElement<T>> T pathDelay(final T elevation, final FieldGeodeticPoint<T> point,
224 final T[] parameters, final FieldAbsoluteDate<T> date) {
225 // Extract the proper parameters valid at date from the input array
226 final T[] extractedParameters = extractParameters(parameters, date);
227 // Compute and return the path delay
228 return getTroposphericModel(date.toAbsoluteDate()).pathDelay(elevation, point,
229 extractedParameters, date);
230 }
231
232 /** Find if a parameter driver with a given name already exists in a list of parameter drivers.
233 * @param driversList the list of parameter drivers
234 * @param name the parameter driver's name to filter with
235 * @return true if the name was found, false otherwise
236 */
237 private boolean findByName(final List<ParameterDriver> driversList, final String name) {
238 for (final ParameterDriver driver : driversList) {
239 if (driver.getName().equals(name)) {
240 return true;
241 }
242 }
243 return false;
244 }
245
246 /** Change the parameter drivers names of a {@link EstimatedTroposphericModel} model, if needed.
247 * <p>
248 * This is done to avoid that several parameter drivers have the same name.<br>
249 * It is done only if the user hasn't modify the EstimatedTroposphericModel parameter drivers default names.
250 * </p>
251 * @param troposphericModel the EstimatedTroposphericModel model
252 * @param date the date used in the parameter driver's name
253 * @param datePrefix the date prefix used in the parameter driver's name
254 * @return the EstimatedTroposphericModel with its drivers' names changed
255 */
256 private EstimatedTroposphericModel changeTroposphericParameterDriversNames(final EstimatedTroposphericModel troposphericModel,
257 final AbsoluteDate date,
258 final String datePrefix) {
259 // Loop on the parameter drivers of the EstimatedTroposphericModel model
260 for (ParameterDriver driver: troposphericModel.getParametersDrivers()) {
261 final String driverName = driver.getName();
262
263 // If the name is the default name for EstimatedTroposphericModel parameter drivers
264 // Modify the name to add the prefix and the date
265 if (driverName.equals(EstimatedTroposphericModel.TOTAL_ZENITH_DELAY)) {
266 driver.setName(driverName + datePrefix + date.toString(timeScale));
267 }
268 }
269 return troposphericModel;
270 }
271
272 }