Skip to content

Commit

Permalink
🔧 Update lighting_condition
Browse files Browse the repository at this point in the history
  • Loading branch information
ronisbr committed Aug 4, 2023
1 parent 47d1d72 commit 824a0ff
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
39 changes: 24 additions & 15 deletions src/lighting_condition.jl
Original file line number Diff line number Diff line change
@@ -1,53 +1,62 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# Description
# ==============================================================================
# ==========================================================================================
#
# Compute the satellite lighting condition considering the Earth eclipse.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# References
# ==============================================================================
# ==========================================================================================
#
# [1] Longo, C. R. O., Rickman, S. L (1995). Method for the Calculation of
# Spacecraft Umbra and Penumbra Shadow Terminator Points. NASA Technical
# Paper 3547.
# [1] Longo, C. R. O., Rickman, S. L (1995). Method for the Calculation of Spacecraft Umbra
# and Penumbra Shadow Terminator Points. NASA Technical Paper 3547.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

export lighting_condition

"""
lighting_condition(r_i::AbstractVector, s_i::AbstractVector)
Compute the lighting condition at the position `r_i` [m] considering the Sun
position vector `s_i` [m]. The possible return values are:
Compute the lighting condition at the position `r_i` [m] considering the Sun position vector
`s_i` [m]. The possible return values are:
- `:sunlight`: The point is under direct sunlight.
- `:penumbra`: The point is in penumbra region.
- `:umbra`: The point is in umbra region.
The algorithm used in this function was based on **[1]**.
!!! note
The vectors `r_i` and `s_i` must be represented in the same reference frame.
# References
- **[1]** Longo, C. R. O., Rickman, S. L (1995). Method for the Calculation of Spacecraft
Umbra and Penumbra Shadow Terminator Points. NASA Technical Paper 3547.
"""
function lighting_condition(r_i::AbstractVector, s_i::AbstractVector)
# Constants.
R₀ = EARTH_EQUATORIAL_RADIUS
Rs = SUN_RADIUS

# Distance from the Earth to the Sun.
norm_s_i = norm(s_i)

# Projection of the satellite position vector on the Sun direction [1].
rs_i = (r_i s_i) * s_i / (norm_s_i * norm_s_i)

# Check if the satellite is under sunlight, umbra or penumbra.

if (rs_i s_i / norm_s_i) < 0
# Distance of the umbral cone and the spacecraft [1].
Δ_i = r_i - rs_i
norm_Δ_i = norm(Δ_i)

# Penumbra section [1].
xp = R0 * norm_s_i / (Rs + R0)
αp = asin(R0 / xp)
xp = R₀ * norm_s_i / (Rs + R₀)
αp = asin(R₀ / xp)

# Location of the penumbral cone terminator at the projected spacecraft
# location [1].
Expand All @@ -57,8 +66,8 @@ function lighting_condition(r_i::AbstractVector, s_i::AbstractVector)
return :sunlight
else
# Umbra section [1].
xu = R0 * norm_s_i / (Rs - R0)
αu = asin(R0 / xu)
xu = R₀ * norm_s_i / (Rs - R₀)
αu = asin(R₀ / xu)

# Location of the umbral cone terminator at the projected spacecraft
# location [1].
Expand Down
20 changes: 10 additions & 10 deletions test/lighting_condition.jl
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# Description
# ==============================================================================
# ==========================================================================================
#
# Tests related to lighting condition analysis.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# File: ./src/lighting_condition.jl
# ==============================================================================
# ==========================================================================================

# Function: lighting_condition
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------

@testset "Function lighting_condition" begin
jd = date_to_jd(2021, 12, 8, 0, 0, 25)
s_i = sun_position_i(jd)
s_i = sun_position_mod(jd)

r_i = SVector(1.06746e6, 3.22132e6, -6.2841e6)
lc = lighting_condition(r_i, s_i)
@test lc === :sunlight
@test lc == :sunlight

r_i = SVector(2.52449e6, 4.89401e6, -4.54648e6)
lc = lighting_condition(r_i, s_i)
@test lc === :penumbra
@test lc == :penumbra

r_i = SVector(3.9575e6, 5.91988e6, -489577.0)
lc = lighting_condition(r_i, s_i)
@test lc === :umbra
@test lc == :umbra

lc = lighting_condition(s_i / norm(s_i) * 7000e3, s_i)
@test lc === :sunlight
@test lc == :sunlight
end
6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ using SatelliteAnalysis
include("./beta_angle.jl")
end

# @testset "Lighting condition" verbose = true begin
# include("./lighting_condition.jl")
# end
@testset "Lighting condition" verbose = true begin
include("./lighting_condition.jl")
end

# @testset "Miscellaneous" verbose = true begin
# include("./misc.jl")
Expand Down

0 comments on commit 824a0ff

Please sign in to comment.