Exemple #1
0
def df(mi, settings):
    alchemy = Alchemy(settings)
    d = DismodFiller(path=Path('temp.db'),
                     settings_configuration=settings,
                     measurement_inputs=mi,
                     grid_alchemy=alchemy,
                     parent_location_id=70,
                     sex_id=2)
    d.fill_for_parent_child()
    return d
Exemple #2
0
def main(args=None):
    """
    Creates a dismod database using the saved inputs and the file
    structure specified in the context.

    Then runs an optional set of commands on the database passed
    in the --commands argument.

    Also passes an optional argument --options as a dictionary to
    the dismod database to fill/modify the options table.
    """
    args = get_args(args=args)
    logging.basicConfig(level=LEVELS[args.loglevel])

    if args.test_dir:
        context = Context(model_version_id=args.model_version_id,
                          configure_application=False,
                          root_directory=args.test_dir)
    else:
        context = Context(model_version_id=args.model_version_id)

    inputs, alchemy, settings = context.read_inputs()

    # If we want to override the rate priors with posteriors from a previous
    # database, pass them in here.
    if args.prior_parent or args.prior_sex:
        if not (args.prior_parent and args.prior_sex):
            raise RuntimeError("Need to pass both prior parent and sex or neither.")
        child_prior = DismodExtractor(path=context.db_file(
            location_id=args.prior_parent,
            sex_id=args.prior_sex
        )).gather_draws_for_prior_grid(
            location_id=args.parent_location_id,
            sex_id=args.sex_id,
            rates=[r.rate for r in settings.rate]
        )
    else:
        child_prior = None

    df = DismodFiller(
        path=context.db_file(location_id=args.parent_location_id, sex_id=args.sex_id),
        settings_configuration=settings,
        measurement_inputs=inputs,
        grid_alchemy=alchemy,
        parent_location_id=args.parent_location_id,
        sex_id=args.sex_id,
        child_prior=child_prior
    )
    df.fill_for_parent_child(**args.options)
    run_dismod_commands(dm_file=df.path.absolute(), commands=args.commands)
Exemple #3
0
def fill_database(path: Union[str, Path], settings: SettingsConfig,
                  inputs: MeasurementInputs, alchemy: Alchemy,
                  parent_location_id: int, sex_id: int,
                  child_prior: Dict[str, Dict[str, np.ndarray]],
                  mulcov_prior: Dict[Tuple[str, str, str],
                                     _Prior], options: Dict[str, Any]) -> None:
    """
    Fill a DisMod database at the specified path with the inputs, model, and settings
    specified, for a specific parent and sex ID, with options to override the priors.
    """
    df = DismodFiller(
        path=path,
        settings_configuration=settings,
        measurement_inputs=inputs,
        grid_alchemy=alchemy,
        parent_location_id=parent_location_id,
        sex_id=sex_id,
        child_prior=child_prior,
        mulcov_prior=mulcov_prior,
    )
    df.fill_for_parent_child(**options)
Exemple #4
0
def test_format_rate_grid_for_ihme(mi):
    settings = load_settings(BASE_CASE)
    alchemy = Alchemy(settings)
    d = DismodFiller(
        path='none',
        settings_configuration=settings,
        measurement_inputs=mi,
        grid_alchemy=alchemy,
        parent_location_id=70,
        sex_id=2
    )
    grid = format_rate_grid_for_ihme(
        rates=d.parent_child_model['rate'],
        gbd_round_id=6,
        location_id=70,
        sex_id=2
    )
    assert all(grid.columns == ['location_id', 'year_id', 'age_group_id',
                                'sex_id', 'measure_id', 'mean', 'upper', 'lower'])