FixedTroposphericDelay.java

  1. /* Copyright 2011-2012 Space Applications Services
  2.  * Licensed to CS Communication & Systèmes (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. import java.util.Collections;
  19. import java.util.List;

  20. import org.hipparchus.CalculusFieldElement;
  21. import org.hipparchus.analysis.interpolation.PiecewiseBicubicSplineInterpolatingFunction;
  22. import org.hipparchus.analysis.interpolation.PiecewiseBicubicSplineInterpolator;
  23. import org.hipparchus.util.FastMath;
  24. import org.hipparchus.util.MathUtils;
  25. import org.orekit.annotation.DefaultDataContext;
  26. import org.orekit.bodies.FieldGeodeticPoint;
  27. import org.orekit.bodies.GeodeticPoint;
  28. import org.orekit.data.DataContext;
  29. import org.orekit.data.DataProvidersManager;
  30. import org.orekit.errors.OrekitException;
  31. import org.orekit.errors.OrekitMessages;
  32. import org.orekit.time.AbsoluteDate;
  33. import org.orekit.time.FieldAbsoluteDate;
  34. import org.orekit.utils.FieldTrackingCoordinates;
  35. import org.orekit.utils.InterpolationTableLoader;
  36. import org.orekit.utils.ParameterDriver;
  37. import org.orekit.utils.TrackingCoordinates;

  38. /** A static tropospheric model that interpolates the actual tropospheric delay
  39.  * based on values read from a configuration file (tropospheric-delay.txt) via
  40.  * the {@link DataProvidersManager}.
  41.  * @author Thomas Neidhart
  42.  */
  43. public class FixedTroposphericDelay implements TroposphericModel {

  44.     /** Singleton object for the default model. */
  45.     private static FixedTroposphericDelay defaultModel;

  46.     /** Abscissa grid for the bi-variate interpolation function read from the file. */
  47.     private final double[] xArr;

  48.     /** Ordinate grid for the bi-variate interpolation function read from the file. */
  49.     private final double[] yArr;

  50.     /** Values samples for the bi-variate interpolation function read from the file. */
  51.     private final double[][] fArr;

  52.     /** Interpolation function for the tropospheric delays. */
  53.     private final PiecewiseBicubicSplineInterpolatingFunction delayFunction;

  54.     /** Creates a new {@link FixedTroposphericDelay} instance.
  55.      * @param xArr abscissa grid for the interpolation function
  56.      * @param yArr ordinate grid for the interpolation function
  57.      * @param fArr values samples for the interpolation function
  58.      */
  59.     public FixedTroposphericDelay(final double[] xArr, final double[] yArr, final double[][] fArr) {
  60.         this.xArr = xArr.clone();
  61.         this.yArr = yArr.clone();
  62.         this.fArr = fArr.clone();
  63.         delayFunction = new PiecewiseBicubicSplineInterpolator().interpolate(xArr, yArr, fArr);
  64.     }

  65.     /** Creates a new {@link FixedTroposphericDelay} instance, and loads the
  66.      * delay values from the given resource via the {@link DataContext#getDefault()
  67.      * default data context}.
  68.      *
  69.      * @param supportedName a regular expression for supported resource names
  70.      * @see #FixedTroposphericDelay(String, DataProvidersManager)
  71.      */
  72.     @DefaultDataContext
  73.     public FixedTroposphericDelay(final String supportedName) {
  74.         this(supportedName, DataContext.getDefault().getDataProvidersManager());
  75.     }

  76.     /**
  77.      * Creates a new {@link FixedTroposphericDelay} instance, and loads the delay values
  78.      * from the given resource via the specified data manager.
  79.      *
  80.      * @param supportedName a regular expression for supported resource names
  81.      * @param dataProvidersManager provides access to auxiliary data.
  82.      * @since 10.1
  83.      */
  84.     public FixedTroposphericDelay(final String supportedName,
  85.                                   final DataProvidersManager dataProvidersManager) {

  86.         final InterpolationTableLoader loader = new InterpolationTableLoader();
  87.         dataProvidersManager.feed(supportedName, loader);

  88.         if (!loader.stillAcceptsData()) {
  89.             xArr = loader.getAbscissaGrid();
  90.             yArr = loader.getOrdinateGrid();
  91.             for (int i = 0; i < yArr.length; ++i) {
  92.                 yArr[i] = FastMath.toRadians(yArr[i]);
  93.             }
  94.             fArr = loader.getValuesSamples();
  95.             delayFunction = new PiecewiseBicubicSplineInterpolator().interpolate(xArr, yArr, fArr);
  96.         } else {
  97.             throw new OrekitException(OrekitMessages.UNABLE_TO_FIND_RESOURCE, supportedName);
  98.         }
  99.     }

  100.     /** Returns the default model, loading delay values from the file
  101.      * "tropospheric-delay.txt" via the {@link DataContext#getDefault() default data
  102.      * context}.
  103.      *
  104.      * <p>This method uses the {@link DataContext#getDefault() default data context}.
  105.      *
  106.      * @return the default model
  107.      */
  108.     @DefaultDataContext
  109.     public static FixedTroposphericDelay getDefaultModel() {
  110.         synchronized (FixedTroposphericDelay.class) {
  111.             if (defaultModel == null) {
  112.                 defaultModel = new FixedTroposphericDelay("^tropospheric-delay\\.txt$");
  113.             }
  114.         }
  115.         return defaultModel;
  116.     }

  117.     /** {@inheritDoc}
  118.      * <p>
  119.      * All delays are affected to {@link TroposphericDelay#getZh() hydrostatic zenith}
  120.      * and {@link TroposphericDelay#getSh() hydrostatic slanted} delays, the wet delays
  121.      * are arbitrarily set to 0.
  122.      * </p>
  123.      */
  124.     @Override
  125.     public TroposphericDelay pathDelay(final TrackingCoordinates trackingCoordinates, final GeodeticPoint point,
  126.                                        final double[] parameters, final AbsoluteDate date) {
  127.         // limit the height to 5000 m
  128.         final double h = FastMath.min(FastMath.max(0, point.getAltitude()), 5000);
  129.         // limit the elevation to 0 - π
  130.         final double ele = FastMath.min(FastMath.PI, FastMath.max(0d, trackingCoordinates.getElevation()));
  131.         // mirror elevation at the right angle of π/2
  132.         final double e = ele > 0.5 * FastMath.PI ? FastMath.PI - ele : ele;

  133.         return new TroposphericDelay(delayFunction.value(h, MathUtils.SEMI_PI), 0.0,
  134.                                      delayFunction.value(h, e), 0.0);
  135.     }

  136.     /** {@inheritDoc}
  137.      * <p>
  138.      * All delays are affected to {@link FieldTroposphericDelay#getZh() hydrostatic zenith}
  139.      * and {@link FieldTroposphericDelay#getSh() hydrostatic slanted} delays, the wet delays
  140.      * are arbitrarily set to 0.
  141.      * </p>
  142.      */
  143.     @Override
  144.     public <T extends CalculusFieldElement<T>> FieldTroposphericDelay<T> pathDelay(final FieldTrackingCoordinates<T> trackingCoordinates,
  145.                                                                                    final FieldGeodeticPoint<T> point,
  146.                                                                                    final T[] parameters, final FieldAbsoluteDate<T> date) {
  147.         final T zero = date.getField().getZero();
  148.         final T pi   = zero.getPi();
  149.         // limit the height to 5000 m
  150.         final T h = FastMath.min(FastMath.max(zero, point.getAltitude()), zero.newInstance(5000));
  151.         // limit the elevation to 0 - π
  152.         final T ele = FastMath.min(pi, FastMath.max(zero, trackingCoordinates.getElevation()));
  153.         // mirror elevation at the right angle of π/2
  154.         final T e = ele.getReal() > pi.multiply(0.5).getReal() ? ele.negate().add(pi) : ele;

  155.         return new FieldTroposphericDelay<>(delayFunction.value(h, date.getField().getZero().newInstance(MathUtils.SEMI_PI)),
  156.                                             date.getField().getZero(),
  157.                                             delayFunction.value(h, e),
  158.                                             date.getField().getZero());

  159.     }

  160.     /** {@inheritDoc} */
  161.     @Override
  162.     public List<ParameterDriver> getParametersDrivers() {
  163.         return Collections.emptyList();
  164.     }

  165. }