From 20dffac141f868aa7a57481c92900b59043d0752 Mon Sep 17 00:00:00 2001 From: Zhaoyi Shen <11598433+szy21@users.noreply.github.com> Date: Sun, 16 Jun 2024 16:08:49 -0700 Subject: [PATCH] limit cos of zenith angle between -1 and 1 in ZenithAngleCalc.jl --- Project.toml | 2 +- src/ZenithAngleCalc.jl | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 6b34534..e900cac 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Insolation" uuid = "e98cc03f-d57e-4e3c-b70c-8d51efe9e0d8" authors = ["Climate Modeling Alliance"] -version = "0.9.2" +version = "0.9.3" [deps] Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" diff --git a/src/ZenithAngleCalc.jl b/src/ZenithAngleCalc.jl index 850a604..cd82adf 100644 --- a/src/ZenithAngleCalc.jl +++ b/src/ZenithAngleCalc.jl @@ -122,7 +122,10 @@ function instantaneous_zenith_angle( η = mod(η_UTC + λ, FT(2π)) # zenith angle, radians - θ = mod(acos(cos(ϕ) * cos(δ) * cos(η) + sin(ϕ) * sin(δ)), FT(2π)) + θ = mod( + acos(max(FT(-1), min(FT(1), cos(ϕ) * cos(δ) * cos(η) + sin(ϕ) * sin(δ)))), + FT(2π), + ) # solar azimuth angle, ζ = 0 when due E and increasing CCW # ζ = 3π/2 (due S) when η=0 at local solar noon