Ejemplo n.º 1
0
def test_prevalence_birth_prevalence_initial_assignment(
        base_config, base_plugins, disease):
    healthy = BaseDiseaseState('healthy')

    data_funcs = {
        'prevalence': lambda _, __: 1,
        'birth_prevalence': lambda _, __: 0.5,
        'disability_weight': lambda _, __: 0
    }
    with_condition = DiseaseState('with_condition',
                                  get_data_functions=data_funcs)

    model = DiseaseModel(disease,
                         initial_state=healthy,
                         states=[healthy, with_condition])
    base_config.update(
        {
            'population': {
                'population_size': 1000,
                'age_start': 0,
                'age_end': 5
            }
        }, **metadata(__file__))
    simulation = InteractiveContext(components=[TestPopulation(), model],
                                    configuration=base_config,
                                    plugin_configuration=base_plugins)

    # prevalence should be used for assigning initial status at sim start
    assert np.isclose(get_test_prevalence(simulation, "with_condition"), 1)

    # birth prevalence should be used for assigning initial status to newly-borns on time steps
    simulation._clock.step_forward()
    simulation.simulant_creator(1000,
                                population_configuration={
                                    'age_start': 0,
                                    'age_end': 0,
                                    'sim_state': 'time_step'
                                })
    assert np.isclose(get_test_prevalence(simulation, "with_condition"), 0.75,
                      0.01)

    # and prevalence should be used for ages not start = end = 0
    simulation._clock.step_forward()
    simulation.simulant_creator(1000,
                                population_configuration={
                                    'age_start': 0,
                                    'age_end': 5,
                                    'sim_state': 'time_step'
                                })
    assert np.isclose(get_test_prevalence(simulation, "with_condition"), 0.83,
                      0.01)
Ejemplo n.º 2
0
def test_prevalence_single_state_with_migration(base_config, base_plugins,
                                                disease, base_data,
                                                test_prevalence_level):
    """
    Test the prevalence for the single state over newly migrated population.
    Start with the initial population, check the prevalence for initial assignment.
    Then add new simulants and check whether the initial status is
    properly assigned to new simulants based on the prevalence data and pre-existing simulants status

    """
    year_start = base_config.time.start.year
    year_end = base_config.time.end.year

    healthy = BaseDiseaseState('healthy')
    data_funcs = base_data(test_prevalence_level)
    data_funcs.update({'disability_weight': lambda _, __: 0.0})
    sick = DiseaseState('sick', get_data_functions=data_funcs)
    model = DiseaseModel(disease,
                         initial_state=healthy,
                         states=[healthy, sick])
    base_config.update({'population': {
        'population_size': 50000
    }}, **metadata(__file__))
    simulation = InteractiveContext(components=[TestPopulation(), model],
                                    configuration=base_config,
                                    plugin_configuration=base_plugins)
    error_message = "initial status of simulants should be matched to the prevalence data."
    assert np.isclose(get_test_prevalence(simulation, 'sick'),
                      test_prevalence_level, 0.01), error_message
    simulation._clock.step_forward()
    assert np.isclose(get_test_prevalence(simulation, 'sick'),
                      test_prevalence_level, .01), error_message
    simulation.simulant_creator(50000,
                                population_configuration={
                                    'age_start': 0,
                                    'age_end': 5,
                                    'sim_state': 'time_step'
                                })
    assert np.isclose(get_test_prevalence(simulation, 'sick'),
                      test_prevalence_level, .01), error_message
    simulation._clock.step_forward()
    simulation.simulant_creator(50000,
                                population_configuration={
                                    'age_start': 0,
                                    'age_end': 5,
                                    'sim_state': 'time_step'
                                })
    assert np.isclose(get_test_prevalence(simulation, 'sick'),
                      test_prevalence_level, .01), error_message