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.Collections;
20  import java.util.List;
21  
22  import org.hipparchus.CalculusFieldElement;
23  import org.hipparchus.util.FastMath;
24  import org.orekit.annotation.DefaultDataContext;
25  import org.orekit.bodies.FieldGeodeticPoint;
26  import org.orekit.bodies.GeodeticPoint;
27  import org.orekit.models.earth.weather.ConstantPressureTemperatureHumidityProvider;
28  import org.orekit.models.earth.weather.FieldPressureTemperatureHumidity;
29  import org.orekit.models.earth.weather.PressureTemperatureHumidity;
30  import org.orekit.time.AbsoluteDate;
31  import org.orekit.time.FieldAbsoluteDate;
32  import org.orekit.utils.FieldTrackingCoordinates;
33  import org.orekit.utils.ParameterDriver;
34  import org.orekit.utils.TrackingCoordinates;
35  
36  /** An estimated tropospheric model. The tropospheric delay is computed according to the formula:
37   * <p>
38   * δ = δ<sub>h</sub> * m<sub>h</sub> + (δ<sub>t</sub> - δ<sub>h</sub>) * m<sub>w</sub>
39   * <p>
40   * With:
41   * <ul>
42   * <li>δ<sub>h</sub>: Tropospheric zenith hydro-static delay.</li>
43   * <li>δ<sub>t</sub>: Tropospheric total zenith delay.</li>
44   * <li>m<sub>h</sub>: Hydro-static mapping function.</li>
45   * <li>m<sub>w</sub>: Wet mapping function.</li>
46   * </ul>
47   * <p>
48   * The mapping functions m<sub>h</sub>(e) and m<sub>w</sub>(e) are
49   * computed thanks to a {@link #model} initialized by the user.
50   * The user has the possibility to use several mapping function models for the computations:
51   * the {@link GlobalMappingFunctionModel Global Mapping Function}, or
52   * the {@link NiellMappingFunctionModel Niell Mapping Function}
53   * </p> <p>
54   * The tropospheric zenith delay δ<sub>h</sub> is computed empirically with a
55   * {@link DiscreteTroposphericModel tropospheric model}
56   * while the tropospheric total zenith delay δ<sub>t</sub> is estimated as a {@link ParameterDriver},
57   * hence the wet part is the difference between the two.
58   * @since 12.1
59   */
60  public class EstimatedModel implements TroposphericModel {
61  
62      /** Name of the parameter of this model: the total zenith delay. */
63      public static final String TOTAL_ZENITH_DELAY = "total zenith delay";
64  
65      /** Mapping Function model. */
66      private final TroposphereMappingFunction model;
67  
68      /** Driver for the tropospheric zenith total delay.*/
69      private final ParameterDriver totalZenithDelay;
70  
71      /** Model for hydrostatic component. */
72      private final TroposphericModel hydrostatic;
73  
74      /** Build a new instance using the given environmental conditions.
75       * <p>
76       * This constructor uses a {@link ModifiedSaastamoinenModel} for the hydrostatic contribution.
77       * </p>
78       * @param h0 altitude of the station [m]
79       * @param t0 the temperature at the station [K]
80       * @param p0 the atmospheric pressure at the station [mbar]
81       * @param model mapping function model.
82       * @param totalDelay initial value for the tropospheric zenith total delay [m]
83       */
84      @DefaultDataContext
85      public EstimatedModel(final double h0, final double t0, final double p0,
86                            final TroposphereMappingFunction model, final double totalDelay) {
87          this(new ModifiedSaastamoinenModel(new ConstantPressureTemperatureHumidityProvider(new PressureTemperatureHumidity(h0,
88                                                                                                                             TroposphericModelUtils.HECTO_PASCAL.toSI(p0),
89                                                                                                                             t0,
90                                                                                                                             0.0,
91                                                                                                                             Double.NaN,
92                                                                                                                             Double.NaN))),
93               model, totalDelay);
94      }
95  
96      /** Build a new instance using the given environmental conditions.
97       * @param hydrostatic model for hydrostatic component
98       * @param model mapping function model.
99       * @param totalDelay initial value for the tropospheric zenith total delay [m]
100      * @since 12.1
101      */
102     public EstimatedModel(final TroposphericModel hydrostatic,
103                           final TroposphereMappingFunction model,
104                           final double totalDelay) {
105 
106         totalZenithDelay = new ParameterDriver(EstimatedModel.TOTAL_ZENITH_DELAY,
107                                                totalDelay, FastMath.scalb(1.0, 0), 0.0, Double.POSITIVE_INFINITY);
108 
109         this.hydrostatic = hydrostatic;
110         this.model = model;
111     }
112 
113     /** Build a new instance using a standard atmosphere model.
114      * <ul>
115      * <li>altitude: 0m
116      * <li>temperature: 18 degree Celsius
117      * <li>pressure: 1013.25 mbar
118      * </ul>
119      * @param model mapping function model.
120      * @param totalDelay initial value for the tropospheric zenith total delay [m]
121      */
122     @DefaultDataContext
123     public EstimatedModel(final TroposphereMappingFunction model, final double totalDelay) {
124         this(0.0, 273.15 + 18.0, 1013.25, model, totalDelay);
125     }
126 
127     /** {@inheritDoc} */
128     @Override
129     public List<ParameterDriver> getParametersDrivers() {
130         return Collections.singletonList(totalZenithDelay);
131     }
132 
133     /** {@inheritDoc} */
134     @Override
135     public TroposphericDelay pathDelay(final TrackingCoordinates trackingCoordinates,
136                                        final GeodeticPoint point,
137                                        final PressureTemperatureHumidity weather,
138                                        final double[] parameters, final AbsoluteDate date) {
139 
140         // zenith hydrostatic delay
141         final double zd = hydrostatic.pathDelay(trackingCoordinates, point, weather, parameters, date).getZh();
142 
143         // zenith wet delay
144         final double wd = parameters[0] - zd;
145 
146         // mapping functions
147         final double[] mf = model.mappingFactors(trackingCoordinates, point, weather, date);
148 
149         // composite delay
150         return new TroposphericDelay(zd, wd, mf[0] * zd, mf[1] * wd);
151 
152     }
153 
154     /** {@inheritDoc} */
155     @Override
156     public <T extends CalculusFieldElement<T>> FieldTroposphericDelay<T> pathDelay(final FieldTrackingCoordinates<T> trackingCoordinates,
157                                                                                    final FieldGeodeticPoint<T> point,
158                                                                                    final FieldPressureTemperatureHumidity<T> weather,
159                                                                                    final T[] parameters, final FieldAbsoluteDate<T> date) {
160 
161         // zenith hydrostatic delay
162         final T zd = hydrostatic.pathDelay(trackingCoordinates, point, weather, parameters, date).getZh();
163 
164         // zenith wet delay
165         final T wd = parameters[0].subtract(zd);
166 
167         // mapping functions
168         final T[] mf = model.mappingFactors(trackingCoordinates, point, weather, date);
169 
170         // composite delay
171         return new FieldTroposphericDelay<>(zd, wd, mf[0].multiply(zd), mf[1].multiply(wd));
172 
173     }
174 
175 }