コード例 #1
0
def test_set_location_defaults():
    """Testing that sp.set_location_defaults() works as expected"""
    sp.set_location_defaults('Senegal')
    assert sp.settings.country_location == 'Senegal', f"Check failed. sp.settings.country_location did not set to 'Senegal'."
    print(f"Check passed. sp.settings.country_location set to 'Senegal'.")
    sp.set_location_defaults('defaults')
    assert sp.settings.country_location == 'usa', f"Check failed. sp.settings.country_location did not set to 'usa'."
    print(f"Check passed. sp.settings.country_location set to 'usa'.")
コード例 #2
0
def test_Spokane():
    """Test that a Dakar population can be created with the basic SynthPops API."""
    sp.logger.info("Test that a Spokane population can be created with the basic SynthPops API.")
    pop = sp.make_population(**pars)
    age_distr = sp.read_age_bracket_distr(sp.datadir, country_location='usa', state_location='Washington', location='seattle_metro')
    assert len(age_distr) == 20, f'Check failed, len(age_distr): {len(age_distr)}'  # will remove if this passes in github actions test

    sp.set_location_defaults('defaults')  # Reset default values after this test is complete.
    return pop
コード例 #3
0
def test_Spokane():
    """Test that a Dakar population can be created with the basic SynthPops API."""
    sp.logger.info("Test that a Spokane population can be created with the basic SynthPops API.")

    pop = sp.Pop(**pars)
    loc_pars = pop.loc_pars
    age_dist = sp.read_age_bracket_distr(**loc_pars)
    assert len(age_dist) == 20, f'Check failed, len(age_dist): {len(age_dist)}'  # will remove if this passes in github actions test

    sp.set_location_defaults('defaults')  # Reset default values after this test is complete.
    return pop
コード例 #4
0
def pop_exploration():
    sp.logger.info(
        "Exploration of the Malawi population generation with default methods and missing data filled in with Senegal data"
    )
    sp.set_location_defaults(country_location="Senegal")
    pop = sp.Pop(**pars)
    print(pop.summarize())
    pop.plot_ages()
    pop.plot_enrollment_rates_by_age()
    sp.set_location_defaults()
    plt.show()
    sp.reset_default_settings()  # reset defaults
コード例 #5
0
def test_Malawi():
    """Test Malawi population constructed."""
    sp.logger.info(
        "Test that Malawi contact networks can be made. Not a guarantee that the population made matches age mixing patterns well yet."
    )

    # reset the default location to pull other data
    sp.set_location_defaults(country_location="Senegal")
    # make a basic population
    pop = sp.Pop(**pars)
    assert pop.country_location == 'Malawi', "population location information is not set to Malawi"
    sp.reset_default_settings()  # reset defaults
コード例 #6
0
ファイル: test_Dakar.py プロジェクト: MeWu-IDM/synthpops-1
def test_Dakar():
    """Test that a Dakar population can be created with the basic SynthPops API."""
    sp.logger.info("Test that a Dakar population can be created with the basic SynthPops API.")
    sp.set_nbrackets(18)  # Dakar age distributions available are up to 18 age brackets
    pop = sp.make_population(**pars)
    assert len(pop) == pars['n'], 'Check failed.'
    print('Check passed')

    sp.set_location_defaults('defaults')  # Reset default values after this test is complete.

    sp.logger.info("Test that the default country was reset.")
    assert sp.default_country == 'usa', f'Check failed: default_country is {sp.default_country}'
    print('2nd Check passed')

    return pop
コード例 #7
0
def pop_exploration():
    sp.logger.info(
        "Exploration of the Nepal population generation with default methods")
    pop = sp.Pop(**pars)
    print(pop.summarize())
    pop.plot_ages()
    pop.plot_household_sizes()
    pop.plot_enrollment_rates_by_age()
    pop.plot_contacts(layer='H',
                      density_or_frequency='density',
                      logcolors_flag=0,
                      title_prefix="Nepal Age Mixing")
    pop.plot_school_sizes(with_school_types=1)
    pop.plot_employment_rates_by_age()
    pop.plot_workplace_sizes()
    sp.set_location_defaults()
    plt.show()
コード例 #8
0
def pop_exploration():
    sp.logger.info(
        "Exploration of the Zimbabwe population generation with default methods and missing data filled in with Senegal data"
    )
    sp.set_location_defaults(country_location="Senegal")
    pop = sp.Pop(**pars)
    print(pop.summarize())
    pop.plot_ages()
    pop.plot_household_sizes()
    pop.plot_enrollment_rates_by_age()
    pop.plot_contacts(layer='H',
                      density_or_frequency='density',
                      logcolors_flag=0,
                      title_prefix="Zimbabwe Age Mixing")
    pop.plot_school_sizes(with_school_types=1)
    pop.plot_employment_rates_by_age()
    pop.plot_workplace_sizes()
    sp.reset_default_settings()  # reset defaults
    plt.show()
コード例 #9
0
def test_pakistan():
    """
    Testing that we get a warning message and that default information is still
    set to usa, however users can manually set their own default location to
    use for data gaps (we're not supplying all data).
    """
    sp.set_location_defaults('Pakistan')
    assert sp.settings.country_location == 'usa', 'Check failed. Defaults are not set as expected.'
    print('Defaults still set to default usa location information.')

    # this data does not actually exist yet
    new_defaults = dict(location=None,
                        state_location=None,
                        country_location='Pakistan')
    sp.reset_settings(new_defaults)
    assert sp.settings.country_location == 'Pakistan', 'Check failed. Default location information did not update to Pakistan.'
    print('Defaults update to Pakistan location information.')

    # reset the global parameters
    sp.reset_settings(sp.default_data['defaults'])
    assert sp.settings.country_location == 'usa', 'Reset failed.'
    print('Reset to original defaults.')