emod_api.demographics.Demographics module

emod_api.demographics.Demographics.from_template_node(lat=0, lon=0, pop=1000000, name='Erewhon', forced_id=1)[source]

Create a single-node Demographics instance from a few params.

emod_api.demographics.Demographics.from_file(base_file)[source]

Create a Demographics instance from an existing demographics file.

emod_api.demographics.Demographics.get_node_ids_from_file(demographics_file)[source]

Get a list of node ids from a demographics file.

emod_api.demographics.Demographics.get_node_pops_from_params(tot_pop, num_nodes, frac_rural)[source]

Get a list of node populations from the params used to create a sparsely parameterized multi-node Demographics instance.

emod_api.demographics.Demographics.from_params(tot_pop=1000000, num_nodes=100, frac_rural=0.3, id_ref='from_params')[source]

Create an EMOD-compatible Demographics object with the population and number of nodes specified. frac_rural determines what fraction of the population gets put in the ‘rural’ nodes, which means all nodes besides node 1. Node 1 is the ‘urban’ node.

emod_api.demographics.Demographics.from_csv(input_file, res=0.008333333333333333, id_ref='from_csv')[source]

Create an EMOD-compatible Demographics instance from a csv population-by-node file.

emod_api.demographics.Demographics.from_pop_csv(pop_filename_in, pop_filename_out='spatial_gridded_pop_dir', site='No_Site')[source]
class emod_api.demographics.Demographics.Demographics(nodes, idref='Gridded world grump2.5arcmin', base_file=None)[source]

Bases: emod_api.demographics.BaseInputFile.BaseInputFile

This class is a container of data necessary to produce a EMOD-valid demographics input file. It can be initialized from an existing valid demographics.joson type file or from an array of valid Nodes.

apply_overlay(overlay_nodes: list)[source]
Parameters

overlay_nodes – Overlay list of nodes over existing nodes in demographics

Returns

to_dict()[source]
generate_file(name='demographics.json')[source]

Write the contents of the instance to an EMOD-compatible (JSON) file.

property node_ids

Return the list of (geographic) node ids.

property nodes
property node_count

Return the number of (geographic) nodes.

get_node(nodeid)[source]

Return the node idendified by nodeid. Search either name or actual id :param nodeid: :return:

SetIndividualAttributesWithFertMort(CrudeBirthRate=0.04, CrudeMortRate=0.02)[source]
AddIndividualPropertyAndHINT(Property: str, Values: List[str], InitialDistribution: List[float] = None, TransmissionMatrix: List[List[float]] = None, Transitions: List = None)[source]

Add Individual Properties, including an optional HINT configuration matrix.

Parameters
  • Property – property (if property already exists an exception is raised).

  • Values – property values.

  • InitialDistribution – initial distribution.

  • TransmissionMatrix – transmission matrix.

Returns

N/A/

AddAgeDependentTransmission(Age_Bin_Edges_In_Years=[0, 1, 2, - 1], TransmissionMatrix=[[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]])[source]

Set up age-based HINT. Since ages are a first class property of an agent, Age_Bin is a special case of HINT. We don’t specify a distribution, but we do specify the age bin edges, in units of years. So if Age_Bin_Edges_In_Years = [ 0, 10, 65, -1 ] it means you’ll have 3 age buckets: 0-10, 10-65, & 65+. Always ‘book-end’ with 0 and -1.

Parameters
  • Age_Bin_Edges_In_Years – array (or list) of floating point values, representing the age bucket bounderies.

  • TransmissionMatrix – 2-D array of floating point values, representing epi connectedness of the age buckets.

SetDefaultIndividualAttributes()[source]

NOTE: This is very Measles-ish. We might want to move into MeaslesDemographics

SetMinimalNodeAttributes()[source]
SetBirthRate(birth_rate)[source]

Set Default birth rate to birth_rate. Turn on Vital Dynamics and Births implicitly.

SetMortalityRate(mortality_rate, node_ids: List[int] = None)[source]

Set constant mortality rate to mort_rate. Turn on Enable_Natural_Mortality implicitly.

SetMortalityDistribution(distribution: emod_api.demographics.PropertiesAndAttributes.IndividualAttributes.MortalityDistribution = None, node_ids: List[int] = None)[source]

