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
andTimeDependentConnections
due to the difference in how they are formatted in the databook)
- Parameters:
framework – A
ProjectFramework
instancedata – A
ProjectData
instancename – Optionally specify the name of the parset
NamedItem constructor
A name must be a string
- Parameters:
name
Attributes
Return y-values in a dictionary
Optionally store an
Initialization
instance to explicitly set initial compartment sizesMethods
Return an iterator over all Parameters
- type pop:
Return y-values in a spreadsheet
copy
Retrieve parameter instance
Load calibration y-factors
Return a constant copy of the ParameterSet
Return a sampled copy of the ParameterSet
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 theParameterSet
- apply_initialization(pop, framework=None)[source]¶
- Parameters:
pop – An
at.Model.Population
instance containing compartment objects that require initializationframework – 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:
- 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:
- 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.
- 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 thatIf y-factors are present in the spreadsheet and not in the
ParameterSet
then they will be skippedIf y-factors are missing in the spreadsheet, the existing values will be maintained
- Parameters:
spreadsheet (
Spreadsheet
)- Return type:
- 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:
fname –
str
orPath
specifying location of file to save- Return type:
- 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