ApparentElevationDetector.java

  1. /* Copyright 2002-2013 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.propagation.events;

  18. import org.apache.commons.math3.util.FastMath;
  19. import org.orekit.errors.OrekitException;
  20. import org.orekit.frames.TopocentricFrame;
  21. import org.orekit.propagation.SpacecraftState;
  22. import org.orekit.propagation.events.handlers.EventHandler;
  23. import org.orekit.propagation.events.handlers.StopOnDecreasing;

  24. /** Finder for satellite apparent elevation events.
  25.  * <p>This class finds apparent elevation events (i.e. apparent satellite raising
  26.  *  and setting from a terrestrial viewpoint).</p>
  27.  * <p>Apparent elevation is the sum of geometrical elevation and refraction angle,
  28.  *  the latter is 0 at zenith, about 1 arcminute at 45°, and 34 arcminutes at the
  29.  *  horizon for optical wavelengths.</p>
  30.  * <p>This event only makes sense for positive apparent elevation in the Earth environment
  31.  * and it is not suited for near zenithal detection, where the simple
  32.  * {@link ElevationDetector} fits better.</p>
  33.  * <p>Refraction angle is computed according to Saemundssen formula quoted by Meeus.
  34.  *  For reference, see <b>Astronomical Algorithms</b> (1998), 2nd ed,
  35.  *  (ISBN 0-943396-61-1), chap. 15.</p>
  36.  * <p>This formula is about 30 arcseconds of accuracy very close to the horizon, as
  37.  *  variable atmospheric effects become very important.</p>
  38.  * <p>Local pressure and temperature can be set to correct refraction at the viewpoint.</p>
  39.  * <p>The default implementation behavior is to {@link
  40.  * org.orekit.propagation.events.handlers.EventHandler.Action#CONTINUE continue}
  41.  * propagation at raising and to {@link
  42.  * org.orekit.propagation.events.handlers.EventHandler.Action#STOP stop} propagation
  43.  * at setting. This can be changed by calling
  44.  * {@link #withHandler(EventHandler)} after construction.</p>
  45.  * @see org.orekit.propagation.Propagator#addEventDetector(EventDetector)
  46.  * @author Pascal Parraud
  47.  * @deprecated as of 6.1 replaced by {@link ElevationDetector}
  48.  */
  49. @Deprecated
  50. public class ApparentElevationDetector extends AbstractReconfigurableDetector<ApparentElevationDetector> {

  51.     /** Default local pressure at viewpoint (Pa). */
  52.     public static final double DEFAULT_PRESSURE = 101000.0;

  53.     /** Default local temperature at viewpoint (K). */
  54.     public static final double DEFAULT_TEMPERATURE = 283.0;

  55.     /** Serializable UID. */
  56.     private static final long serialVersionUID = 20131118L;

  57.     /** Elevation min value to compute refraction (under the horizon). */
  58.     private static final double MIN_ELEVATION = -2.0;

  59.     /** Elevation max value to compute refraction (zenithal). */
  60.     private static final double MAX_ELEVATION = 89.89;

  61.     /** Local pressure. */
  62.     private double pressure = DEFAULT_PRESSURE;

  63.     /** Local temperature. */
  64.     private double temperature = DEFAULT_TEMPERATURE;

  65.     /** Refraction correction from local pressure and temperature. */
  66.     private double correfrac = 1.;

  67.     /** Threshold apparent elevation value. */
  68.     private final double elevation;

  69.     /** Topocentric frame in which elevation should be evaluated. */
  70.     private final TopocentricFrame topo;

  71.     /** Build a new apparent elevation detector.
  72.      * <p>This simple constructor takes default values for maximal checking
  73.      *  interval ({@link #DEFAULT_MAXCHECK}) and convergence threshold
  74.      * ({@link #DEFAULT_THRESHOLD}).</p>
  75.      * @param elevation threshold elevation value
  76.      * @param topo topocentric frame in which elevation should be evaluated
  77.      */
  78.     public ApparentElevationDetector(final double elevation, final TopocentricFrame topo) {
  79.         this(DEFAULT_MAXCHECK, DEFAULT_THRESHOLD, elevation, topo);
  80.     }

  81.     /** Build a new apparent elevation detector.
  82.      * <p>This constructor takes default value for convergence threshold
  83.      * ({@link #DEFAULT_THRESHOLD}).</p>
  84.      * <p>The maximal interval between elevation checks should
  85.      * be smaller than the half duration of the minimal pass to handle,
  86.      * otherwise some short passes could be missed.</p>
  87.      * @param maxCheck maximal checking interval (s)
  88.      * @param elevation threshold elevation value (rad)
  89.      * @param topo topocentric frame in which elevation should be evaluated
  90.      */
  91.     public ApparentElevationDetector(final double maxCheck,
  92.                                      final double elevation,
  93.                                      final TopocentricFrame topo) {
  94.         this(maxCheck, DEFAULT_THRESHOLD, elevation, topo);
  95.     }

  96.     /** Build a new apparent elevation detector.
  97.      * <p>The maximal interval between elevation checks should
  98.      * be smaller than the half duration of the minimal pass to handle,
  99.      * otherwise some short passes could be missed.</p>
  100.      * @param maxCheck maximal checking interval (s)
  101.      * @param threshold convergence threshold (s)
  102.      * @param elevation threshold elevation value (rad)
  103.      * @param topo topocentric frame in which elevation should be evaluated
  104.      */
  105.     public ApparentElevationDetector(final double maxCheck,
  106.                                      final double threshold,
  107.                                      final double elevation,
  108.                                      final TopocentricFrame topo) {
  109.         this(maxCheck, threshold, DEFAULT_MAX_ITER, new StopOnDecreasing<ApparentElevationDetector>(),
  110.              elevation, topo);
  111.     }

  112.     /** Private constructor with full parameters.
  113.      * <p>
  114.      * This constructor is private as users are expected to use the builder
  115.      * API with the various {@code withXxx()} methods to set up the instance
  116.      * in a readable manner without using a huge amount of parameters.
  117.      * </p>
  118.      * @param maxCheck maximum checking interval (s)
  119.      * @param maxIter maximum number of iterations in the event time search
  120.      * @param threshold convergence threshold (s)
  121.      * @param handler event handler to call at event occurrences
  122.      * @param elevation threshold elevation value (rad)
  123.      * @param topo topocentric frame in which elevation should be evaluated
  124.      * @since 6.1
  125.      */
  126.     private ApparentElevationDetector(final double maxCheck, final double threshold,
  127.                                       final int maxIter, final EventHandler<ApparentElevationDetector> handler,
  128.                                       final double elevation,
  129.                                       final TopocentricFrame topo) {
  130.         super(maxCheck, threshold, maxIter, handler);
  131.         this.elevation = elevation;
  132.         this.topo      = topo;
  133.     }

  134.     /** {@inheritDoc} */
  135.     @Override
  136.     protected ApparentElevationDetector create(final double newMaxCheck, final double newThreshold,
  137.                                                final int newMaxIter, final EventHandler<ApparentElevationDetector> newHandler) {
  138.         return new ApparentElevationDetector(newMaxCheck, newThreshold, newMaxIter, newHandler,
  139.                                              elevation, topo);
  140.     }

  141.     /** Set the local pressure at topocentric frame origin if needed.
  142.      * <p>Otherwise the default value for the local pressure is set to {@link #DEFAULT_PRESSURE}.</p>
  143.      * @param pressure the pressure to set (Pa)
  144.      */
  145.     public void setPressure(final double pressure) {
  146.         this.pressure = pressure;
  147.         this.correfrac = (pressure / DEFAULT_PRESSURE) * (DEFAULT_TEMPERATURE / temperature);
  148.     }

  149.     /** Set the local temperature at topocentric frame origin if needed.
  150.      * <p>Otherwise the default value for the local temperature is set to {@link #DEFAULT_TEMPERATURE}.</p>
  151.      * @param temperature the temperature to set (K)
  152.      */
  153.     public void setTemperature(final double temperature) {
  154.         this.temperature = temperature;
  155.         this.correfrac = (pressure / DEFAULT_PRESSURE) * (DEFAULT_TEMPERATURE / temperature);
  156.     }

  157.     /** Get the threshold apparent elevation value.
  158.      * @return the threshold apparent elevation value (rad)
  159.      */
  160.     public double getElevation() {
  161.         return elevation;
  162.     }

  163.     /** Get the topocentric frame.
  164.      * @return the topocentric frame
  165.      */
  166.     public TopocentricFrame getTopocentricFrame() {
  167.         return topo;
  168.     }

  169.     /** Get the local pressure at topocentric frame origin.
  170.      * @return the pressure
  171.      */
  172.     public double getPressure() {
  173.         return pressure;
  174.     }

  175.     /** Get the local temperature at topocentric frame origin.
  176.      * @return the temperature
  177.      */
  178.     public double getTemperature() {
  179.         return temperature;
  180.     }

  181.     /** Compute the value of the switching function.
  182.      * <p>This function measures the difference between the current apparent elevation
  183.      * and the threshold apparent elevation.</p>
  184.      * @param s the current state information: date, kinematics, attitude
  185.      * @return value of the switching function
  186.      * @exception OrekitException if some specific error occurs
  187.      */
  188.     public double g(final SpacecraftState s) throws OrekitException {
  189.         final double trueElevation = topo.getElevation(s.getPVCoordinates().getPosition(), s.getFrame(), s.getDate());
  190.         return trueElevation + getRefraction(trueElevation) - elevation;
  191.     }

  192.     /** Compute the refraction angle from the true (geometrical) elevation.
  193.      * @param trueElevation true elevation (rad)
  194.      * @return refraction angle (rad)
  195.      */
  196.     private double getRefraction(final double trueElevation) {
  197.         double refraction = 0.0;
  198.         final double eld = FastMath.toDegrees(trueElevation);
  199.         if (eld > MIN_ELEVATION && eld < MAX_ELEVATION) {
  200.             final double tmp = eld + 10.3 / (eld + 5.11);
  201.             final double ref = 1.02 / FastMath.tan(FastMath.toRadians(tmp)) / 60.;
  202.             refraction = FastMath.toRadians(correfrac * ref);
  203.         }
  204.         return refraction;
  205.     }

  206. }