-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete unused functions + clean code structure
- Loading branch information
Showing
9 changed files
with
297 additions
and
394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
""" | ||
get_models(m) | ||
Get the models of a dictionary of model mapping. | ||
# Arguments | ||
- `m::Dict{String,Any}`: a dictionary of model mapping | ||
Returns a vector of models | ||
# Examples | ||
```jldoctest mylabel | ||
julia> using PlantSimEngine; | ||
``` | ||
Import example models (can be found in the `examples` folder of the package, or in the `Examples` sub-modules): | ||
```jldoctest mylabel | ||
julia> using PlantSimEngine.Examples; | ||
``` | ||
If we just give a MultiScaleModel, we get its model as a one-element vector: | ||
```jldoctest mylabel | ||
julia> models = MultiScaleModel( \ | ||
model=ToyCAllocationModel(), \ | ||
mapping=[ \ | ||
:carbon_assimilation => ["Leaf"], \ | ||
:carbon_demand => ["Leaf", "Internode"], \ | ||
:carbon_allocation => ["Leaf", "Internode"] \ | ||
], \ | ||
); | ||
``` | ||
```jldoctest mylabel | ||
julia> PlantSimEngine.get_models(models) | ||
1-element Vector{ToyCAllocationModel}: | ||
ToyCAllocationModel() | ||
``` | ||
If we give a tuple of models, we get each model in a vector: | ||
```jldoctest mylabel | ||
julia> models2 = ( \ | ||
MultiScaleModel( \ | ||
model=ToyAssimModel(), \ | ||
mapping=[:soil_water_content => "Soil",], \ | ||
), \ | ||
ToyCDemandModel(optimal_biomass=10.0, development_duration=200.0), \ | ||
Status(aPPFD=1300.0, TT=10.0), \ | ||
); | ||
``` | ||
Notice that we provide "Soil", not ["Soil"] in the mapping because a single value is expected for the mapping here. | ||
```jldoctest mylabel | ||
julia> PlantSimEngine.get_models(models2) | ||
2-element Vector{AbstractModel}: | ||
ToyAssimModel{Float64}(0.2) | ||
ToyCDemandModel{Float64}(10.0, 200.0) | ||
``` | ||
""" | ||
get_models(m) = [model_(i) for i in m if !isa(i, Status)] | ||
|
||
|
||
# Same, for the status (if any provided): | ||
|
||
""" | ||
get_status(m) | ||
Get the status of a dictionary of model mapping. | ||
# Arguments | ||
- `m::Dict{String,Any}`: a dictionary of model mapping | ||
Returns a [`Status`](@ref) or `nothing`. | ||
# Examples | ||
See [`get_models`](@ref) for examples. | ||
""" | ||
function get_status(m) | ||
st = Status[i for i in m if isa(i, Status)] | ||
@assert length(st) <= 1 "Only one status can be provided for each organ type." | ||
length(st) == 0 && return nothing | ||
return first(st) | ||
end | ||
|
||
""" | ||
get_mapping(m) | ||
Get the mapping of a dictionary of model mapping. | ||
# Arguments | ||
- `m::Dict{String,Any}`: a dictionary of model mapping | ||
Returns a vector of pairs of symbols and strings or vectors of strings | ||
# Examples | ||
See [`get_models`](@ref) for examples. | ||
""" | ||
function get_mapping(m) | ||
mod_mapping = [mapping_(i) for i in m if isa(i, MultiScaleModel)] | ||
if length(mod_mapping) == 0 | ||
return Pair{Symbol,String}[] | ||
end | ||
return reduce(vcat, mod_mapping) |> unique | ||
end |
Oops, something went wrong.