Beispiel #1
0
def test_integrand_grids(alchemy, default_ages, default_times):
    g = integrand_grids(alchemy=alchemy, integrands=['iota', 'prevalence'])
    np.testing.assert_array_equal(g['prevalence']['age'], default_ages)
    np.testing.assert_array_equal(g['prevalence']['time'], default_times)
    np.testing.assert_array_equal(g['iota']['age'],
                                  np.array([0., 5., 10., 50., 100.]))
    np.testing.assert_array_equal(
        g['iota']['time'],
        np.array([1990., 1995., 2000., 2005., 2010., 2015., 2016.]))
Beispiel #2
0
def test_get_prior_avgint_grid():

    settings = load_settings(BASE_CASE)
    alchemy = Alchemy(settings)

    rates = ['pini', 'iota', 'chi']

    grids = integrand_grids(alchemy=alchemy, integrands=rates)

    df = get_prior_avgint_grid(
        grids=grids,
        sexes=[1, 2],
        locations=[1]
    )
    assert type(df) == pd.DataFrame
    assert sorted(df['integrand_id'].unique()) == [0, 2, 7]
    assert all(df.location_id == 1)
Beispiel #3
0
def fill_avgint_with_priors_grid(inputs: MeasurementInputs, alchemy: Alchemy,
                                 settings: SettingsConfig,
                                 source_db_path: Union[str, Path],
                                 child_locations: List[int],
                                 child_sexes: List[int]):

    sourceDB = DismodIO(path=source_db_path)
    rates = [r.rate for r in settings.rate]
    grids = integrand_grids(alchemy=alchemy, integrands=rates)

    posterior_grid = get_prior_avgint_grid(grids=grids,
                                           sexes=child_sexes,
                                           locations=child_locations,
                                           midpoint=False)
    posterior_grid = inputs.add_covariates_to_data(df=posterior_grid)
    posterior_grid = prep_data_avgint(df=posterior_grid,
                                      node_df=sourceDB.node,
                                      covariate_df=sourceDB.covariate)
    posterior_grid.rename(columns={'sex_id': 'c_sex_id'}, inplace=True)
    sourceDB.avgint = posterior_grid
Beispiel #4
0
def fill_avgint_with_priors_grid(inputs: MeasurementInputs, alchemy: Alchemy,
                                 settings: SettingsConfig,
                                 source_db_path: Union[str, Path],
                                 child_locations: List[int],
                                 child_sexes: List[int]):
    """
    Fill the average integrand table with the grid that the priors are on.
    This is so that we can "predict" the prior for the next level of the cascade.

    Parameters
    ----------
    inputs
        An inputs object
    alchemy
        A grid alchemy object
    settings
        A settings configuration object
    source_db_path
        The path of the source database that has had a fit on it
    child_locations
        The child locations to predict for
    child_sexes
        The child sexes to predict for
    """

    sourceDB = DismodIO(path=source_db_path)
    rates = [r.rate for r in settings.rate]
    grids = integrand_grids(alchemy=alchemy, integrands=rates)

    posterior_grid = get_prior_avgint_grid(grids=grids,
                                           sexes=child_sexes,
                                           locations=child_locations,
                                           midpoint=False)
    posterior_grid = inputs.add_covariates_to_data(df=posterior_grid)
    posterior_grid = prep_data_avgint(df=posterior_grid,
                                      node_df=sourceDB.node,
                                      covariate_df=sourceDB.covariate)
    posterior_grid.rename(columns={'sex_id': 'c_sex_id'}, inplace=True)
    sourceDB.avgint = posterior_grid