Skip to content

risk_aversion

Classes:

Name Description
RiskAversionRecipe

Risk aversion option

dscim.menu.risk_aversion.RiskAversionRecipe

Bases: MainRecipe

Risk aversion option

Methods:

Name Description
ce_cc_calculation

Calculate certainty equivalent over consumption with climate change

ce_no_cc_calculation

Calculate certainty equivalent consumption without climate change

global_consumption_calculation

Calculate global consumption

global_damages_calculation

Aggregate damages to global level

Attributes:

Name Type Description
calculated_damages DataArray

Calculate damages (difference between CEs)

Source code in src/dscim/menu/risk_aversion.py
 6
 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
43
44
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
class RiskAversionRecipe(MainRecipe):
    """Risk aversion option"""

    NAME = "risk_aversion"
    __doc__ = MainRecipe.__doc__

    def ce_cc_calculation(self) -> xr.DataArray:
        """Calculate certainty equivalent over consumption with climate change

        Returns
        -------
             xr.DataArray
        """
        ce_array = self.risk_aversion_damages("cc").cc

        # for GWR options, take the CE over growth models
        if "gwr" in self.discounting_type:
            ce_array = self.ce(ce_array, dims=["ssp", "model"])

        return ce_array

    def ce_no_cc_calculation(self) -> xr.DataArray:
        """Calculate certainty equivalent consumption without climate change

        Returns
        -------
            xr.DataArray
        """
        ce_array = self.risk_aversion_damages("no_cc").no_cc

        if "gwr" in self.discounting_type:
            ce_array = self.ce(ce_array, dims=["ssp", "model"])

        return ce_array

    @property
    def calculated_damages(self) -> xr.DataArray:
        """Calculate damages (difference between CEs)"""
        return self.ce_no_cc - self.ce_cc

    def global_damages_calculation(self) -> pd.DataFrame:
        """Aggregate damages to global level

        Returns
        --------
            pd.DataFrame
        """

        dams_collapse = (self.calculated_damages * self.collapsed_pop).sum(dim="region")
        df = dams_collapse.to_dataframe("damages").reset_index()

        if "gwr" in self.discounting_type:
            df = df.assign(
                ssp=str(list(self.gdp.ssp.values)),
                model=str(list(self.gdp.model.values)),
            )

        return df

    def global_consumption_calculation(self, disc_type):
        """Calculate global consumption

        Returns
        -------
            xr.DataArray
        """

        if (disc_type == "constant") or ("ramsey" in disc_type):
            global_cons_no_cc = self.gdp.sum(dim=["region"])

        elif disc_type == "constant_model_collapsed":
            global_cons_no_cc = self.gdp.sum(dim=["region"]).mean(dim=["model"])

        elif "gwr" in disc_type:
            ce_cons = self.ce(self.gdppc, dims=["ssp", "model"])
            global_cons_no_cc = (ce_cons * self.collapsed_pop).sum(dim=["region"])

        # Convert to array in case xarray becames temperamental. This is a hack
        # that need to be changed
        if isinstance(global_cons_no_cc, xr.Dataset):
            global_cons_no_cc = global_cons_no_cc.to_array()

        global_cons_no_cc.name = f"global_cons_{disc_type}"

        return global_cons_no_cc

dscim.menu.risk_aversion.RiskAversionRecipe.calculated_damages property

calculated_damages

Calculate damages (difference between CEs)

dscim.menu.risk_aversion.RiskAversionRecipe.ce_cc_calculation

ce_cc_calculation()

Calculate certainty equivalent over consumption with climate change

Returns:

Type Description
xr.DataArray
Source code in src/dscim/menu/risk_aversion.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def ce_cc_calculation(self) -> xr.DataArray:
    """Calculate certainty equivalent over consumption with climate change

    Returns
    -------
         xr.DataArray
    """
    ce_array = self.risk_aversion_damages("cc").cc

    # for GWR options, take the CE over growth models
    if "gwr" in self.discounting_type:
        ce_array = self.ce(ce_array, dims=["ssp", "model"])

    return ce_array

dscim.menu.risk_aversion.RiskAversionRecipe.ce_no_cc_calculation

ce_no_cc_calculation()

Calculate certainty equivalent consumption without climate change

Returns:

Type Description
xr.DataArray
Source code in src/dscim/menu/risk_aversion.py
27
28
29
30
31
32
33
34
35
36
37
38
39
def ce_no_cc_calculation(self) -> xr.DataArray:
    """Calculate certainty equivalent consumption without climate change

    Returns
    -------
        xr.DataArray
    """
    ce_array = self.risk_aversion_damages("no_cc").no_cc

    if "gwr" in self.discounting_type:
        ce_array = self.ce(ce_array, dims=["ssp", "model"])

    return ce_array

dscim.menu.risk_aversion.RiskAversionRecipe.global_consumption_calculation

global_consumption_calculation(disc_type)

Calculate global consumption

Returns:

Type Description
xr.DataArray
Source code in src/dscim/menu/risk_aversion.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def global_consumption_calculation(self, disc_type):
    """Calculate global consumption

    Returns
    -------
        xr.DataArray
    """

    if (disc_type == "constant") or ("ramsey" in disc_type):
        global_cons_no_cc = self.gdp.sum(dim=["region"])

    elif disc_type == "constant_model_collapsed":
        global_cons_no_cc = self.gdp.sum(dim=["region"]).mean(dim=["model"])

    elif "gwr" in disc_type:
        ce_cons = self.ce(self.gdppc, dims=["ssp", "model"])
        global_cons_no_cc = (ce_cons * self.collapsed_pop).sum(dim=["region"])

    # Convert to array in case xarray becames temperamental. This is a hack
    # that need to be changed
    if isinstance(global_cons_no_cc, xr.Dataset):
        global_cons_no_cc = global_cons_no_cc.to_array()

    global_cons_no_cc.name = f"global_cons_{disc_type}"

    return global_cons_no_cc

dscim.menu.risk_aversion.RiskAversionRecipe.global_damages_calculation

global_damages_calculation()

Aggregate damages to global level

Returns:

Type Description
pd.DataFrame
Source code in src/dscim/menu/risk_aversion.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def global_damages_calculation(self) -> pd.DataFrame:
    """Aggregate damages to global level

    Returns
    --------
        pd.DataFrame
    """

    dams_collapse = (self.calculated_damages * self.collapsed_pop).sum(dim="region")
    df = dams_collapse.to_dataframe("damages").reset_index()

    if "gwr" in self.discounting_type:
        df = df.assign(
            ssp=str(list(self.gdp.ssp.values)),
            model=str(list(self.gdp.model.values)),
        )

    return df