Skip to content

zero_infections

zero_human_infections(humans, keep_ids=None)

Sets the infection state of individuals to uninfected.

Parameters:

Name Type Description Default
humans List[dict]

All humans in a node

required
keep_ids list

ids of individuals that will be skipped, i.e. infection state is not changed

None
Source code in emodpy_malaria/serialization/zero_infections.py
def zero_human_infections(humans: List[dict], keep_ids: list = None):
    """
    Sets the infection state of individuals to uninfected.

    Args:
        humans: All humans in a node
        keep_ids: ids of individuals that will be skipped, i.e. infection state is not changed
    """
    if not keep_ids:
        keep_ids = []
    for person in humans:
        if person.suid.id not in keep_ids:
            if all(key in person for key in UNINFECTED_HUMAN):
                person.update(UNINFECTED_HUMAN)
            else:
                missing_keys = set(UNINFECTED_HUMAN).difference(set(person))
                raise KeyError("Template Uninfected Human and human of serialized population differ in the following "
                               "key(s): ", missing_keys)

zero_infection_path(in_out_paths, ser_date, ignore_nodeids=None, keep_humanids=None)

Loop over all .dtk files in ser_paths that have ser_date in the file name but not 'zero' and remove human and vector infections. '_zero' is appended to the output files.

Parameters:

Name Type Description Default
in_out_paths list

a list of lists of paths for directories to look into for .dtk files

required
ser_date list

List of timestamps

required
ignore_nodeids list

list of nodes that are ignored

None
keep_humanids list

infections are not removed from these humans

None
Source code in emodpy_malaria/serialization/zero_infections.py
def zero_infection_path(in_out_paths: list, ser_date: list, ignore_nodeids: list = None, keep_humanids: list = None):
    """
    Loop over all .dtk files in ser_paths that have ser_date in the file name but not 'zero' and remove human and
     vector infections. '_zero' is appended to the output files.

    Args:
        in_out_paths: a list of lists of paths for directories to look into for .dtk files
        ser_date:  List of timestamps
        ignore_nodeids: list of nodes that are ignored
        keep_humanids: infections are not removed from these humans

    """
    if not ignore_nodeids:
        ignore_nodeids = []
    if not keep_humanids:
        keep_humanids = []
    file_paths = _get_paths(in_out_paths, ser_date)
    for in_path, out_path in file_paths:
        zero_infections(in_path, out_path, ignore_nodeids, keep_humanids)

zero_infections(source_filename, dest_filename, ignore_nodes, keep_individuals, remove=False)

Removes/resets infections from humans and vectors.

Parameters:

Name Type Description Default
source_filename str

input file

required
dest_filename str

output file

required
ignore_nodes List[int]

list of node ids. These nodes are skipped.

required
keep_individuals List[int]

Ids of individuals. These individuals are skipped.

required
remove bool

If true infections are removed from vectors, if false infections are reset.

False

Returns:

Type Description
None

None

Source code in emodpy_malaria/serialization/zero_infections.py
def zero_infections(source_filename: str, dest_filename: str, ignore_nodes: List[int], keep_individuals: List[int],
                    remove: bool = False) -> None:
    """
    Removes/resets infections from humans and vectors.

    Args:
        source_filename: input file
        dest_filename: output file
        ignore_nodes: list of node ids. These nodes are skipped.
        keep_individuals: Ids of individuals. These individuals are skipped.
        remove: If true infections are removed from vectors, if false infections are reset.

    Returns:
        None
    """
    print('Ignoring nodes {0}'.format(ignore_nodes))
    print('Keeping infections in humans {0}'.format(keep_individuals))
    print("Reading file: '{0}'".format(source_filename))

    ser_pop = SerPop.SerializedPopulation(source_filename)

    for index, node in enumerate(ser_pop.nodes):
        print('Reading node {0} with node_id: {1}'.format(index, node.externalId))
        if node.externalId not in ignore_nodes:
            print('Zeroing vector infections')
            zero_vector_infections(node.m_vectorpopulations, remove)
            print('Zeroing human infections')
            zero_human_infections(node.individualHumans, keep_individuals)
        else:
            print('Ignoring node {0}'.format(index))

    # create output path if it doesn't exist
    out_path = Path(dest_filename).parent
    out_path.mkdir(parents=True, exist_ok=True)
    ser_pop.write(dest_filename)

zero_vector_infections(vector_pop_list, remove=False)

Resets infections in vectors or removes infections from vectors.

Parameters:

Name Type Description Default
vector_pop_list list

list of vector population in a node.

required
remove bool

If True all infected vectors are removed from serialized population. If set to False (default) all vectors in the simulation are reset to state STATE_ADULT.

False

Returns: None

Source code in emodpy_malaria/serialization/zero_infections.py
def zero_vector_infections(vector_pop_list: list, remove: bool = False):
    """
    Resets infections in vectors or removes infections from vectors.

    Args:
        vector_pop_list: list of vector population in a node.
        remove: If True all infected vectors are removed from serialized population. If set to False (default) all
                vectors in the simulation are reset to state STATE_ADULT.
    Returns:
        None

    """
    for idx_vector_pop_list, vector_population in enumerate(vector_pop_list):
        # empty infections from all queues
        for queue in Infection_Queues:
            vec_population = vector_population[queue]["collection"]

            if remove:
                new_adult_queue_list = [cohort for cohort in vec_population if
                                        cohort.state != STATE_INFECTED and cohort.state != STATE_INFECTIOUS]
                vector_pop_list[idx_vector_pop_list][queue]["collection"] = new_adult_queue_list
            else:
                for cohort in vec_population:
                    assert (cohort['__class__'] == 'VectorCohortIndividual' or cohort['__class__'] == 'VectorCohort')
                    cohort.state = STATE_ADULT
                    cohort.progress = 0.0
                    cohort.m_pStrain = dtk.NullPtr()