Skip to content

Commit

Permalink
Refactor Snow, MedlynConductance, TwoStream, BeerLambert parameter co…
Browse files Browse the repository at this point in the history
…nstructors
  • Loading branch information
nefrathenrici committed Mar 20, 2024
1 parent 8152587 commit 217737a
Show file tree
Hide file tree
Showing 15 changed files with 240 additions and 221 deletions.
25 changes: 9 additions & 16 deletions docs/tutorials/integrated/soil_canopy_tutorial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,25 +225,18 @@ autotrophic_respiration_args =
(; parameters = AutotrophicRespirationParameters(FT))

radiative_transfer_args = (;
parameters = TwoStreamParameters{FT}(;
ld = FT(0.5),
α_PAR_leaf = FT(0.1),
α_NIR_leaf = FT(0.45),
τ_PAR_leaf = FT(0.05),
τ_NIR_leaf = FT(0.25),
Ω = FT(0.69),
λ_γ_PAR = FT(5e-7),
λ_γ_NIR = FT(1.65e-6),
parameters = TwoStreamParameters(
FT;
ld = 0.5,
α_PAR_leaf = 0.1,
α_NIR_leaf = 0.45,
τ_PAR_leaf = 0.05,
τ_NIR_leaf = 0.25,
Ω = 0.69,
)
)

conductance_args = (;
parameters = MedlynConductanceParameters{FT}(;
g1 = FT(141),
Drel = FT(1.6),
g0 = FT(1e-4),
)
)
conductance_args = (; parameters = MedlynConductanceParameters(FT; g1 = 141))

photosynthesis_args =
(; parameters = FarquharParameters(FT, Canopy.C3(); Vcmax25 = FT(5e-5)));
Expand Down
9 changes: 3 additions & 6 deletions docs/tutorials/standalone/Canopy/canopy_tutorial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ soil_driver = PrescribedSoil(
# Now, setup the canopy model by component.
# Provide arguments to each component, beginning with radiative transfer:

rt_params = TwoStreamParameters{FT}(;
rt_params = TwoStreamParameters(
FT;
ld = FT(0.5),
α_PAR_leaf = FT(0.1),
α_NIR_leaf = FT(0.45),
Expand All @@ -169,11 +170,7 @@ rt_model = TwoStreamModel{FT}(rt_params);

# Arguments for conductance model:

cond_params = MedlynConductanceParameters{FT}(;
g1 = FT(141),
Drel = FT(1.6),
g0 = FT(1e-4),
)
cond_params = MedlynConductanceParameters(FT; g1 = 141)

stomatal_model = MedlynConductanceModel{FT}(cond_params);

Expand Down
26 changes: 9 additions & 17 deletions experiments/integrated/fluxnet/ozark_pft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,26 +177,18 @@ autotrophic_respiration_args =
(; parameters = AutotrophicRespirationParameters(FT))
# Set up radiative transfer
radiative_transfer_args = (;
parameters = TwoStreamParameters{FT}(;
Ω = Ω,
ld = ld,
α_PAR_leaf = α_PAR_leaf,
λ_γ_PAR = λ_γ_PAR,
λ_γ_NIR = λ_γ_NIR,
τ_PAR_leaf = τ_PAR_leaf,
α_NIR_leaf = α_NIR_leaf,
τ_NIR_leaf = τ_NIR_leaf,
ϵ_canopy = ϵ_canopy,
parameters = TwoStreamParameters(
FT;
Ω,
ld,
α_PAR_leaf,
τ_PAR_leaf,
α_NIR_leaf,
τ_NIR_leaf,
)
)
# Set up conductance
conductance_args = (;
parameters = MedlynConductanceParameters{FT}(;
g1 = g1,
Drel = Drel,
g0 = g0,
)
)
conductance_args = (; parameters = MedlynConductanceParameters(FT; g1))
# Set up photosynthesis
# Set up photosynthesis
photosynthesis_args =
Expand Down
26 changes: 9 additions & 17 deletions experiments/integrated/fluxnet/run_fluxnet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,18 @@ autotrophic_respiration_args =
(; parameters = AutotrophicRespirationParameters(FT))
# Set up radiative transfer
radiative_transfer_args = (;
parameters = TwoStreamParameters{FT}(;
Ω = Ω,
ld = ld,
α_PAR_leaf = α_PAR_leaf,
λ_γ_PAR = λ_γ_PAR,
λ_γ_NIR = λ_γ_NIR,
τ_PAR_leaf = τ_PAR_leaf,
α_NIR_leaf = α_NIR_leaf,
τ_NIR_leaf = τ_NIR_leaf,
ϵ_canopy = ϵ_canopy,
parameters = TwoStreamParameters(
FT;
Ω,
ld,
α_PAR_leaf,
τ_PAR_leaf,
α_NIR_leaf,
τ_NIR_leaf,
)
)
# Set up conductance
conductance_args = (;
parameters = MedlynConductanceParameters{FT}(;
g1 = g1,
Drel = Drel,
g0 = g0,
)
)
conductance_args = (; parameters = MedlynConductanceParameters(FT; g1))
# Set up photosynthesis
photosynthesis_args =
(; parameters = FarquharParameters(FT, Canopy.C3(); Vcmax25 = Vcmax25))
Expand Down
25 changes: 9 additions & 16 deletions experiments/integrated/ozark/conservation/ozark_conservation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,18 @@ for float_type in (Float32, Float64)
(; parameters = AutotrophicRespirationParameters(FT))
# Set up radiative transfer
radiative_transfer_args = (;
parameters = TwoStreamParameters{FT}(;
Ω = Ω,
ld = ld,
α_PAR_leaf = α_PAR_leaf,
λ_γ_PAR = λ_γ_PAR,
λ_γ_NIR = λ_γ_NIR,
τ_PAR_leaf = τ_PAR_leaf,
α_NIR_leaf = α_NIR_leaf,
τ_NIR_leaf = τ_NIR_leaf,
parameters = TwoStreamParameters(
FT;
Ω,
ld,
α_PAR_leaf,
τ_PAR_leaf,
α_NIR_leaf,
τ_NIR_leaf,
)
)
# Set up conductance
conductance_args = (;
parameters = MedlynConductanceParameters{FT}(;
g1 = g1,
Drel = Drel,
g0 = g0,
)
)
conductance_args = (; parameters = MedlynConductanceParameters(FT; g1))
# Set up photosynthesis
photosynthesis_args =
(; parameters = FarquharParameters(FT, Canopy.C3(); Vcmax25 = Vcmax25))
Expand Down
172 changes: 172 additions & 0 deletions ext/CreateParametersExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import ClimaLand.Soil.EnergyHydrologyParameters
import ClimaLand.Canopy.AutotrophicRespirationParameters
import ClimaLand.Canopy.FarquharParameters
import ClimaLand.Canopy.OptimalityFarquharParameters
import ClimaLand.Canopy.BeerLambertParameters
import ClimaLand.Canopy.TwoStreamParameters
import ClimaLand.Snow.SnowParameters
import ClimaLand.Bucket.BucketModelParameters
import ClimaLand.Soil.Biogeochemistry.SoilCO2ModelParameters

Expand Down Expand Up @@ -494,4 +497,173 @@ function SoilCO2ModelParameters(toml_dict::CP.AbstractTOMLDict; kwargs...)
)
end

"""
function MedlynConductanceParameters(FT::AbstractFloat;
g1 = 790,
kwargs...
)
function MedlynConductanceParameters(toml_dict;
g1 = 790,
kwargs...
)
Floating-point and toml dict based constructor supplying default values
for the MedlynConductanceParameters struct.
Additional parameter values can be directly set via kwargs.
"""
MedlynConductanceParameters(::Type{FT}; kwargs...) where {FT <: AbstractFloat} =
MedlynConductanceParameters(CP.create_toml_dict(FT); kwargs...)

function MedlynConductanceParameters(
toml_dict::CP.AbstractTOMLDict;
g1 = 790,
kwargs...,
)
name_map = (;
:relative_diffusivity_of_water_vapor => :Drel,
:min_stomatal_conductance => :g0,
)

parameters = CP.get_parameter_values(toml_dict, name_map, "Land")
FT = CP.float_type(toml_dict)
return MedlynConductanceParameters{FT}(; g1, parameters..., kwargs...)
end

"""
function TwoStreamParameters(FT::AbstractFloat;
ld = 0.5,
α_PAR_leaf = 0.3,
τ_PAR_leaf = 0.2,
α_NIR_leaf = 0.4,
τ_NIR_leaf = 0.25,
Ω = 1,
n_layers = UInt64(20),
kwargs...
)
function TwoStreamParameters(toml_dict;
ld = 0.5,
α_PAR_leaf = 0.3,
τ_PAR_leaf = 0.2,
α_NIR_leaf = 0.4,
τ_NIR_leaf = 0.25,
Ω = 1,
n_layers = UInt64(20),
kwargs...
)
Floating-point and toml dict based constructor supplying default values
for the TwoStreamParameters struct. Additional parameter values can be directly set via kwargs.
"""
TwoStreamParameters(::Type{FT}; kwargs...) where {FT <: AbstractFloat} =
TwoStreamParameters(CP.create_toml_dict(FT); kwargs...)

function TwoStreamParameters(
toml_dict::CP.AbstractTOMLDict;
ld = 0.5,
α_PAR_leaf = 0.3,
τ_PAR_leaf = 0.2,
α_NIR_leaf = 0.4,
τ_NIR_leaf = 0.25,
Ω = 1,
n_layers = UInt64(20),
kwargs...,
)
name_map = (;
:wavelength_per_PAR_photon => :λ_γ_PAR,
:wavelength_per_NIR_photon => :λ_γ_NIR,
:canopy_emissivity => :ϵ_canopy,
)

parameters = CP.get_parameter_values(toml_dict, name_map, "Land")
FT = CP.float_type(toml_dict)
return TwoStreamParameters{FT}(;
ld,
α_PAR_leaf,
τ_PAR_leaf,
α_NIR_leaf,
τ_NIR_leaf,
Ω,
n_layers,
parameters...,
kwargs...,
)
end

"""
function BeerLambertParameters(FT::AbstractFloat;
ld = 0.5,
α_PAR_leaf = 0.1,
α_NIR_leaf = 0.4,
Ω = 1,
kwargs...
)
function BeerLambertParameters(toml_dict;
ld = 0.5,
α_PAR_leaf = 0.1,
α_NIR_leaf = 0.4,
Ω = 1,
kwargs...
)
Floating-point and toml dict based constructor supplying default values
for the BeerLambertParameters struct. Additional parameter values can be directly set via kwargs.
"""
BeerLambertParameters(::Type{FT}; kwargs...) where {FT <: AbstractFloat} =
BeerLambertParameters(CP.create_toml_dict(FT); kwargs...)

function BeerLambertParameters(
toml_dict::CP.AbstractTOMLDict;
ld = 0.5,
α_PAR_leaf = 0.1,
α_NIR_leaf = 0.4,
Ω = 1,
kwargs...,
)
name_map = (;
:wavelength_per_PAR_photon => :λ_γ_PAR,
:wavelength_per_NIR_photon => :λ_γ_NIR,
:canopy_emissivity => :ϵ_canopy,
)

parameters = CP.get_parameter_values(toml_dict, name_map, "Land")
FT = CP.float_type(toml_dict)
return BeerLambertParameters{FT}(;
ld,
α_PAR_leaf,
α_NIR_leaf,
Ω,
parameters...,
kwargs...,
)
end


SnowParameters(::Type{FT}, Δt; kwargs...) where {FT <: AbstractFloat} =
SnowParameters(CP.create_toml_dict(FT), Δt; kwargs...)

function SnowParameters(toml_dict::CP.AbstractTOMLDict, Δt; kwargs...)
name_map = (;
:snow_momentum_roughness_length => :z_0m,
:snow_scalar_roughness_length => :z_0b,
:thermal_conductivity_of_water_ice => :κ_ice,
:snow_density => :ρ_snow,
:snow_albedo => :α_snow,
:snow_emissivity => :ϵ_snow,
:holding_capacity_of_water_in_snow => :θ_r,
:wet_snow_hydraulic_conductivity => :Ksat,
:snow_cover_fraction_crit_threshold => :fS_c,
)

parameters = CP.get_parameter_values(toml_dict, name_map, "Land")
FT = CP.float_type(toml_dict)
earth_param_set = LandParameters(toml_dict)
PSE = typeof(earth_param_set)
return SnowParameters{FT, PSE}(;
Δt,
earth_param_set,
parameters...,
kwargs...,
)
end

end
6 changes: 4 additions & 2 deletions lib/ClimaLandSimulations/src/Fluxnet/run_fluxnet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ function run_fluxnet(
)
# Set up radiative transfer
radiative_transfer_args = (;
parameters = TwoStreamParameters{FT}(;
parameters = TwoStreamParameters(
FT;
Ω = params.radiative_transfer.Ω,
ld = params.radiative_transfer.ld,
α_PAR_leaf = params.radiative_transfer.α_PAR_leaf,
Expand All @@ -126,7 +127,8 @@ function run_fluxnet(
)
# Set up conductance
conductance_args = (;
parameters = MedlynConductanceParameters{FT}(;
parameters = MedlynConductanceParameters(
FT;
g1 = params.conductance.g1,
Drel = params.conductance.Drel,
g0 = params.conductance.g0,
Expand Down
Loading

0 comments on commit 217737a

Please sign in to comment.