1   /* Copyright 2002-2021 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.bodies.FieldGeodeticPoint;
25  import org.orekit.bodies.GeodeticPoint;
26  import org.orekit.time.AbsoluteDate;
27  import org.orekit.time.FieldAbsoluteDate;
28  import org.orekit.utils.ParameterDriver;
29  
30  /** An estimated tropospheric model. The tropospheric delay is computed according to the formula:
31   * <p>
32   * δ = δ<sub>h</sub> * m<sub>h</sub> + (δ<sub>t</sub> - δ<sub>h</sub>) * m<sub>w</sub>
33   * <p>
34   * With:
35   * <ul>
36   * <li>δ<sub>h</sub>: Tropospheric zenith hydro-static delay.</li>
37   * <li>δ<sub>t</sub>: Tropospheric total zenith delay.</li>
38   * <li>m<sub>h</sub>: Hydro-static mapping function.</li>
39   * <li>m<sub>w</sub>: Wet mapping function.</li>
40   * </ul>
41   * <p>
42   * The mapping functions m<sub>h</sub>(e) and m<sub>w</sub>(e) are
43   * computed thanks to a {@link #model} initialized by the user.
44   * The user has the possibility to use several mapping function models for the computations:
45   * the {@link GlobalMappingFunctionModel Global Mapping Function}, or
46   * the {@link NiellMappingFunctionModel Niell Mapping Function}
47   * </p> <p>
48   * The tropospheric zenith delay δ<sub>h</sub> is computed empirically with a {@link SaastamoinenModel}
49   * while the tropospheric total zenith delay δ<sub>t</sub> is estimated as a {@link ParameterDriver}
50   */
51  public class EstimatedTroposphericModel implements DiscreteTroposphericModel {
52  
53      /** Name of the parameter of this model: the total zenith delay. */
54      public static final String TOTAL_ZENITH_DELAY = "total zenith delay";
55  
56      /** Mapping Function model. */
57      private final MappingFunction model;
58  
59      /** Driver for the tropospheric zenith total delay.*/
60      private final ParameterDriver totalZenithDelay;
61  
62      /** The temperature at the station [K]. */
63      private double t0;
64  
65      /** The atmospheric pressure [mbar]. */
66      private double p0;
67  
68      /** Build a new instance using the given environmental conditions.
69       * @param t0 the temperature at the station [K]
70       * @param p0 the atmospheric pressure at the station [mbar]
71       * @param model mapping function model (NMF or GMF).
72       * @param totalDelay initial value for the tropospheric zenith total delay [m]
73       */
74      public EstimatedTroposphericModel(final double t0, final double p0,
75                                        final MappingFunction model, final double totalDelay) {
76  
77          totalZenithDelay = new ParameterDriver(EstimatedTroposphericModel.TOTAL_ZENITH_DELAY,
78                                                 totalDelay, FastMath.scalb(1.0, 0), 0.0, Double.POSITIVE_INFINITY);
79  
80          this.t0    = t0;
81          this.p0    = p0;
82          this.model = model;
83      }
84  
85      /** Build a new instance using a standard atmosphere model.
86       * <ul>
87       * <li>temperature: 18 degree Celsius
88       * <li>pressure: 1013.25 mbar
89       * </ul>
90       * @param model mapping function model (NMF or GMF).
91       * @param totalDelay initial value for the tropospheric zenith total delay [m]
92       */
93      public EstimatedTroposphericModel(final MappingFunction model, final double totalDelay) {
94          this(273.15 + 18.0, 1013.25, model, totalDelay);
95      }
96  
97      /** {@inheritDoc} */
98      @Override
99      public List<ParameterDriver> getParametersDrivers() {
100         return Collections.singletonList(totalZenithDelay);
101     }
102 
103     /** {@inheritDoc} */
104     @Override
105     public double pathDelay(final double elevation, final GeodeticPoint point,
106                             final double[] parameters, final AbsoluteDate date) {
107         // Use an empirical model for tropospheric zenith hydro-static delay : Saastamoinen model
108         final SaastamoinenModel saastamoinen = new SaastamoinenModel(t0, p0, 0.0);
109         // Zenith delays. elevation = pi/2 because we compute the delay in the zenith direction
110         final double zhd = saastamoinen.pathDelay(0.5 * FastMath.PI, point, parameters, date);
111         final double ztd = parameters[0];
112         // Mapping functions
113         final double[] mf = model.mappingFactors(elevation, point, date);
114         // Total delay
115         return mf[0] * zhd + mf[1] * (ztd - zhd);
116     }
117 
118     /** {@inheritDoc} */
119     @Override
120     public <T extends CalculusFieldElement<T>> T pathDelay(final T elevation, final FieldGeodeticPoint<T> point,
121                                                        final T[] parameters, final FieldAbsoluteDate<T> date) {
122         // Use an empirical model for tropospheric zenith hydro-static delay : Saastamoinen model
123         final SaastamoinenModel saastamoinen = new SaastamoinenModel(t0, p0, 0.0);
124         // Zenith delays. elevation = pi/2 because we compute the delay in the zenith direction
125         final T zhd = saastamoinen.pathDelay(elevation.getPi().multiply(0.5), point, parameters, date);
126         final T ztd = parameters[0];
127         // Mapping functions
128         final T[] mf = model.mappingFactors(elevation, point, date);
129         // Total delay
130         return mf[0].multiply(zhd).add(mf[1].multiply(ztd.subtract(zhd)));
131     }
132 
133 }