Skip to content

Commit

Permalink
simplify get_alias
Browse files Browse the repository at this point in the history
  • Loading branch information
visr committed Feb 3, 2022
1 parent f0ce9d2 commit 3897e9d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
width `dw` as model type `sbm`.
- Renamed `h_bankfull` parameter to `bankfull_depth` for consistency between kinematic-wave
and local-inertial river routing. When using the old name under the
`[input.lateral.river]` section of the TOML file, it will still work but suggest to update
the name.
`[input.lateral.river]` section of the TOML file, it will work but it is suggested to
update the name.

### Added
- Additional log messages and log file as output, see also [Logging](@ref).
Expand Down
14 changes: 7 additions & 7 deletions src/flow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ function initialize_surfaceflow_river(

n_river = ncread(
nc,
config.input.lateral.river,
"n";
config.input,
"lateral.river.n";
sel = inds,
defaults = 0.036,
type = Float,
)
bankfull_depth = ncread(
nc,
config.input.lateral.river,
"bankfull_depth";
alias = "h_bankfull",
config.input,
"lateral.river.bankfull_depth";
alias = "lateral.river.h_bankfull",
sel = inds,
defaults = 1.0,
type = Float,
Expand All @@ -144,8 +144,8 @@ function initialize_surfaceflow_river(
end
sl = ncread(
nc,
config.input.lateral.river,
"slope";
config.input,
"lateral.river.slope";
optional = false,
sel = inds,
type = Float,
Expand Down
8 changes: 2 additions & 6 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,8 @@ end

"Get a value from the Config with either the key or an alias of the key."
function get_alias(config::Config, key, alias, default)
dict = Dict(config)
path = pathof(config)
alias_or_default = get(dict, alias, default)
a = get(dict, key, alias_or_default)
# if it is a Dict, wrap the result in Config
return a isa AbstractDict ? Config(a, path) : a
alias_or_default = param(config, alias, default)
return param(config, key, alias_or_default)
end

"Get a value from the Config with a key, throwing an error if it is not one of the options."
Expand Down
3 changes: 3 additions & 0 deletions test/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ Wflow.load_dynamic_input!(model)
@test length(writer.state_parameters) == 14
end

# get a default value if the parameter does not exist
@test Wflow.param(model, "lateral.doesnt_exist", -1) == -1

@testset "warm states" begin
@test Wflow.param(model, "lateral.river.reservoir.volume")[1] 3.2807224993363418e7
@test Wflow.param(model, "vertical.satwaterdepth")[9115] 477.13548089422125
Expand Down

0 comments on commit 3897e9d

Please sign in to comment.