예제 #1
0
def create_stgpr_version(path_to_config: str,
                         model_index_id: Optional[int] = None,
                         output_path: Optional[str] = None) -> int:
    """
    Creates a new ST-GPR version (and model version) and adds it to
    the database.

    Args:
        path_to_config: path to config CSV containing model parameters
        model_index_id: index of config parameters to use, if config contains
            multiple sets of model parameters
        output_path: where to save files

    Returns:
        Created ST-GPR version ID

    Raises:
        ValueError: for config validation errors
    """
    # Validate input.
    config_exists = os.path.isfile(path_to_config)
    config_is_csv = path_to_config.lower().endswith('.csv')
    if not config_exists or not config_is_csv:
        raise ValueError(
            f'{path_to_config} is not a valid path to a config CSV')

    with session_management.session_scope() as session:
        # Call library function to create ST-GPR version.
        return stgpr_version.create_stgpr_version(session, path_to_config,
                                                  model_index_id, output_path)
예제 #2
0
def get_parameters(stgpr_version_id: int) -> Dict[str, Any]:
    """
    Pulls parameters associated with an ST-GPR version ID.

    Args:
        stgpr_version_id: the ID with which to pull parameters

    Returns:
        Dictionary of parameters for an ST-GPR run

    Raises:
        ValueError: if stgpr_version_id is not in the database
    """
    with session_management.session_scope() as session:
        # Validate input.
        stgpr_version_validation.validate_stgpr_version_exists(
            stgpr_version_id, session)

        # Call library function to get parameters.
        return parameters.get_parameters(session, stgpr_version_id)
예제 #3
0
def get_custom_stage_1_estimates(stgpr_version_id: int) -> pd.DataFrame:
    """
    Pulls custom stage 1 data associated with an ST-GPR version ID.

    Args:
        stgpr_version_id: the ID with which to pull custom stage 1 estimates

    Returns:
        Dataframe of custom stage 1 estimates for an ST-GPR run or None if
        there are no custom stage 1 estimates for the given ST-GPR version ID

    Raises:
        ValueError: if stgpr_version_id is not in the database
    """
    with session_management.session_scope() as session:
        # Validate input.
        stgpr_version_validation.validate_stgpr_version_exists(
            stgpr_version_id, session)

        # Call library function to get parameters.
        return stage_1.get_custom_stage_1_estimates(session, stgpr_version_id)
예제 #4
0
def create_model_version(
        stgpr_version_id: int,
        decomp_step: str,
        gbd_round_id: int,
        modelable_entity_id: Optional[int] = None,
        covariate_id: Optional[int] = None,
        epi_model_version_id: Optional[int] = None,
        covariate_model_version_id: Optional[int] = None) -> int:
    """
    Creates a new ST-GPR model version and adds it to the database.

    Args:
        stgpr_version_id: the ST-GPR version ID to link to this model version
        decomp_step: the decomp step associated with this ST-GPR
        gbd_round_id: the ID of the GBD round associated with this ST-GPR model
        modelable_entity_id: the ME ID associated with this ST-GPR model
        covariate_id: the covariate ID associated with this ST-GPR model
        epi_model_version_id: the epi model version ID associated with this
            ST-GPR model
        covariate_model_version_id: the covariate model version ID associated
            with this ST-GPR model

    Returns:
        Created model version ID
    """
    with session_management.session_scope() as session:
        # Validate input.
        stgpr_version_validation.validate_stgpr_version_exists(
            stgpr_version_id, session)

        # Call library function to create model version.
        return model_version.create_model_version(session, stgpr_version_id,
                                                  decomp_step, gbd_round_id,
                                                  modelable_entity_id,
                                                  covariate_id,
                                                  epi_model_version_id,
                                                  covariate_model_version_id)