Skip to content

Commit 200ad10

Browse files
committed
add named_Current_parameters
1 parent 4cebce8 commit 200ad10

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

docs/src/tutorial.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,10 @@ parameters(mtk)
409409

410410
## Integration with DynamicalSystems.jl
411411

412-
ConceptualClimateModels.jl integrates with [DynamicalSystems.jl](https://juliadynamics.github.io/DynamicalSystemsDocs.jl/dynamicalsystems/dev/). It provides a summary function [`dynamical_system_summary`](@ref), and also provides initial condition
413-
sampling to use when e.g., finding attractors and their basin fractions with
414-
`DynamicalSystems.basins_fractions`, via the function [`plausible_limits`](@ref).
412+
ConceptualClimateModels.jl integrates with [DynamicalSystems.jl](https://juliadynamics.github.io/DynamicalSystemsDocs.jl/dynamicalsystems/dev/).
413+
It provides some convenience functions that require ModelingToolkit.jl, such as
414+
[`dynamical_system_summary`](@ref), [`plausible_limits`](@ref) or
415+
[`named_current_parameters`](@ref), see below.
415416
Moreover, since all dynamical systems generated by ConceptualClimateModels.jl have
416417
symbolic bindings, one can use the symbolic variables in e.g., [interactive GUI exploration](https://juliadynamics.github.io/DynamicalSystemsDocs.jl/dynamicalsystems/dev/visualizations/#Interactive-or-animated-trajectory-evolution)
417418
or to access or set the parameters of the system.
@@ -421,6 +422,7 @@ plausible_limits
421422
plausible_ic_sampler
422423
plausible_grid
423424
dynamical_system_summary
425+
named_current_parameters
424426
```
425427

426428
## API Reference

src/dynamicalsystems.jl

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export processes_to_coupledodes
22
export dynamical_system_summary
33
export all_equations
4+
export named_current_parameters
45

56
DEFAULT_DIFFEQ = DynamicalSystemsBase.DEFAULT_DIFFEQ
67

@@ -28,7 +29,7 @@ or see the online [Tutorial](@ref).
2829
- `kw...`: all other keywords are propagated to `processes_to_mtkmodel`.
2930
"""
3031
function processes_to_coupledodes(proc, default = [];
31-
diffeq = DEFAULT_DIFFEQ, inplace = nothing, split::Bool = false, kwargs...
32+
diffeq = DEFAULT_DIFFEQ, inplace::Bool = false, split::Bool = false, kwargs...
3233
)
3334
sys = processes_to_mtkmodel(proc, default; kwargs...)
3435
ssys = structural_simplify(sys; split)
@@ -39,11 +40,10 @@ function processes_to_coupledodes(proc, default = [];
3940

4041
# The usage of `nothing` for the initial state assumes all state variables
4142
# and all parameters have been defined with a default value. This also means
42-
# that we can use `default_value` to
4343
if inplace
44-
prob = ODEProblem(ssys, nothing, (0.0, Inf))
44+
prob = ODEProblem(ssys, nothing, (0.0, Inf), nothing)
4545
else
46-
prob = ODEProblem{false}(ssys, nothing, (0.0, Inf); u0_constructor = x->SVector(x...))
46+
prob = ODEProblem{false}(ssys, nothing, (0.0, Inf), nothing; u0_constructor = x->SVector(x...))
4747
end
4848
ds = CoupledODEs(prob, diffeq)
4949
return ds
@@ -76,13 +76,20 @@ end
7676
keepfirstlines(str, n) = join(split(str, '\n')[1:n], '\n')
7777
skipfirstline(str, limit = 2) = split(str, '\n'; limit)[2]
7878

79-
function named_current_parameters(ebm)
80-
cp = current_parameters(ebm)
81-
pnames = parameters(referrenced_sciml_model(ebm))
82-
return [pn ~ p for (p, pn) in zip(cp, pnames)]
83-
end
84-
8579
function ProcessBasedModelling.all_equations(ds::DynamicalSystem)
8680
model = referrenced_sciml_model(ds)
8781
return all_equations(model)
8882
end
83+
84+
"""
85+
named_current_parameters(ds::DynamicalSystem)
86+
87+
Return a dictionary mapping parameters of `ds` (as `Symbol`s) to their values.
88+
"""
89+
function named_current_parameters(ds::DynamicalSystem)
90+
mtk = referrenced_sciml_model(ds)
91+
params_names = Symbol.(ModelingToolkit.parameters(mtk))
92+
params_values = current_parameter.(ds, params_names)
93+
params = Dict(params_names .=> params_values)
94+
return params
95+
end

src/statespace.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ end
2525
2626
Return a vector of limits (min, max) for each dynamic state variable in `ds`.
2727
Optionally provide the `idxs` of the variables to use as a vector of `Symbol`s
28-
or a vector of symbolic variables present in the referrenced MTK model of `ds`.
28+
for symbolic variables present in the referrenced MTK model of `ds`.
2929
3030
See also [`plausible_grid`](@ref), [`plausible_ic_sampler`](@ref).
3131
"""

0 commit comments

Comments
 (0)