Sorry in advance for length, but I wanted to be comprehensive and clear here!
You can only call update_param!
on an existing model parameter that was previously created by calling set_param!
.
In the original FUND model created with
m = MimiFUND.get_model()
the temp
parameter in components such as ocean
is never set with set_param!
, so there is no model parameter :temp
holding values that can be updated. The values are instead computed within the climatedynamics
component as the temp
variable and then connected to the temp
parameter in various components, including ocean
, with a call to connect_param!
.
There are several options for changing how temperature is calculated and passed to components within FUND depending on your goals as written below, and the Mimi API is here for reference and clarification.
If you want to remove the climatedynamics
component entirely, you can do so with delete_comp!
. You will then need to fix up any missing connections that used to flow throw climatedynamics
using new connections for dynamic computation, or set_param!
to force with external values.
If you want to edit the climatedynamics
component’s computation of temperature, you can create your own component from scratch or derived from the FUND climatedynamics
component and then use the replace_comp!
functionality. This could, for example, adapt FUND’s climatedynamics
:temp
variable to be computed in a different way, which would then automatically flow through the model.
If you want to leave the FUND components as they are but just force some components with your new Tempcor
values, you could break the connections between climatedynamics
and the various components like ocean
and then call set_param!
to set their values to your externally computed Tempcor
.
Generally, the easiest way to do this would be to first disconnect all the component parameters you want to use your external values with disconnect_param!
, so they no longer pull from climate dynamics
, and then use set_param!
create a new model parameter temp
with values Tempcor
, which at run time will set the value for parameter temp
in any component with a parameter of that name that is not yet connected.
m = MimiFUND.get_model()
disconnect_param(m, :ocean, :temp)
disconnect_param(m, :other_component, :temp)
set_param!(m, :temp, Tempcor)
However, in FUND temp
is a parameter in several components, not all of which use the same values (ie. in ocean
it only has the time
dimension but in others it has both time
and regions
), so Mimi cannot safely make the assumption that any component parameter :temp
that is not unconnected at build time can be set to the same model parameter.
Instead, we must call set_param!
for each component and be explicit about what we want the model parameter name to be using the longer set_param!
method set_param!(m, comp_name, param_name, unique_param_name, value)
, so your code would be
m = MimiFUND.get_model()
disconnect_param(m, :ocean, :temp) # optional, the line below will do this automatically
set_param!(m, :ocean, :temp, :ocean_temp, Tempcor)
This will break any connections ocean
's parameter temp
has to other variables, create a new model parameter with the name ocean_temp
(normally defaults to the temp
) with value Tempcor
, and then set ocean
's parameter :temp
to the have the values of the model parameter ocean_temp
, which in this case are Tempcor
.
Then if you want to update ocean
's temp
parameter in the future you would use
update_param!(m, :ocean_temp, new_values)