KlobucharIonoModel.java

  1. /* Copyright 2002-2025 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.     /** 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. */
  67.     private final double[] alpha;

  68.     /** 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. */
  69.     private final double[] beta;

  70.     /** GPS time scale. */
  71.     private final TimeScale gps;

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

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

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

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

  123.         // degrees to semicircles
  124.         final double rad2semi = 1. / FastMath.PI;
  125.         final double semi2rad = FastMath.PI;

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

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

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

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

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

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

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

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

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

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

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

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

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

  168.         // Elevation in radians
  169.         final Vector3D position  = state.getPosition(baseFrame);
  170.         final double   elevation = position.getDelta();

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

  185.         return 0.0;
  186.     }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  272.         return elevation.getField().getZero();
  273.     }

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