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 result

  • scenario_values (dict) –

    A dict of overwrites to parameter values. The structure is {parameter_label: {pop_identifier: dict o} where the overwrite o contains keys

    • t : np.array or list with year values

    • y : np.array or list with corresponding parameter values

    The pop_identifier is a single population name if the parameter_label corresponds to a Framework parameter or it should be a tuple/list (from_pop,to_pop) if the parameter_label corresponds to an interaction or transfer.

  • active (bool) – If running via Project.run_scenarios this flags whether to run the scenario

  • parsetname (str) – If running via Project.run_scenarios this identifies which parset to use from the project

  • interpolation (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

scenario_values

Store dictionary containing the overwrite values

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

active

Flag whether the scenario should be run via Project.run_scenarios

Methods

add

Add overwrite to scenario

copy

get_instructions

Get scenario instructions

get_parset

Return modified parset

get_progset

Get scenario progset

run

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 interaction

  • pop_name (str) – Population to overwrite values for. If the par_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:

None

get_instructions(progset, project)

Get scenario instructions

If the derived scenario class produces program instructions, return them here.

Parameters:

progset (ProgramSet) – Input ProgramSet

Return type:

ProgramInstructions

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 the ParameterSet 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) – A ParameterSet instance

  • project – A Project instance (required for simulation times and to identify function parameters)

Return type:

ParameterSet

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) – Input ProgramSet

Return type:

ProgramSet

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 instance

  • parset (ParameterSet) – Optionally a ParameterSet instance, otherwise will use self.parsetname

  • progset (ProgramSet) – Optionally a ProgramSet instance, otherwise will use self.progsetname

  • store_results (bool) – If True, the results will be copied into the project

Return type:

Result

Returns:

A Result object

scenario_values

Store dictionary containing the overwrite values