Set a default mortality distribution for all nodes or per node. Turn on Enable_Natural_Mortality implicitly. :param distribution: distribution :param node_ids: a list of node_ids

Returns

None

SetAgeDistribution(distribution: emod_api.demographics.PropertiesAndAttributes.IndividualAttributes.AgeDistribution, node_ids: List[int] = None)[source]

Set a default age distribution for all nodes or per node. Sets distribution type to COMPLEX implicitly. :param distribution: age distribution :param node_ids: a list of node_ids

Returns

None

SetDefaultNodeAttributes(birth=True)[source]

Set the default NodeAttributes (Altitude, Airport, Region, Seaport), optionally including birth, which is most important actually.

SetDefaultIndividualProperties()[source]

Initialize Individual Properties to empty.

SetDefaultProperties()[source]

Set a bunch of defaults (age structure, initial susceptibility and initial prevalencec) to sensible values.

SetDefaultPropertiesFertMort(CrudeBirthRate=0.04, CrudeMortRate=0.02)[source]

Set a bunch of defaults (birth rates, death rates, age structure, initial susceptibility and initial prevalencec) to sensible values.

SetDefaultFromTemplate(template, setter_fn=None)[source]

Add to the default IndividualAttributes using the input template (raw json) and set corresponding config values per the setter_fn. The template should always be constructed by a function in DemographicsTemplates. Eventually this function will be hidden and only accessed via separate application-specific API functions such as the ones below.

SetNodeDefaultFromTemplate(template, setter_fn)[source]

Add to the default NodeAttributes using the input template (raw json) and set corresponding config values per the setter_fn. The template should always be constructed by a function in DemographicsTemplates. Eventually this function will be hidden and only accessed via separate application-specific API functions such as the ones below.

SetEquilibriumAgeDistFromBirthAndMortRates(CrudeBirthRate=0.04, CrudeMortRate=0.02)[source]

Set the inital ages of the population to a sensible equilibrium profile based on the specified input birth and death rates. Note this does not set the fertility and mortality rates.

SetInitialAgeExponential(rate=0.0001068, description='')[source]

Set the initial age of the population to an exponential distribution with a specified rate. :param rate: rate :param description: description, why was this distribution chosen

SetInitialAgeLikeSubSaharanAfrica(description='')[source]

Set the initial age of the population to a overly simplified structure that sort of looks like sub-Saharan Africa. This uses the SetInitialAgeExponential. :param description: description, why was this age chosen?

SetOverdispersion(new_overdispersion_value, nodes=[])[source]

Set the overdispersion value for the specified nodes (all if empty).

SetConstantSusceptibility()[source]

Set the initial susceptibilty for each new individual to a constant value of 1.0.

SetInitPrevFromUniformDraw(min_init_prev, max_init_prev, description='')[source]

Set Initial Prevalence (one value per node) drawn from an uniform distribution. :param min_init_prev: minimal initial prevalence :param max_init_prevalence: maximal initial prevalence :param description: description, why were these parameters chosen?

SetConstantRisk(risk=1, description='')[source]

Set the initial risk for each new individual to the same value, defaults to full risk :param risk: risk :param description: description, why was this parameter chosen?

SetHeteroRiskUniformDist(min_risk=0, max_risk=1)[source]

Set the initial risk for each new individual to a value drawn from a uniform distribution.

SetHeteroRiskLognormalDist(mean=1.0, sigma=0)[source]

Set the initial risk for each new individual to a value drawn from a log-normal distribution.

SetHeteroRiskExponDist(mean=1.0)[source]

Set the initial risk for each new individual to a value drawn from an exponential distribution.

infer_natural_mortality(file_male, file_female, interval_fit=[1970, 1980], which_point='mid', predict_horizon=2050, csv_out=False, n=0, results_scale_factor=0.0027397260273972603)[source]

Calculate and set the expected natural mortality by age, sex, and year from data, predicting what it would have been without disease (usually HIV).

class emod_api.demographics.Demographics.DemographicsOverlay(nodes=None, meta_data: dict = None, individual_attributes=None, node_attributes=None, mortality_distribution=None)[source]

Bases: object

to_dict()[source]
to_file(file_name='demographics_overlay.json')[source]