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;

  18. import org.hipparchus.analysis.BivariateFunction;
  19. import org.hipparchus.analysis.interpolation.PiecewiseBicubicSplineInterpolator;
  20. import org.hipparchus.util.FastMath;
  21. import org.orekit.data.DataProvidersManager;
  22. import org.orekit.errors.OrekitException;
  23. import org.orekit.errors.OrekitMessages;
  24. import org.orekit.utils.InterpolationTableLoader;

  25. /** A static tropospheric model that interpolates the actual tropospheric delay
  26.  * based on values read from a configuration file (tropospheric-delay.txt) via
  27.  * the {@link DataProvidersManager}.
  28.  * @author Thomas Neidhart
  29.  */
  30. public class FixedTroposphericDelay implements TroposphericModel {

  31.     /** Serializable UID. */
  32.     private static final long serialVersionUID = -92320711761929077L;

  33.     /** Singleton object for the default model. */
  34.     private static FixedTroposphericDelay defaultModel;

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

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

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

  41.     /** Interpolation function for the tropospheric delays. */
  42.     private transient BivariateFunction delayFunction;

  43.     /** Creates a new {@link FixedTroposphericDelay} instance.
  44.      * @param xArr abscissa grid for the interpolation function
  45.      * @param yArr ordinate grid for the interpolation function
  46.      * @param fArr values samples for the interpolation function
  47.      */
  48.     public FixedTroposphericDelay(final double[] xArr, final double[] yArr, final double[][] fArr) {
  49.         this.xArr = xArr.clone();
  50.         this.yArr = yArr.clone();
  51.         this.fArr = fArr.clone();
  52.         delayFunction = new PiecewiseBicubicSplineInterpolator().interpolate(xArr, yArr, fArr);
  53.     }

  54.     /** Creates a new {@link FixedTroposphericDelay} instance, and loads the
  55.      * delay values from the given resource via the {@link DataProvidersManager}.
  56.      * @param supportedName a regular expression for supported resource names
  57.      * @throws OrekitException if the resource could not be loaded
  58.      */
  59.     public FixedTroposphericDelay(final String supportedName) throws OrekitException {

  60.         final InterpolationTableLoader loader = new InterpolationTableLoader();
  61.         DataProvidersManager.getInstance().feed(supportedName, loader);

  62.         if (!loader.stillAcceptsData()) {
  63.             xArr = loader.getAbscissaGrid();
  64.             yArr = loader.getOrdinateGrid();
  65.             for (int i = 0; i < yArr.length; ++i) {
  66.                 yArr[i] = FastMath.toRadians(yArr[i]);
  67.             }
  68.             fArr = loader.getValuesSamples();
  69.             delayFunction = new PiecewiseBicubicSplineInterpolator().interpolate(xArr, yArr, fArr);
  70.         } else {
  71.             throw new OrekitException(OrekitMessages.UNABLE_TO_FIND_RESOURCE, supportedName);
  72.         }
  73.     }

  74.     /** Returns the default model, loading delay values from the file
  75.      * "tropospheric-delay.txt".
  76.      * @return the default model
  77.      * @throws OrekitException if the file could not be loaded
  78.      */
  79.     public static FixedTroposphericDelay getDefaultModel() throws OrekitException {
  80.         synchronized (FixedTroposphericDelay.class) {
  81.             if (defaultModel == null) {
  82.                 defaultModel = new FixedTroposphericDelay("^tropospheric-delay\\.txt$");
  83.             }
  84.         }
  85.         return defaultModel;
  86.     }

  87.     /** {@inheritDoc} */
  88.     public double pathDelay(final double elevation, final double height) {
  89.         // limit the height to 5000 m
  90.         final double h = FastMath.min(FastMath.max(0, height), 5000);
  91.         // limit the elevation to 0 - π
  92.         final double ele = FastMath.min(FastMath.PI, FastMath.max(0d, elevation));
  93.         // mirror elevation at the right angle of π/2
  94.         final double e = ele > 0.5 * FastMath.PI ? FastMath.PI - ele : ele;

  95.         return delayFunction.value(h, e);
  96.     }

  97.     /** Make sure the unserializable bivariate interpolation function is properly rebuilt.
  98.      * @return replacement object, with bivariate function properly set up
  99.      */
  100.     private Object readResolve() {
  101.         return new FixedTroposphericDelay(xArr, yArr, fArr);
  102.     }

  103. }