atomica.parameters.ParameterSet

class atomica.parameters.ParameterSet(framework, data, name='default')[source]

Bases: NamedItem

Collection of model parameters to run a simulation

A ParameterSet contains a collection of Parameters required to run the simulation. The parameters contain scale factors used for calibration, so often a project will contain multiple ParameterSets corresponding to different calibrations.

Although parameters are constructed from ProjectData, there are two key differences

  • The ParameterSet contains calibration scale factors

  • The ParameterSet expands transfers and interactions into per-population parameters so they are stored on an equal basis (whereas ProjectData segregates them in TimeDependentValuesEntry and TimeDependentConnections due to the difference in how they are formatted in the databook)

Parameters:
  • framework – A ProjectFramework instance

  • data – A ProjectData instance

  • name – Optionally specify the name of the parset

NamedItem constructor

A name must be a string

Parameters:

name

Attributes

y_factors

Return y-values in a dictionary

initialization

Optionally store an Initialization instance to explicitly set initial compartment sizes

Methods

all_pars

Return an iterator over all Parameters

apply_initialization

type pop:

calibration_spreadsheet

Return y-values in a spreadsheet

copy

get_par

Retrieve parameter instance

load_calibration

Load calibration y-factors

make_constant

Return a constant copy of the ParameterSet

sample

Return a sampled copy of the ParameterSet

save_calibration

Save y-values to file

set_initialization

all_pars()[source]

Return an iterator over all Parameters

This is useful because transfers and interaction Parameter instances are stored in nested dictionaries, so it’s not trivial to iterate over all of them.

Returns:

Generator over all Parameter instances contained in the ParameterSet

apply_initialization(pop, framework=None)[source]
Parameters:
  • pop – An at.Model.Population instance containing compartment objects that require initialization

  • framework – A Framework containing a specification of which compartments/characteristics are ordinarily used for initialization. If a framework is not provided, then the y-factors will not be validated.

Return type:

None

Returns:

calibration_spreadsheet()[source]

Return y-values in a spreadsheet

Note that the tabular structure contains missing entries for any interactions that don’t exist (e.g. due to missing population types) - these can be identified with pd.isna

Return type:

Spreadsheet

Returns:

Spreadsheet containing y-factors in tabular form

get_par(name, pop=None)[source]

Retrieve parameter instance

The parameter values for interactions and transfers are stored keyed by the source/from population. Thus, if the quantity name is an interaction or transfer, it is also necessary to specify the source population in order to return a Parameter instance.

Parameters:
  • name (str) – The code name of a parameter, interaction, or transfer

  • pop (str)

Return type:

Parameter

Returns:

A Parameter instance

initialization

Optionally store an Initialization instance to explicitly set initial compartment sizes

load_calibration(spreadsheet)[source]

Load calibration y-factors

This function reads a spreadsheet created by ParameterSet.save_calibration() and inserts the y-factors. It is permissive in that

  • If y-factors are present in the spreadsheet and not in the ParameterSet then they will be skipped

  • If y-factors are missing in the spreadsheet, the existing values will be maintained

Parameters:

spreadsheet (Spreadsheet)

Return type:

None

Returns:

make_constant(year)[source]

Return a constant copy of the ParameterSet

This function will return a copy of the ParameterSet where all parameter time series have been replaced with temporally static versions.

Parameters:

year (float) – Year to use for interpolation

Returns:

A copy of the ParameterSet with constant parameters

sample(constant=True)[source]

Return a sampled copy of the ParameterSet

Parameters:

constant – If True, time series will be perturbed by a single constant offset. If False, a different perturbation will be applied to each time specific value independently.

Returns:

A new ParameterSet with perturbed values

save_calibration(fname)[source]

Save y-values to file

Parameters:

fnamestr or Path specifying location of file to save

Return type:

None

property y_factors: dict

Return y-values in a dictionary

Note that any missing populations reflect population types. For example, the dictionary for a parameter in one population type will not contain any entries for populations that belong to another type

Returns:

Dictionary keyed by (par, pop) containing a dict of y-values