Skip to content

Commit

Permalink
Merge pull request #407 from CliMA/js/insol08
Browse files Browse the repository at this point in the history
use Insolation v0.8
  • Loading branch information
juliasloan25 authored Nov 27, 2023
2 parents 60c616b + 8fb650c commit 5e989b7
Show file tree
Hide file tree
Showing 22 changed files with 125 additions and 144 deletions.
6 changes: 3 additions & 3 deletions docs/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.9.4"
manifest_format = "2.0"
project_hash = "6cc9e2b156a4b59ebb284e1be687ef18f212cffe"
project_hash = "6e09c6e4bb3544522827eac8007d75cd7aedbc96"

[[deps.ADTypes]]
git-tree-sha1 = "332e5d7baeff8497b923b730b994fa480601efc7"
Expand Down Expand Up @@ -746,9 +746,9 @@ version = "0.1.1"

[[deps.Insolation]]
deps = ["Artifacts", "Dates", "DelimitedFiles", "Interpolations"]
git-tree-sha1 = "eb83622d1d24e764d799ebeb92e9ffa5926870fc"
git-tree-sha1 = "937658520f9d5786ea11b70713163fe277925492"
uuid = "e98cc03f-d57e-4e3c-b70c-8d51efe9e0d8"
version = "0.7.0"
version = "0.8.0"

