Source code for emodpy_measles.demographics.MeaslesDemographics
import emod_api.demographics.Demographics as Demog
from emod_api.demographics.Demographics import Demographics, Node
from emod_api.demographics import DemographicsTemplates as DT
[docs]class MeaslesDemographics(Demographics):
"""
This class is derived from emod_api.demographics' Demographics class so that we can set
certain defaults for Measles in construction. Keen observers will note thatt SetDefaultProperties
does not look like a measles-specific function. But as we add other disease types the
generatlizations and speicfics will become clearer. The architectural point is solid.
"""
def __init__(self, nodes, idref="Gridded world grump2.5arcmin", base_file=None ):
super().__init__( nodes, idref, base_file )
super().SetDefaultProperties()
DT.InitSusceptConstant(self)
[docs]def from_template_node(lat=0, lon=0, pop=1e6, name=1, forced_id=1 ):
"""
This function creates a single-node MeaslesDemographics instance from the params you give it.
"""
new_nodes = [ Node(lat=lat, lon=lon, pop=pop, name=name, forced_id=forced_id) ]
return MeaslesDemographics(nodes=new_nodes )
[docs]def from_params(tot_pop=1e6, num_nodes=100, frac_rural=0.3, id_ref="from_params" ):
"""
Create a multi-node :py:class:`~emodpy_measles.demographics.MeaslesDemographics`
instance as a synthetic population based on a few parameters.
Args:
tot_pop: The total human population in the node.
num_nodes: The number of nodes to create.
frac_rural: The fraction of the population that is rural.
id_ref: Method describing how the latitude and longitude values are created
for each of the nodes in a simulation. "Gridded world" values use a grid
overlaid across the globe at some arcsec resolution. You may also generate
the grid using another tool or coordinate system. For more information,
see :ref:`emod-generic:demo-metadata`.
Returns:
A :py:class:`~emodpy_measles.demographics.Measles` instance.
"""
generic_demog = Demog.from_params(tot_pop, num_nodes, frac_rural, id_ref )
nodes = generic_demog.nodes
return MeaslesDemographics(nodes=nodes, idref=id_ref )
[docs]def from_pop_csv( pop_filename_in, site="No_Site", min_node_pop = 0 ):
"""
Create a multi-node :py:class:`~emodpy_malaria.demographics.MeaslesDemographics`
instance from a CSV file describing a population.
Args:
pop_filename_in: The path to the demographics file to ingest.
pop_filename_out: The path to the file to output.
site: A string to identify the country, village, or trial site.
Returns:
A :py:class:`~emodpy_malaria.demographics.MalariaDemographics` instance.
"""
generic_demog = Demog.from_csv( pop_filename_in )
nodes = []
for node in generic_demog.nodes:
if node.pop >= min_node_pop:
nodes.append( node )
else:
print( f"Purged node {node.id} coz not enough people ({node.pop} < {min_node_pop})." )
return MeaslesDemographics(nodes=nodes, idref=site)
[docs]def get_file_from_http( url ):
"""
Get data files from simple http server.
"""
import urllib.request as req
import tempfile
path = tempfile.NamedTemporaryFile()
path.close()
req.urlretrieve( url, path.name )
return path.name