GroundAtNightDetector.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.propagation.events;

  18. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  19. import org.hipparchus.util.FastMath;
  20. import org.orekit.frames.Frame;
  21. import org.orekit.frames.TopocentricFrame;
  22. import org.orekit.models.AtmosphericRefractionModel;
  23. import org.orekit.models.earth.ITURP834AtmosphericRefraction;
  24. import org.orekit.propagation.SpacecraftState;
  25. import org.orekit.propagation.events.handlers.ContinueOnEvent;
  26. import org.orekit.propagation.events.handlers.EventHandler;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.utils.PVCoordinatesProvider;


  29. /** Detector for ground location being at night.
  30.  * <p>
  31.  * This detector is mainly useful for scheduling optical measurements
  32.  * (either passive telescope observation of satellites against the stars background
  33.  *  or active satellite laser ranging).
  34.  * </p>
  35.  * <p>
  36.  * The {@code g} function of this detector is positive when ground is at night
  37.  * (i.e. Sun is below dawn/dusk elevation angle).
  38.  * </p>
  39.  * @author Luc Maisonobe
  40.  * @since 9.3
  41.  */
  42. public class GroundAtNightDetector extends AbstractDetector<GroundAtNightDetector> {

  43.     /** Sun elevation at civil dawn/dusk (6° below horizon). */
  44.     public static final double CIVIL_DAWN_DUSK_ELEVATION = FastMath.toRadians(-6.0);

  45.     /** Sun elevation at nautical dawn/dusk (12° below horizon). */
  46.     public static final double NAUTICAL_DAWN_DUSK_ELEVATION = FastMath.toRadians(-12.0);

  47.     /** Sun elevation at astronomical dawn/dusk (18° below horizon). */
  48.     public static final double ASTRONOMICAL_DAWN_DUSK_ELEVATION = FastMath.toRadians(-18.0);

  49.     /** Ground location to check. */
  50.     private final TopocentricFrame groundLocation;

  51.     /** Provider for Sun position. */
  52.     private final PVCoordinatesProvider sun;

  53.     /** Sun elevation below which we consider night is dark enough. */
  54.     private final double dawnDuskElevation;

  55.     /** Atmospheric Model used for calculations, if defined. */
  56.     private final AtmosphericRefractionModel refractionModel;

  57.     /** Simple constructor.
  58.      * <p>
  59.      * Beware that {@link org.orekit.models.earth.EarthStandardAtmosphereRefraction Earth
  60.      * standard refraction model} does apply only for elevations above -2°. It is therefore
  61.      * not suitable for used with {@link #CIVIL_DAWN_DUSK_ELEVATION} (-6°), {@link
  62.      * #NAUTICAL_DAWN_DUSK_ELEVATION} (-12°) or {@link #ASTRONOMICAL_DAWN_DUSK_ELEVATION} (-18°).
  63.      * The {@link ITURP834AtmosphericRefraction ITU-R P.834 refraction model}
  64.      * which can compute refraction at large negative elevations should be preferred.
  65.      * </p>
  66.      * @param groundLocation ground location to check
  67.      * @param sun provider for Sun position
  68.      * @param dawnDuskElevation Sun elevation below which we consider night is dark enough (rad)
  69.      * (typically {@link #ASTRONOMICAL_DAWN_DUSK_ELEVATION})
  70.      * @param refractionModel reference to refraction model (null if refraction should be ignored)
  71.      */
  72.     public GroundAtNightDetector(final TopocentricFrame groundLocation, final PVCoordinatesProvider sun,
  73.                                  final double dawnDuskElevation,
  74.                                  final AtmosphericRefractionModel refractionModel) {
  75.         this(groundLocation, sun, dawnDuskElevation, refractionModel,
  76.                 EventDetectionSettings.getDefaultEventDetectionSettings(), new ContinueOnEvent());
  77.     }

  78.     /** Private constructor.
  79.      * @param groundLocation ground location from which measurement is performed
  80.      * @param sun provider for Sun position
  81.      * @param dawnDuskElevation Sun elevation below which we consider night is dark enough (rad)
  82.      * (typically {@link #ASTRONOMICAL_DAWN_DUSK_ELEVATION})
  83.      * @param refractionModel reference to refraction model (null if refraction should be ignored),
  84.      * @param detectionSettings event detection settings
  85.      * @param handler   event handler to call at event occurrences
  86.      * @since 13.0
  87.      */
  88.     protected GroundAtNightDetector(final TopocentricFrame groundLocation, final PVCoordinatesProvider sun,
  89.                                     final double dawnDuskElevation,
  90.                                     final AtmosphericRefractionModel refractionModel,
  91.                                     final EventDetectionSettings detectionSettings,
  92.                                     final EventHandler handler) {
  93.         super(detectionSettings, handler);
  94.         this.groundLocation    = groundLocation;
  95.         this.sun               = sun;
  96.         this.dawnDuskElevation = dawnDuskElevation;
  97.         this.refractionModel   = refractionModel;
  98.     }

  99.     /** {@inheritDoc} */
  100.     @Override
  101.     protected GroundAtNightDetector create(final EventDetectionSettings detectionSettings,
  102.                                            final EventHandler newHandler) {
  103.         return new GroundAtNightDetector(groundLocation, sun, dawnDuskElevation, refractionModel,
  104.                                          detectionSettings, newHandler);
  105.     }

  106.     /** {@inheritDoc}
  107.      * <p>
  108.      * The {@code g} function of this detector is positive when ground is at night
  109.      * (i.e. Sun is below dawn/dusk elevation angle).
  110.      * </p>
  111.      * <p>
  112.      * This function only depends on date, not on the actual position of the spacecraft.
  113.      * </p>
  114.      */
  115.     @Override
  116.     public double g(final SpacecraftState state) {

  117.         final AbsoluteDate  date     = state.getDate();
  118.         final Frame         frame    = state.getFrame();
  119.         final Vector3D      position = sun.getPosition(date, frame);
  120.         final double trueElevation   = groundLocation.getElevation(position, frame, date);

  121.         final double calculatedElevation;
  122.         if (refractionModel != null) {
  123.             calculatedElevation = trueElevation + refractionModel.getRefraction(trueElevation);
  124.         } else {
  125.             calculatedElevation = trueElevation;
  126.         }

  127.         return dawnDuskElevation - calculatedElevation;

  128.     }

  129. }