Skip to content

Commit

Permalink
Change vegetation model parameters
Browse files Browse the repository at this point in the history
Rename these parameters to standard names.
 Additionally, made a start with standard name mapping (external standard name => internal model name). It makes use of `Wflow.param` functionality as much as possible, allowing to write any model output variable with the former TOML keys.
  • Loading branch information
vers-w committed Dec 11, 2024
1 parent 9e45b15 commit 1256662
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 132 deletions.
30 changes: 8 additions & 22 deletions server/test/sbm_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ soil_water_sat-zone_bottom__max_leakage_volume_flux = "MaxLeakage"
"soil_root~wet__sigmoid_function_shape_parameter" = "rootdistpar"
soil__thickness = "SoilThickness"

vegetation_canopy_water__mean_evaporation-to-mean_precipitation_ratio = "EoverR"
vegetation__leaf-area_index = "LAI"
vegetation_canopy__light-extinction_coefficient = "Kext"
vegetation__specific-leaf_storage = "Sl"
vegetation_woody-part__storage_capacity = "Swood"
vegetation_root__depth = "RootingDepth"

# specify the internal IDs of the parameters which vary over time
# the external name mapping needs to be below together with the other mappings
forcing = [
Expand All @@ -83,14 +90,7 @@ forcing = [
"vertical.atmospheric_forcing.potential_evaporation",
]

cyclic = ["vertical.vegetation_parameter_set.leaf_area_index"]

[input.vertical.vegetation_parameter_set]
leaf_area_index = "LAI"
kext = "Kext"
storage_specific_leaf = "Sl"
storage_wood = "Swood"
rootingdepth = "RootingDepth"
cyclic = ["vegetation__leaf-area_index"]

[input.vertical.runoff.parameters]
waterfrac = "WaterFrac"
Expand All @@ -103,20 +103,6 @@ potential_evaporation = "pet"
precipitation = "precip"
temperature = "temp"

[input.vertical.soil.parameters]
c = "c"
cf_soil = "cf_soil"
f = "f"
infiltcappath = "InfiltCapPath"
infiltcapsoil = "InfiltCapSoil"
water_holding_capacity = "WHC"
theta_r = "thetaR"
theta_s = "thetaS"
maxleakage = "MaxLeakage"
pathfrac = "PathFrac"
rootdistpar = "rootdistpar"
soilthickness = "SoilThickness"

[input.soil_surface_water__vertical_saturated_hydraulic_conductivity]
netcdf.variable.name = "KsatVer"
scale = 1.0
Expand Down
1 change: 1 addition & 0 deletions src/Wflow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function Clock(config, reader)
return Clock(starttime, 0, dt)
end

include("standard_name.jl")
include("io.jl")

"""
Expand Down
5 changes: 3 additions & 2 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function param(obj, fields, default)
return default
end
end
get_fields(name) = haskey(standard_name_map, name) ? standard_name_map[name] : name

"""
Config(path::AbstractString)
Expand Down Expand Up @@ -718,8 +719,8 @@ function prepare_reader(config)
cyclic_parameters = Dict{Tuple{Symbol, Vararg{Symbol}}, NamedTuple}()
cyclic_times = Dict{Tuple{Symbol, Vararg{Symbol}}, Vector{Tuple{Int, Int}}}()
for par in config.input.cyclic
fields = symbols(par)
ncname, mod = ncvar_name_modifier(param(config.input, fields))
fields = symbols(get_fields(par)) #TODO: make this more restrict (only allow variables in `standard_name_map`)
ncname, mod = ncvar_name_modifier(param(config.input, par))
i = findfirst(x -> startswith(x, "time"), dimnames(cyclic_dataset[ncname]))
dimname = dimnames(cyclic_dataset[ncname])[i]
cyclic_nc_times = collect(cyclic_dataset[dimname])
Expand Down
16 changes: 8 additions & 8 deletions src/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,40 @@ function VegetationParameters(dataset, config, indices)
rootingdepth = ncread(
dataset,
config,
"vertical.vegetation_parameter_set.rootingdepth";
"vegetation_root__depth";
sel = indices,
defaults = 750.0,
type = Float,
)
kc = ncread(
dataset,
config,
"vertical.vegetation_parameter_set.kc";
"vegetation__crop_factor";
sel = indices,
defaults = 1.0,
type = Float,
)
if haskey(config.input.vertical.vegetation_parameter_set, "leaf_area_index")
if haskey(config.input, "vegetation__leaf-area_index")
storage_specific_leaf = ncread(
dataset,
config,
"vertical.vegetation_parameter_set.storage_specific_leaf";
"vegetation__specific-leaf_storage";
optional = false,
sel = indices,
type = Float,
)
storage_wood = ncread(
dataset,
config,
"vertical.vegetation_parameter_set.storage_wood";
"vegetation_woody-part__storage_capacity";
optional = false,
sel = indices,
type = Float,
)
kext = ncread(
dataset,
config,
"vertical.vegetation_parameter_set.kext";
"vegetation_canopy__light-extinction_coefficient";
optional = false,
sel = indices,
type = Float,
Expand All @@ -76,15 +76,15 @@ function VegetationParameters(dataset, config, indices)
canopygapfraction = ncread(
dataset,
config,
"vertical.vegetation_parameter_set.canopygapfraction";
"vegetation_canopy__gap_fraction";
sel = indices,
defaults = 0.1,
type = Float,
)
cmax = ncread(
dataset,
config,
"vertical.vegetation_parameter_set.cmax";
"vegetation_water__storage_capacity";
sel = indices,
defaults = 1.0,
type = Float,
Expand Down
5 changes: 5 additions & 0 deletions src/standard_name.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

const standard_name_map = Dict{String,String}(
"vegetation__leaf-area_index" => "vertical.vegetation_parameter_set.leaf_area_index",
"river_water__volume_inflow_rate"=> "lateral.river.boundary_conditions.inflow",
)
2 changes: 1 addition & 1 deletion src/vegetation/canopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function GashInterceptionModel(dataset, config, indices, vegetation_parameter_se
e_r = ncread(
dataset,
config,
"vertical.interception.parameters.e_r";
"vegetation_canopy_water__mean_evaporation-to-mean_precipitation_ratio";
sel = indices,
defaults = 0.1,
type = Float,
Expand Down
8 changes: 4 additions & 4 deletions test/run_sbm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ config.input.vertical.atmospheric_forcing.potential_evaporation = Dict(
"offset" => 1.50,
"netcdf" => Dict("variable" => Dict("name" => "pet")),
)
config.input.vertical.vegetation_parameter_set.leaf_area_index =
config.input["vegetation__leaf-area_index"] =
Dict("scale" => 1.6, "netcdf" => Dict("variable" => Dict("name" => "LAI")))

model = Wflow.initialize_sbm_model(config)
Expand All @@ -208,10 +208,10 @@ tomlpath = joinpath(@__DIR__, "sbm_config.toml")
config = Wflow.Config(tomlpath)

config.input.cyclic = [
"vertical.vegetation_parameter_set.leaf_area_index",
"lateral.river.boundary_conditions.inflow",
"vegetation__leaf-area_index",
"river_water__volume_inflow_rate",
]
Dict(config.input.lateral.river)["boundary_conditions"] = Dict("inflow" => "inflow")
config.input.river_water__volume_inflow_rate = "inflow"

model = Wflow.initialize_sbm_model(config)
Wflow.run_timestep!(model)
Expand Down
19 changes: 8 additions & 11 deletions test/sbm_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ soil_water_sat-zone_bottom__max_leakage_volume_flux = "MaxLeakage"
"soil_root~wet__sigmoid_function_shape_parameter" = "rootdistpar"
soil__thickness = "SoilThickness"

vegetation_canopy_water__mean_evaporation-to-mean_precipitation_ratio = "EoverR"
vegetation__leaf-area_index = "LAI"
vegetation_canopy__light-extinction_coefficient = "Kext"
vegetation__specific-leaf_storage = "Sl"
vegetation_woody-part__storage_capacity = "Swood"
vegetation_root__depth = "RootingDepth"

# specify the internal IDs of the parameters which vary over time
# the external name mapping needs to be below together with the other mappings
forcing = [
Expand All @@ -83,21 +90,11 @@ forcing = [
"vertical.atmospheric_forcing.potential_evaporation",
]

cyclic = ["vertical.vegetation_parameter_set.leaf_area_index"]

[input.vertical.vegetation_parameter_set]
leaf_area_index = "LAI"
kext = "Kext"
storage_specific_leaf = "Sl"
storage_wood = "Swood"
rootingdepth = "RootingDepth"
cyclic = ["vegetation__leaf-area_index"]

[input.vertical.runoff.parameters]
waterfrac = "WaterFrac"

[input.vertical.interception.parameters]
e_r = "EoverR"

[input.vertical.atmospheric_forcing]
potential_evaporation = "pet"
precipitation = "precip"
Expand Down
45 changes: 20 additions & 25 deletions test/sbm_gw.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ atmosphere_air__snowfall_temperature_interval = "TTI"
snowpack__melting_temperature_threshold = "TTM"
snowpack__degree-day_coefficient = "Cfmax"

soil_water__brooks-corey_epsilon_parameter = "c"
soil_surface_water__infiltration_reduction_parameter = "cf_soil"
soil_water__vertical_saturated_hydraulic_conductivity_scale_parameter = "f"
"soil~compacted_surface_water__infiltration_capacity" = "InfiltCapPath"
"soil~non-compacted_surface_water__infiltration_capacity" = "InfiltCapSoil"
soil_water__residual_volume_fraction = "thetaR"
soil_water__saturated_volume_fraction = "thetaS"
soil_water_sat-zone_bottom__max_leakage_volume_flux = "MaxLeakage"
"soil~compacted__area_fraction" = "PathFrac"
"soil_root~wet__sigmoid_function_shape_parameter" = "rootdistpar"
soil__thickness = "SoilThickness"

vegetation_canopy_water__mean_evaporation-to-mean_precipitation_ratio = "EoverR"
vegetation__leaf-area_index = "LAI"
vegetation_canopy__light-extinction_coefficient = "Kext"
vegetation__specific-leaf_storage = "Sl"
vegetation_woody-part__storage_capacity = "Swood"
vegetation_root__depth = "RootingDepth"

# specify the internal IDs of the parameters which vary over time
# the external name mapping needs to be below together with the other mappings
forcing = [
Expand All @@ -66,40 +85,16 @@ forcing = [
"vertical.atmospheric_forcing.potential_evaporation",
]

cyclic = ["vertical.vegetation_parameter_set.leaf_area_index"]
cyclic = ["vegetation__leaf-area_index"]

[input.vertical.atmospheric_forcing]
potential_evaporation = "pet"
precipitation = "precip"
temperature = "temp"

[input.vertical.vegetation_parameter_set]
leaf_area_index = "LAI"
kext = "Kext"
storage_specific_leaf = "Sl"
storage_wood = "Swood"
rootingdepth = "RootingDepth"

[input.vertical.runoff.parameters]
waterfrac = "WaterFrac"

[input.vertical.soil.parameters]
c = "c"
cf_soil = "cf_soil"
cfmax = "Cfmax"
e_r = "EoverR"
f = "f"
infiltcappath = "InfiltCapPath"
infiltcapsoil = "InfiltCapSoil"
kv_0 = "KsatVer"
maxleakage = "MaxLeakage"
pathfrac = "PathFrac"
rootdistpar = "rootdistpar"
rootingdepth = "RootingDepth"
soilthickness = "SoilThickness"
theta_r = "thetaR"
theta_s = "thetaS"

[input.lateral.river]
length = "wflow_riverlength"
mannings_n = "N_River"
Expand Down
13 changes: 5 additions & 8 deletions test/sbm_gwf_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,18 @@ soil_water__saturated_volume_fraction = "thetaS"
"soil~compacted__area_fraction" = "PathFrac"
soil__thickness = "soilthickness"

vegetation_canopy_water__mean_evaporation-to-mean_precipitation_ratio = "EoverR"
vegetation_root__depth = "rootingdepth"
vegetation_canopy__gap_fraction = "canopygapfraction"
vegetation_water__storage_capacity = "cmax"

# specify the internal IDs of the parameters which vary over time
# the external name mapping needs to be below together with the other mappings
forcing = [
"vertical.atmospheric_forcing.precipitation",
"vertical.atmospheric_forcing.potential_evaporation",
]

[input.vertical.vegetation_parameter_set]
rootingdepth = "rootingdepth"
canopygapfraction = "canopygapfraction"
cmax = "cmax"

[input.vertical.interception.parameters]
e_r = "EoverR"

[input.vertical.atmospheric_forcing]
potential_evaporation = "PET"
precipitation = "P"
Expand Down
20 changes: 8 additions & 12 deletions test/sbm_gwf_piave_demand_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,21 @@ soil_water__vertical_saturated_hydraulic_conductivity_factor = "kvfrac"
"vegetation_root__feddes_critial_pressure_head_h~3~high" = "h3_high"
"vegetation_root__feddes_critial_pressure_head_h~3~low" = "h3_low"
"vegetation_root__feddes_critial_pressure_head_h~4" = "h4"
vegetation_canopy_water__mean_evaporation-to-mean_precipitation_ratio = "EoverR"
vegetation__leaf-area_index = "LAI"
vegetation_canopy__light-extinction_coefficient = "Kext"
vegetation__specific-leaf_storage = "Sl"
vegetation_woody-part__storage_capacity = "Swood"
vegetation_root__depth = "RootingDepth"
vegetation__crop_factor = "crop_factor"

forcing = [
"vertical.atmospheric_forcing.precipitation",
"vertical.atmospheric_forcing.temperature",
"vertical.atmospheric_forcing.potential_evaporation",
]
cyclic = [
"vertical.vegetation_parameter_set.leaf_area_index",
"vegetation__leaf-area_index",
"vertical.demand.domestic.demand.demand_gross",
"vertical.demand.domestic.demand.demand_net",
"vertical.demand.industry.demand.demand_gross",
Expand Down Expand Up @@ -109,17 +116,6 @@ head = "head"
[input.vertical.glacier.variables]
glacier_store = "wflow_glacierstore"

[input.vertical.vegetation_parameter_set]
leaf_area_index = "LAI"
kext = "Kext"
storage_specific_leaf = "Sl"
storage_wood = "Swood"
rootingdepth = "RootingDepth"
kc = "crop_factor"

[input.vertical.interception.parameters]
e_r = "EoverR"

[input.vertical.atmospheric_forcing]
potential_evaporation = "pet"
precipitation = "precip"
Expand Down
20 changes: 8 additions & 12 deletions test/sbm_piave_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,21 @@ soil__thickness = "SoilThickness"
"vegetation_root__feddes_critial_pressure_head_h~3~high" = "h3_high"
"vegetation_root__feddes_critial_pressure_head_h~3~low" = "h3_low"
"vegetation_root__feddes_critial_pressure_head_h~4" = "h4"
vegetation_canopy_water__mean_evaporation-to-mean_precipitation_ratio = "EoverR"
vegetation__leaf-area_index = "LAI"
vegetation_canopy__light-extinction_coefficient = "Kext"
vegetation__specific-leaf_storage = "Sl"
vegetation_woody-part__storage_capacity = "Swood"
vegetation_root__depth = "RootingDepth"
vegetation__crop_factor = "crop_factor"

forcing = [
"vertical.atmospheric_forcing.precipitation",
"vertical.atmospheric_forcing.temperature",
"vertical.atmospheric_forcing.potential_evaporation",
]

cyclic = ["vertical.vegetation_parameter_set.leaf_area_index"]
cyclic = ["vegetation__leaf-area_index"]

[model]
type = "sbm"
Expand Down Expand Up @@ -90,17 +97,6 @@ glacier_store = "glacierstore"
[input.vertical.glacier.variables]
glacier_store = "wflow_glacierstore"

[input.vertical.vegetation_parameter_set]
leaf_area_index = "LAI"
kext = "Kext"
storage_specific_leaf = "Sl"
storage_wood = "Swood"
rootingdepth = "RootingDepth"
kc = "crop_factor"

[input.vertical.interception.parameters]
e_r = "EoverR"

[input.vertical.atmospheric_forcing]
potential_evaporation = "pet"
precipitation = "precip"
Expand Down
Loading

0 comments on commit 1256662

Please sign in to comment.