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 AbstractTopocentricDetector<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.     /** Provider for Sun position. */
  50.     private final PVCoordinatesProvider sun;

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

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

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

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

  96.     /** {@inheritDoc} */
  97.     @Override
  98.     protected GroundAtNightDetector create(final EventDetectionSettings detectionSettings,
  99.                                            final EventHandler newHandler) {
  100.         return new GroundAtNightDetector(getTopocentricFrame(), sun, dawnDuskElevation, refractionModel,
  101.                                          detectionSettings, newHandler);
  102.     }

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

  114.         final AbsoluteDate  date     = state.getDate();
  115.         final Frame         frame    = state.getFrame();
  116.         final Vector3D      position = sun.getPosition(date, frame);
  117.         final double trueElevation   = getTopocentricFrame().getElevation(position, frame, date);

  118.         final double calculatedElevation;
  119.         if (refractionModel != null) {
  120.             calculatedElevation = trueElevation + refractionModel.getRefraction(trueElevation);
  121.         } else {
  122.             calculatedElevation = trueElevation;
  123.         }

  124.         return dawnDuskElevation - calculatedElevation;

  125.     }

  126. }