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 cc_step 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
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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 `cc_step` 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`.

    """
    if not exp.intervention_list or exp.intervention_list == []:
        print('No interventions specified')
    else:
        if 'cc_step' in exp.intervention_list:
            print('Adding parameters for cc_step')
            exp = cc_step_params(exp)
        # if 'smc' in exp.intervention_list:
        #    print('Adding parameters for smc')
        #    exp = smc_params(exp)
        else:
            raise ValueError('Invalid intervention specified. Note that case management is automatically included.')

    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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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 "cc_step" in exp.intervention_list:
        from interventions.cc_step import cc_step_input_check
        cc_step_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 cc_step 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 cc_step intervention, including: - Removal of invalid combinations where output_target equals cc_change. - Addition of columns specific to the cc_step intervention.

Source code in utility\helper_interventions.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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 `cc_step`
    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 `cc_step`
                          intervention, including:
                          - Removal of invalid combinations where `output_target` equals `cc_change`.
                          - Addition of columns specific to the `cc_step` intervention.
    """

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

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

    return df