fpsim.base module

Base classes for loading parameters and for running simulations with FP model

class ParsObj(pars, **kwargs)[source]

Bases: FlexPretty

A class based around performing operations on a self.pars dict.

update_pars(pars=None, create=False, **kwargs)[source]

Update internal dict with new pars.

Parameters
  • pars (dict) – the parameters to update (if None, do nothing)

  • create (bool) – if create is False, then raise a KeyNotFoundError if the key does not already exist

  • kwargs (dict) – additional parameters

class BasePeople[source]

Bases: prettyobj

Class for all the people in the simulation.

Initialize essential attributes used for filtering

keys()[source]

Returns keys for all properties of the people object

property is_female

Boolean array of everyone female

property is_male

Boolean array of everyone male

property int_age

Return ages as an integer

property ceil_age

Rounds age up to the next highest integer

property int_age_clip

Return ages as integers, clipped to maximum allowable age for pregnancy

property n

Number of people alive

property inds

Alias to self._inds to prevent accidental overwrite & increase speed

property len_inds

Alias to len(self)

property len_people

Full length of People array, ignoring filtering

plot(fig_args=None, hist_args=None)[source]

Plot histograms of each quantity

filter(criteria=None, inds=None)[source]

Store indices to allow for easy filtering of the People object.

Parameters
  • criteria (array) – a boolean array for the filtering critria

  • inds (array) – alternatively, explicitly filter by these indices

Returns

A filtered People object, which works just like a normal People object except only operates on a subset of indices.

unfilter()[source]

An easy way of unfiltering the People object, returning the original.

binomial(prob, as_inds=False, as_filter=False)[source]

Return indices either by a single probability or by an array of probabilities. By default just return the boolean array, but can also return the indices, or the filtered People object.

Parameters
  • prob (float/array) – either a scalar probability, or an array of probabilities of the same length as People

  • as_inds (bool) – return as list of indices instead of a boolean array

  • as_filter (bool) – return as filter instead than boolean array

class BaseSim(pars, **kwargs)[source]

Bases: ParsObj

The BaseSim class handles the dynamics of the simulation.

year2ind(year)[source]
ind2year(ind)[source]
ind2calendar(ind)[source]
property npts

Count the number of points in timesteps between the starting year and the ending year.

property tvec

Create a time vector array at intervals of the timestep in years

property n
get_interventions(label=None, partial=False, as_inds=False)[source]

Find the matching intervention(s) by label, index, or type. If None, return all interventions. If the label provided is “summary”, then print a summary of the interventions (index, label, type).

Parameters
  • label (str, int, Intervention, list) – the label, index, or type of intervention to get; if a list, iterate over one of those types

  • partial (bool) – if true, return partial matches (e.g. ‘beta’ will match all beta interventions)

  • as_inds (bool) – if true, return matching indices instead of the actual interventions

get_intervention(label=None, partial=False, first=False, die=True)[source]

Like get_interventions(), find the matching intervention(s) by label, index, or type. If more than one intervention matches, return the last by default. If no label is provided, return the last intervention in the list.

Parameters
  • label (str, int, Intervention, list) – the label, index, or type of intervention to get; if a list, iterate over one of those types

  • partial (bool) – if true, return partial matches (e.g. ‘beta’ will match all beta interventions)

  • first (bool) – if true, return first matching intervention (otherwise, return last)

  • die (bool) – whether to raise an exception if no intervention is found

get_analyzers(label=None, partial=False, as_inds=False)[source]

Same as get_interventions(), but for analyzers.

get_analyzer(label=None, partial=False, first=False, die=True)[source]

Same as get_intervention(), but for analyzers.