[[deps.IntelOpenMP_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"
[compat]
CLIMAParameters = "0.7"
ClimaTimeSteppers = "=0.7.7"
Insolation = "0.7"
Insolation = "0.8"
InteractiveUtils = "1"
2 changes: 1 addition & 1 deletion docs/tutorials/integrated/soil_canopy_tutorial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import SciMLBase
using Plots
using Statistics
using Dates
using Insolation


# Load CliMA Packages and ClimaLSM Modules:

Expand Down
10 changes: 2 additions & 8 deletions docs/tutorials/standalone/Bucket/bucket_tutorial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ using ClimaCore
import CLIMAParameters as CP

# We also use Insolation to calculate solar zenith angle and solar insolation.
using Insolation


# Lastly, let's bring in the bucket model types (from ClimaLSM) that we
# will need access to.
Expand Down Expand Up @@ -230,13 +230,7 @@ ref_time = DateTime(2005);
# Here we define the model drivers, starting with downward radiation.
SW_d = (t) -> 300;
LW_d = (t) -> 300;
bucket_rad = PrescribedRadiativeFluxes(
FT,
SW_d,
LW_d,
ref_time;
orbital_data = Insolation.OrbitalData(),
);
bucket_rad = PrescribedRadiativeFluxes(FT, SW_d, LW_d, ref_time);

# Prescribed atmospheric variables

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/standalone/Canopy/canopy_tutorial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import SciMLBase
using Plots
using Statistics
using Dates
using Insolation


# Load CliMA Packages and ClimaLSM Modules:

Expand Down
6 changes: 3 additions & 3 deletions experiments/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.9.4"
manifest_format = "2.0"
project_hash = "b3e3a6d4123251d3704cd4a385039b761f093c21"
project_hash = "2067c786604e9e079cf0e3e81be0d40fac5319be"

[[deps.ADTypes]]
git-tree-sha1 = "332e5d7baeff8497b923b730b994fa480601efc7"
Expand Down Expand Up @@ -724,9 +724,9 @@ version = "0.1.1"

[[deps.Insolation]]
deps = ["Artifacts", "Dates", "DelimitedFiles", "Interpolations"]
git-tree-sha1 = "eb83622d1d24e764d799ebeb92e9ffa5926870fc"
git-tree-sha1 = "937658520f9d5786ea11b70713163fe277925492"
uuid = "e98cc03f-d57e-4e3c-b70c-8d51efe9e0d8"
version = "0.7.0"
version = "0.8.0"

[[deps.IntelOpenMP_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
Expand Down
2 changes: 1 addition & 1 deletion experiments/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"
[compat]
CLIMAParameters = "0.7"
ClimaTimeSteppers = "=0.7.7"
Insolation = "0.7"
Insolation = "0.8"
Statistics = "1"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import CLIMAParameters as CP
using Plots
using Statistics
using Dates
using Insolation


using ClimaLSM
using ClimaLSM.Domains: Column
Expand Down
2 changes: 1 addition & 1 deletion experiments/integrated/ozark/ozark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import CLIMAParameters as CP
using Plots
using Statistics
using Dates
using Insolation

using StatsBase

using ClimaLSM
Expand Down
28 changes: 18 additions & 10 deletions experiments/integrated/ozark/ozark_met_drivers_FLUXNET.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
## Citation: Jeffrey Wood, Lianhong Gu (2021),
## AmeriFlux FLUXNET-1F US-MOz Missouri Ozark Site, Ver. 3-5, AmeriFlux AMP, (Dataset). https://doi.org/10.17190/AMF/1854370


using ArtifactWrappers
using DelimitedFiles
using Dierckx
using Thermodynamics
using Dates
import Insolation

function replace_missing_with_mean!(field, flag)
good_indices = (flag .== 0) .|| (flag .== 1)
fill_value = mean(field[good_indices])
Expand Down Expand Up @@ -133,23 +134,31 @@ long = FT(-92.2000) # degree

function zenith_angle(
t,
orbital_data,
ref_time;
latitude = lat,
longitude = long,
insol_params::Insolation.Parameters.InsolationParameters{FT} = earth_param_set.insol_params,
) where {FT}
# This should be time in UTC
dt = ref_time + Dates.Second(round(t))
# Orbital Data uses Float64, so we need to convert to our sim
# FT.
current_datetime = ref_time + Dates.Second(round(t))

# Orbital Data uses Float64, so we need to convert to our sim FT
d, δ, η_UTC =
FT.(
Insolation.helper_instantaneous_zenith_angle(
current_datetime,
ref_time,
insol_params,
)
)

FT(
instantaneous_zenith_angle(
dt,
orbital_data,
Insolation.instantaneous_zenith_angle(
d,
δ,
η_UTC,
longitude,
latitude,
insol_params,
)[1],
)
end
Expand All @@ -161,7 +170,6 @@ radiation = ClimaLSM.PrescribedRadiativeFluxes(
LW_IN_spline,
UTC_DATETIME[1];
θs = zenith_angle,
orbital_data = Insolation.OrbitalData(),
)


Expand Down
2 changes: 1 addition & 1 deletion experiments/integrated/vaira_ranch/vaira.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import CLIMAParameters as CP
using Plots
using Statistics
using Dates
using Insolation

using StatsBase

using ClimaLSM
Expand Down
27 changes: 18 additions & 9 deletions experiments/integrated/vaira_ranch/vaira_met_drivers_FLUXNET.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ using Dierckx
using Thermodynamics
using Dates
using ArtifactWrappers
import Insolation

function replace_missing_with_mean!(field, flag)
good_indices = (flag .== 0) .|| (flag .== 1)
fill_value = mean(field[good_indices])
Expand Down Expand Up @@ -152,23 +154,31 @@ long = FT(-120.9508) # degree

function zenith_angle(
t,
orbital_data,
ref_time;
latitude = lat,
longitude = long,
insol_params::Insolation.Parameters.InsolationParameters{FT} = earth_param_set.insol_params,
) where {FT}
# This should be time in UTC
dt = ref_time + Dates.Second(round(t))
# Orbital Data uses Float64, so we need to convert to our sim
# FT.
current_datetime = ref_time + Dates.Second(round(t))

# Orbital Data uses Float64, so we need to convert to our sim FT.
d, δ, η_UTC =
FT.(
Insolation.helper_instantaneous_zenith_angle(
current_datetime,
ref_time,
insol_params,
)
)

FT(
instantaneous_zenith_angle(
dt,
orbital_data,
Insolation.instantaneous_zenith_angle(
d,
δ,
η_UTC,
longitude,
latitude,
insol_params,
)[1],
)
end
Expand All @@ -180,7 +190,6 @@ radiation = ClimaLSM.PrescribedRadiativeFluxes(
LW_IN_spline,
UTC_DATETIME[1];
θs = zenith_angle,
orbital_data = Insolation.OrbitalData(),
)

# LAI data
Expand Down
10 changes: 2 additions & 8 deletions experiments/standalone/Soil/evaporation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using Plots
import SciMLBase
import ClimaTimeSteppers as CTS
using Thermodynamics
using Insolation

using ClimaCore
import CLIMAParameters as CP
using RootSolvers
Expand Down Expand Up @@ -67,13 +67,7 @@ for (FT, tf) in ((Float32, 2 * dt), (Float64, tf))
ref_time = DateTime(2005)
SW_d = (t) -> 0
LW_d = (t) -> 301.15^4 * 5.67e-8
radiation = PrescribedRadiativeFluxes(
FT,
SW_d,
LW_d,
ref_time;
orbital_data = Insolation.OrbitalData(),
)
radiation = PrescribedRadiativeFluxes(FT, SW_d, LW_d, ref_time)
# Atmos
T_air = 301.15
rh = 0.38
Expand Down
18 changes: 4 additions & 14 deletions src/shared_utilities/drivers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,15 @@ function surface_fluxes_at_a_point(
end

"""
PrescribedRadiativeFluxes{FT, DT, T, OD} <: AbstractRadiativeDrivers{FT}
PrescribedRadiativeFluxes{FT, SW, LW, DT, T} <: AbstractRadiativeDrivers{FT}
Container for the prescribed radiation functions needed to drive land models in standalone mode.
$(DocStringExtensions.FIELDS)
The arguments labeled with "function of time" are typically either of type
`Function` or type `Spline1D` from the `Dierckx.jl` package.
"""
struct PrescribedRadiativeFluxes{FT, SW, LW, DT, T, OD} <:
struct PrescribedRadiativeFluxes{FT, SW, LW, DT, T} <:
AbstractRadiativeDrivers{FT}
"Downward shortwave radiation function of time (W/m^2): positive indicates towards surface"
SW_d::SW
Expand All @@ -291,18 +291,8 @@ struct PrescribedRadiativeFluxes{FT, SW, LW, DT, T, OD} <:
ref_time::DT
"Sun zenith angle, in radians"
θs::T
"Orbital Data for Insolation.jl"
orbital_data::OD
function PrescribedRadiativeFluxes(
FT,
SW_d,
LW_d,
ref_time;
θs = nothing,
orbital_data,
)
args = (SW_d, LW_d, ref_time, θs, orbital_data)
@assert !isnothing(orbital_data)
function PrescribedRadiativeFluxes(FT, SW_d, LW_d, ref_time; θs = nothing)
args = (SW_d, LW_d, ref_time, θs)
return new{FT, typeof.(args)...}(args...)
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/standalone/Vegetation/Canopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ function ClimaLSM.make_update_aux(

# Current atmospheric conditions
ref_time = canopy.atmos.ref_time
θs::FT = canopy.radiation.θs(t, canopy.radiation.orbital_data, ref_time)
θs::FT = canopy.radiation.θs(t, ref_time)
c_co2_air::FT = canopy.atmos.c_co2(t)
P_air::FT = canopy.atmos.P(t)
T_air::FT = canopy.atmos.T(t)
Expand Down
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"
Aqua = "0.8"
CLIMAParameters = "0.7"
DelimitedFiles = "1"
Insolation = "0.7"
Insolation = "0.8"
NLsolve = "4.5"
SafeTestsets = "0.1"
Test = "1"
15 changes: 3 additions & 12 deletions test/standalone/Bucket/albedo_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using ClimaCore
using ClimaCore: Geometry, Meshes, Domains, Topologies, Spaces, Fields
using ClimaComms
import CLIMAParameters as CP
using Insolation

using Dates
using NCDatasets
using JLD2
Expand Down Expand Up @@ -302,15 +302,13 @@ end
npolynomial = 2,
),
]
orbital_data = Insolation.OrbitalData()

for bucket_domain in bucket_domains
# Radiation
ref_time = DateTime(2005)
SW_d = (t) -> 0.0
LW_d = (t) -> 5.67e-8 * 280.0^4.0
bucket_rad =
PrescribedRadiativeFluxes(FT, SW_d, LW_d, ref_time; orbital_data)
bucket_rad = PrescribedRadiativeFluxes(FT, SW_d, LW_d, ref_time)
# Atmos
precip = (t) -> 0 # no precipitation
T_atmos = (t) -> 280.0
Expand Down Expand Up @@ -416,7 +414,6 @@ end
npolynomial = 2,
),
]
orbital_data = Insolation.OrbitalData()

for bucket_domain in bucket_domains
space = bucket_domain.space.surface
Expand All @@ -427,13 +424,7 @@ end
ref_time = DateTime(2005)
SW_d = (t) -> 0
LW_d = (t) -> 5.67e-8 * 280.0^4.0
bucket_rad = PrescribedRadiativeFluxes(
FT,
SW_d,
LW_d,
ref_time;
orbital_data,
)
bucket_rad = PrescribedRadiativeFluxes(FT, SW_d, LW_d, ref_time)
# Atmos
precip = (t) -> 0 # no precipitation
T_atmos = (t) -> 280.0
Expand Down
Loading

0 comments on commit 5e989b7

Please sign in to comment.