helper_interventions.py

exp_params_to_update(exp)

Configures the exp object by adding parameters for all user-specified interventions.

This function checks the list of interventions in the exp object and updates the object with the necessary parameters for each supported intervention. If no interventions are specified, a message is printed. If an invalid intervention is specified, a ValueError is raised.

Currently, the function supports the ccstep intervention and includes a placeholder for other potential interventions (e.g., smc).

Parameters:
  • exp (object) –

    An object representing the experiment, which should have an intervention_list attribute (a list of strings specifying interventions).

Returns:
  • object

    The updated exp object with added parameters for specified interventions.

Raises:
  • ValueError

    If an invalid intervention is specified in the intervention_list.

Source code in utility\helper_interventions.py
def exp_params_to_update(exp):
    """
    Configures the `exp` object by adding parameters for all user-specified interventions.

    This function checks the list of interventions in the `exp` object and updates the
    object with the necessary parameters for each supported intervention. If no
    interventions are specified, a message is printed. If an invalid intervention is
    specified, a `ValueError` is raised.

    Currently, the function supports the `ccstep` intervention and includes a placeholder
    for other potential interventions (e.g., `smc`).

    Args:
        exp (object): An object representing the experiment, which should have an
            `intervention_list` attribute (a list of strings specifying interventions).

    Returns:
        object: The updated `exp` object with added parameters for specified interventions.

    Raises:
        ValueError: If an invalid intervention is specified in the `intervention_list`.

    """

    # Note having unique levels of those two parameters is currently needed in the plotting scripts
    exp.cm_clinical = [x[0] for x in exp.case_management]
    exp.cm_severe = [x[1] for x in exp.case_management]

    exp.intervention_analyzer_columns = []
    if not exp.intervention_list or exp.intervention_list == []:
        print('No interventions specified')
    else:
        if 'ccstep' in exp.intervention_list:
            print('Adding parameters for ccstep')
            exp = ccstep_params(exp)
        else:
            raise ValueError('Invalid intervention specified. Note that case management is automatically included.')

    # if 'smc' in exp.intervention_list:	
        #    print('Adding parameters for smc')	
        #    exp = smc_params(exp)
    return exp

intervention_params_to_check(exp)

Validates experiment configuration specific for the intervention recognized by the framework.

Parameters:
  • exp

    object The experiment configuration object. It must have an attribute intervention_list that contains a list of interventions to be checked.

Returns:
  • None

Source code in utility\helper_interventions.py
def intervention_params_to_check(exp):

    """
    Validates experiment configuration specific for the intervention recognized by the framework.

    Args:
        exp : object
            The experiment configuration object. It must have an attribute
            `intervention_list` that contains a list of interventions to be checked.

    Returns:
        None

    """

    if "ccstep" in exp.intervention_list:
        ccstep_input_check(exp)

scenario_df_to_update(exp, df)

Update a scenarios DataFrame to handle intervention-specific requirements. This function modifies the provided scenarios DataFrame (df) based on the attributes of the experiment (exp), specifically handling the ccstep intervention by removing invalid combinations and adding related columns.

Parameters:
  • exp (Experiment) –

    The experiment object containing the intervention list and related settings.

  • df (DataFrame) –

    The DataFrame containing generated scenario combinations.

Returns:
  • pandas.DataFrame: An updated DataFrame with modifications based on the ccstep intervention, including: - Removal of invalid combinations where target_output_values equals ccstep. - Addition of columns specific to the ccstep intervention.

Source code in utility\helper_interventions.py
def scenario_df_to_update(exp, df):
    """
    Update a scenarios DataFrame to handle intervention-specific requirements.
    This function modifies the provided scenarios DataFrame (`df`) based on
    the attributes of the experiment (`exp`), specifically handling the `ccstep`
    intervention by removing invalid combinations and adding related columns.

    Args:
        exp (Experiment): The experiment object containing the intervention list
                          and related settings.
        df (pandas.DataFrame): The DataFrame containing generated scenario combinations.

    Returns:
        pandas.DataFrame: An updated DataFrame with modifications based on the `ccstep`
                          intervention, including:
                          - Removal of invalid combinations where `target_output_values` equals `ccstep`.
                          - Addition of columns specific to the `ccstep` intervention.
    """

    if 'ccstep' in exp.intervention_list:
        # remove repeats were target_output_values equal ccstep generated by itertools.product
        df = df[df['target_output_values'] != df['ccstep']]
        if exp.cc_decreasing:
            df = df[df['target_output_values'] > df['ccstep']] # Decreasing
        else:
            df = df[df['target_output_values'] < df['ccstep']] # Increasing
        df = df.reset_index(drop=True)

        # Additional cc step specific columns
        df = ccstep_columns(exp, df)

    return df