fpsim.base module

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

class fpsim.base.ParsObj(pars, **kwargs)

Bases: fpsim.base.FlexPretty

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

update_pars(pars=None, create=False, **kwargs)

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 fpsim.base.BasePeople

Bases: sciris.sc_utils.prettyobj

Class for all the people in the simulation.

keys()

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)

Plot histograms of each quantity

filter(criteria=None, inds=None)

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()

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

binomial(prob, as_inds=False, as_filter=False)

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 fpsim.base.BaseSim(pars, **kwargs)

Bases: fpsim.base.ParsObj

The BaseSim class handles the dynamics of the simulation.

year2ind(year)
ind2year(ind)
ind2calendar(ind)
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