KlobucharIonoModel.java

  1. /* Copyright 2002-2022 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.ionosphere;

  18. import java.util.Collections;
  19. import java.util.List;

  20. import org.hipparchus.Field;
  21. import org.hipparchus.CalculusFieldElement;
  22. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  23. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  24. import org.hipparchus.util.FastMath;
  25. import org.hipparchus.util.FieldSinCos;
  26. import org.hipparchus.util.MathUtils;
  27. import org.hipparchus.util.SinCos;
  28. import org.orekit.annotation.DefaultDataContext;
  29. import org.orekit.bodies.FieldGeodeticPoint;
  30. import org.orekit.bodies.GeodeticPoint;
  31. import org.orekit.data.DataContext;
  32. import org.orekit.frames.TopocentricFrame;
  33. import org.orekit.propagation.FieldSpacecraftState;
  34. import org.orekit.propagation.SpacecraftState;
  35. import org.orekit.time.AbsoluteDate;
  36. import org.orekit.time.DateTimeComponents;
  37. import org.orekit.time.FieldAbsoluteDate;
  38. import org.orekit.time.TimeScale;
  39. import org.orekit.utils.Constants;
  40. import org.orekit.utils.ParameterDriver;

  41. /**
  42.  * Klobuchar ionospheric delay model.
  43.  * Klobuchar ionospheric delay model is designed as a GNSS correction model.
  44.  * The parameters for the model are provided by the GPS satellites in their broadcast
  45.  * messsage.
  46.  * This model is based on the assumption the electron content is concentrated
  47.  * in 350 km layer.
  48.  *
  49.  * The delay refers to L1 (1575.42 MHz).
  50.  * If the delay is sought for L2 (1227.60 MHz), multiply the result by 1.65 (Klobuchar, 1996).
  51.  * More generally, since ionospheric delay is inversely proportional to the square of the signal
  52.  * frequency f, to adapt this model to other GNSS frequencies f, multiply by (L1 / f)^2.
  53.  *
  54.  * References:
  55.  *     ICD-GPS-200, Rev. C, (1997), pp. 125-128
  56.  *     Klobuchar, J.A., Ionospheric time-delay algorithm for single-frequency GPS users,
  57.  *         IEEE Transactions on Aerospace and Electronic Systems, Vol. 23, No. 3, May 1987
  58.  *     Klobuchar, J.A., "Ionospheric Effects on GPS", Global Positioning System: Theory and
  59.  *         Applications, 1996, pp.513-514, Parkinson, Spilker.
  60.  *
  61.  * @author Joris Olympio
  62.  * @since 7.1
  63.  *
  64.  */
  65. public class KlobucharIonoModel implements IonosphericModel {

  66.     /** Serializable UID. */
  67.     private static final long serialVersionUID = 7277525837842061107L;

  68.     /** The 4 coefficients of a cubic equation representing the amplitude of the vertical delay. Units are sec/semi-circle^(i-1) for the i-th coefficient, i=1, 2, 3, 4. */
  69.     private final double[] alpha;

  70.     /** The 4 coefficients of a cubic equation representing the period of the model. Units are sec/semi-circle^(i-1) for the i-th coefficient, i=1, 2, 3, 4. */
  71.     private final double[] beta;

  72.     /** GPS time scale. */
  73.     private final TimeScale gps;

  74.     /** Create a new Klobuchar ionospheric delay model, when a single frequency system is used.
  75.      * This model accounts for at least 50 percent of RMS error due to ionospheric propagation effect (ICD-GPS-200)
  76.      *
  77.      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
  78.      *
  79.      * @param alpha coefficients of a cubic equation representing the amplitude of the vertical delay.
  80.      * @param beta coefficients of a cubic equation representing the period of the model.
  81.      * @see #KlobucharIonoModel(double[], double[], TimeScale)
  82.      */
  83.     @DefaultDataContext
  84.     public KlobucharIonoModel(final double[] alpha, final double[] beta) {
  85.         this(alpha, beta, DataContext.getDefault().getTimeScales().getGPS());
  86.     }

  87.     /**
  88.      * Create a new Klobuchar ionospheric delay model, when a single frequency system is
  89.      * used. This model accounts for at least 50 percent of RMS error due to ionospheric
  90.      * propagation effect (ICD-GPS-200)
  91.      *
  92.      * @param alpha coefficients of a cubic equation representing the amplitude of the
  93.      *              vertical delay.
  94.      * @param beta  coefficients of a cubic equation representing the period of the
  95.      *              model.
  96.      * @param gps   GPS time scale.
  97.      * @since 10.1
  98.      */
  99.     public KlobucharIonoModel(final double[] alpha,
  100.                               final double[] beta,
  101.                               final TimeScale gps) {
  102.         this.alpha = alpha.clone();
  103.         this.beta  = beta.clone();
  104.         this.gps = gps;
  105.     }

  106.     /**
  107.      * Calculates the ionospheric path delay for the signal path from a ground
  108.      * station to a satellite.
  109.      * <p>
  110.      * The path delay is computed for any elevation angle.
  111.      * </p>
  112.      * @param date current date
  113.      * @param geo geodetic point of receiver/station
  114.      * @param elevation elevation of the satellite in radians
  115.      * @param azimuth azimuth of the satellite in radians
  116.      * @param frequency frequency of the signal in Hz
  117.      * @param parameters ionospheric model parameters
  118.      * @return the path delay due to the ionosphere in m
  119.      */
  120.     public double pathDelay(final AbsoluteDate date, final GeodeticPoint geo,
  121.                             final double elevation, final double azimuth, final double frequency,
  122.                             final double[] parameters) {

  123.         // Sine and cosine of the azimuth
  124.         final SinCos sc = FastMath.sinCos(azimuth);

  125.         // degrees to semicircles
  126.         final double rad2semi = 1. / FastMath.PI;
  127.         final double semi2rad = FastMath.PI;

  128.         // Earth Centered angle
  129.         final double psi = 0.0137 / (elevation / FastMath.PI + 0.11) - 0.022;

  130.         // Subionospheric latitude: the latitude of the IPP (Ionospheric Pierce Point)
  131.         // in [-0.416, 0.416], semicircle
  132.         final double latIono = FastMath.min(
  133.                                       FastMath.max(geo.getLatitude() * rad2semi + psi * sc.cos(), -0.416),
  134.                                       0.416);

  135.         // Subionospheric longitude: the longitude of the IPP
  136.         // in semicircle
  137.         final double lonIono = geo.getLongitude() * rad2semi + (psi * sc.sin() / FastMath.cos(latIono * semi2rad));

  138.         // Geomagnetic latitude, semicircle
  139.         final double latGeom = latIono + 0.064 * FastMath.cos((lonIono - 1.617) * semi2rad);

  140.         // day of week and tow (sec)
  141.         // Note: Sunday=0, Monday=1, Tuesday=2, Wednesday=3, Thursday=4, Friday=5, Saturday=6
  142.         final DateTimeComponents dtc = date.getComponents(gps);
  143.         final int dofweek = dtc.getDate().getDayOfWeek();
  144.         final double secday = dtc.getTime().getSecondsInLocalDay();
  145.         final double tow = dofweek * 86400. + secday;

  146.         final double t = 43200. * lonIono + tow;
  147.         final double tsec = t - FastMath.floor(t / 86400.) * 86400; // Seconds of day

  148.         // Slant factor, semicircle
  149.         final double slantFactor = 1.0 + 16.0 * FastMath.pow(0.53 - elevation / FastMath.PI, 3);

  150.         // Period of model, seconds
  151.         final double period = FastMath.max(72000., beta[0] + (beta[1]  + (beta[2] + beta[3] * latGeom) * latGeom) * latGeom);

  152.         // Phase of the model, radians
  153.         // (Max at 14.00 = 50400 sec local time)
  154.         final double x = 2.0 * FastMath.PI * (tsec - 50400.0) / period;

  155.         // Amplitude of the model, seconds
  156.         final double amplitude = FastMath.max(0, alpha[0] + (alpha[1]  + (alpha[2] + alpha[3] * latGeom) * latGeom) * latGeom);

  157.         // Ionospheric correction (L1)
  158.         double ionoTimeDelayL1 = slantFactor * (5. * 1e-9);
  159.         if (FastMath.abs(x) < 1.570) {
  160.             ionoTimeDelayL1 += slantFactor * (amplitude * (1.0 - FastMath.pow(x, 2) / 2.0 + FastMath.pow(x, 4) / 24.0));
  161.         }

  162.         // Ionospheric delay for the L1 frequency, in meters, with slant correction.
  163.         final double ratio = FastMath.pow(1575.42e6 / frequency, 2);
  164.         return ratio * Constants.SPEED_OF_LIGHT * ionoTimeDelayL1;
  165.     }

  166.     /** {@inheritDoc} */
  167.     @Override
  168.     public double pathDelay(final SpacecraftState state, final TopocentricFrame baseFrame,
  169.                             final double frequency, final double[] parameters) {

  170.         // Elevation in radians
  171.         final Vector3D position  = state.getPVCoordinates(baseFrame).getPosition();
  172.         final double   elevation = position.getDelta();

  173.         // Only consider measures above the horizon
  174.         if (elevation > 0.0) {
  175.             // Date
  176.             final AbsoluteDate date = state.getDate();
  177.             // Geodetic point
  178.             final GeodeticPoint geo = baseFrame.getPoint();
  179.             // Azimuth angle in radians
  180.             double azimuth = FastMath.atan2(position.getX(), position.getY());
  181.             if (azimuth < 0.) {
  182.                 azimuth += MathUtils.TWO_PI;
  183.             }
  184.             // Delay
  185.             return pathDelay(date, geo, elevation, azimuth, frequency, parameters);
  186.         }

  187.         return 0.0;
  188.     }

  189.     /**
  190.      * Calculates the ionospheric path delay for the signal path from a ground
  191.      * station to a satellite.
  192.      * <p>
  193.      * The path delay is computed for any elevation angle.
  194.      * </p>
  195.      * @param <T> type of the elements
  196.      * @param date current date
  197.      * @param geo geodetic point of receiver/station
  198.      * @param elevation elevation of the satellite in radians
  199.      * @param azimuth azimuth of the satellite in radians
  200.      * @param frequency frequency of the signal in Hz
  201.      * @param parameters ionospheric model parameters
  202.      * @return the path delay due to the ionosphere in m
  203.      */
  204.     public <T extends CalculusFieldElement<T>> T pathDelay(final FieldAbsoluteDate<T> date, final FieldGeodeticPoint<T> geo,
  205.                                                        final T elevation, final T azimuth, final double frequency,
  206.                                                        final T[] parameters) {

  207.         // Sine and cosine of the azimuth
  208.         final FieldSinCos<T> sc = FastMath.sinCos(azimuth);

  209.         // Field
  210.         final Field<T> field = date.getField();
  211.         final T zero = field.getZero();
  212.         final T one  = field.getOne();

  213.         // degrees to semicircles
  214.         final T pi       = one.getPi();
  215.         final T rad2semi = pi.reciprocal();

  216.         // Earth Centered angle
  217.         final T psi = elevation.divide(pi).add(0.11).divide(0.0137).reciprocal().subtract(0.022);

  218.         // Subionospheric latitude: the latitude of the IPP (Ionospheric Pierce Point)
  219.         // in [-0.416, 0.416], semicircle
  220.         final T latIono = FastMath.min(
  221.                                       FastMath.max(geo.getLatitude().multiply(rad2semi).add(psi.multiply(sc.cos())), zero.subtract(0.416)),
  222.                                       zero.add(0.416));

  223.         // Subionospheric longitude: the longitude of the IPP
  224.         // in semicircle
  225.         final T lonIono = geo.getLongitude().multiply(rad2semi).add(psi.multiply(sc.sin()).divide(FastMath.cos(latIono.multiply(pi))));

  226.         // Geomagnetic latitude, semicircle
  227.         final T latGeom = latIono.add(FastMath.cos(lonIono.subtract(1.617).multiply(pi)).multiply(0.064));

  228.         // day of week and tow (sec)
  229.         // Note: Sunday=0, Monday=1, Tuesday=2, Wednesday=3, Thursday=4, Friday=5, Saturday=6
  230.         final DateTimeComponents dtc = date.getComponents(gps);
  231.         final int dofweek = dtc.getDate().getDayOfWeek();
  232.         final double secday = dtc.getTime().getSecondsInLocalDay();
  233.         final double tow = dofweek * 86400. + secday;

  234.         final T t = lonIono.multiply(43200.).add(tow);
  235.         final T tsec = t.subtract(FastMath.floor(t.divide(86400.)).multiply(86400.)); // Seconds of day

  236.         // Slant factor, semicircle
  237.         final T slantFactor = FastMath.pow(elevation.divide(pi).negate().add(0.53), 3).multiply(16.0).add(one);

  238.         // Period of model, seconds
  239.         final T period = FastMath.max(zero.add(72000.), latGeom.multiply(latGeom.multiply(latGeom.multiply(beta[3]).add(beta[2])).add(beta[1])).add(beta[0]));

  240.         // Phase of the model, radians
  241.         // (Max at 14.00 = 50400 sec local time)
  242.         final T x = tsec.subtract(50400.0).multiply(pi.multiply(2.0)).divide(period);

  243.         // Amplitude of the model, seconds
  244.         final T amplitude = FastMath.max(zero, latGeom.multiply(latGeom.multiply(latGeom.multiply(alpha[3]).add(alpha[2])).add(alpha[1])).add(alpha[0]));

  245.         // Ionospheric correction (L1)
  246.         T ionoTimeDelayL1 = slantFactor.multiply(5. * 1e-9);
  247.         if (FastMath.abs(x.getReal()) < 1.570) {
  248.             ionoTimeDelayL1 = ionoTimeDelayL1.add(slantFactor.multiply(amplitude.multiply(one.subtract(FastMath.pow(x, 2).multiply(0.5)).add(FastMath.pow(x, 4).divide(24.0)))));
  249.         }

  250.         // Ionospheric delay for the L1 frequency, in meters, with slant correction.
  251.         final double ratio = FastMath.pow(1575.42e6 / frequency, 2);
  252.         return ionoTimeDelayL1.multiply(Constants.SPEED_OF_LIGHT).multiply(ratio);
  253.     }

  254.     /** {@inheritDoc} */
  255.     @Override
  256.     public <T extends CalculusFieldElement<T>> T pathDelay(final FieldSpacecraftState<T> state, final TopocentricFrame baseFrame,
  257.                                                        final double frequency, final T[] parameters) {

  258.         // Elevation and azimuth in radians
  259.         final FieldVector3D<T> position = state.getPVCoordinates(baseFrame).getPosition();
  260.         final T elevation = position.getDelta();

  261.         if (elevation.getReal() > 0.0) {
  262.             // Date
  263.             final FieldAbsoluteDate<T> date = state.getDate();
  264.             // Geodetic point
  265.             final FieldGeodeticPoint<T> geo = baseFrame.getPoint(date.getField());
  266.             // Azimuth angle in radians
  267.             T azimuth = FastMath.atan2(position.getX(), position.getY());
  268.             if (azimuth.getReal() < 0.) {
  269.                 azimuth = azimuth.add(MathUtils.TWO_PI);
  270.             }
  271.             // Delay
  272.             return pathDelay(date, geo, elevation, azimuth, frequency, parameters);
  273.         }

  274.         return elevation.getField().getZero();
  275.     }

  276.     @Override
  277.     public List<ParameterDriver> getParametersDrivers() {
  278.         return Collections.emptyList();
  279.     }
  280. }