atomica.scenarios.ParameterScenario¶
- class atomica.scenarios.ParameterScenario(name=None, scenario_values=None, active=True, parsetname=None, interpolation='linear')[source]¶
Bases:
Scenario
Define and run parameter scenarios
This object stores overwrites to parameter values that are used to modify a
ParameterSet
instance before running a simulation.Example usage:
>>> scvalues = dict() >>> param = 'birth_transit' >>> scvalues[param] = dict() >>> scvalues[param]['Pop1'] = dict() >>> scvalues[param]['Pop1']['y'] = [3e6, 1e4, 1e4, 2e6] >>> scvalues[param]['Pop1']['t'] = [2003.,2004.,2014.,2015.] >>> pscenario = ParameterScenario(name="examplePS",scenario_values=scvalues)
- Parameters:
name (
str
) – The name of the scenario. This will also be used to name the resultscenario_values (
dict
) –A dict of overwrites to parameter values. The structure is
{parameter_label: {pop_identifier: dict o}
where the overwriteo
contains keyst
: np.array or list with year valuesy
: np.array or list with corresponding parameter values
The
pop_identifier
is a single population name if theparameter_label
corresponds to a Framework parameter or it should be a tuple/list(from_pop,to_pop)
if theparameter_label
corresponds to an interaction or transfer.active (
bool
) – If running viaProject.run_scenarios
this flags whether to run the scenarioparsetname (
str
) – If running viaProject.run_scenarios
this identifies which parset to use from the projectinterpolation (
str
) – The specified interpolation method will be used to interpolate scenario values onto simulation times. Common options are ‘linear’ (smoothly change) and ‘previous’ (stepped)
NamedItem constructor
A name must be a string
- Parameters:
name (
str
)
Attributes
Store dictionary containing the overwrite values
Stores the name of a supported interpolation method
Specify parset name when run via
Project.run_scenarios
Specify progset name when run via
Project.run_scenarios
Flag whether the scenario should be run via
Project.run_scenarios
Methods
Add overwrite to scenario
copy
Get scenario instructions
Return modified parset
Get scenario progset
Run scenario
- active¶
Flag whether the scenario should be run via
Project.run_scenarios
- add(par_name, pop_name, t, y)[source]¶
Add overwrite to scenario
This method adds a TimeSeries with parameter overwrite values to the ParameterSet
Example usage:
>>> pscenario = ParameterScenario(name="examplePS") >>> pscenario.add('rec_rate','Pop1',[2004.,2014],[3e6, 1e4]) >>> pscenario.add('aging',('Pop1','Pop2'),[2004.,2014],[0.05,0.06])
This can provide a more readable way to define a parameter scenario, without having to assemble a dict of the overwrites in advance.
- Parameters:
par_name (
str
) – Name of the parameter to overwrite. This can also be the code name of a transfer or interactionpop_name (
str
) – Population to overwrite values for. If thepar_name
is a transfer or interaction, this should be a tuple containing(from_pop,to_pop)
t – scalar, list, or array of times
y – scalar, list, or array of overwrite values
end_overwrite – If True, after the final overwrite, the parameter will revert to its baseline value
- Return type:
- get_instructions(progset, project)¶
Get scenario instructions
If the derived scenario class produces program instructions, return them here.
- Parameters:
progset (
ProgramSet
) – InputProgramSet
- Return type:
- Returns:
ProgramInstructions
instance, or None if no instructions (in which case, programs will not be used)
- get_parset(parset, project)[source]¶
Return modified parset
This method takes in a
ParameterSet
and modifies it by applying the overwrites present in the scenario. This can thus be used to return theParameterSet
for use in other simulations that are manually run, or to do things like perform a budget scenario simulation in conjunction with a parameter scenario.The returned
ParameterSet
will have been pre-interpolated onto the simulation times.- Parameters:
parset (
ParameterSet
) – AParameterSet
instanceproject – A
Project
instance (required for simulation times and to identify function parameters)
- Return type:
- Returns:
A new
ParameterSet
object
- get_progset(progset, project)¶
Get scenario progset
If the derived scenario class modifies the progset, return the modified version
- Parameters:
progset (
ProgramSet
) – InputProgramSet
- Return type:
- Returns:
Modified progset for use in the simulation
- interpolation¶
Stores the name of a supported interpolation method
- parsetname¶
Specify parset name when run via
Project.run_scenarios
- progsetname¶
Specify progset name when run via
Project.run_scenarios
- run(project, parset=None, progset=None, store_results=True)¶
Run scenario
- Parameters:
project – A
Project
instanceparset (
ParameterSet
) – Optionally aParameterSet
instance, otherwise will useself.parsetname
progset (
ProgramSet
) – Optionally aProgramSet
instance, otherwise will useself.progsetname
store_results (
bool
) – If True, the results will be copied into the project
- Return type:
- Returns:
A
Result
object
- scenario_values¶
Store dictionary containing the overwrite values