Completed
Push — master ( 02e3b3...783fd3 )
by
unknown
03:37
created

scenario_builder.heatload_scenario_calculator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 193
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 69
dl 0
loc 193
rs 10
c 0
b 0
f 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A get_industry_heating_hotwater_scenario() 0 37 1
A get_CTS_heatload_scenario() 0 38 1
A get_industry_CTS_process_heat_scenario() 0 34 1
A get_household_heatload_by_NUTS3_scenario() 0 26 1
A get_combined_heatload_for_region_scenario() 0 40 3
1
from disaggregator import data, spatial
2
from reegis import geometries as geo, config as cfg
3
import pandas as pd
4
import os
5
6
def get_household_heatload_by_NUTS3_scenario(
7
    m_type,  weight_by_income=True
8
):
9
10
    """
11
    Parameters
12
    ----------
13
    region_pick : list
14
        Selected regions in NUTS-3 format
15
    m_type: int
16
        1 = Status Quo, 2 = Conventional modernisation, 3 = Future modernisation
17
    weight_by_income : bool
18
        Choose whether heat demand shall be weighted by household income
19
20
    Returns: pd.DataFrame
21
        Dataframe containing yearly household load for selection
22
    -------
23
    """
24
    # Abweichungen in den Jahresmengen bei bottom-up
25
    qdem_temp= spatial.disagg_households_heatload_DB_scenario(
26
        m_type, weight_by_income=weight_by_income
27
    )
28
29
    qdem = qdem_temp.sum(axis=1)
30
31
    return qdem
32
33
34
def get_CTS_heatload_scenario(region_pick, efficiency_gain=0.5):
35
    """
36
    Parameters
37
    ----------
38
    region_pick : list
39
        Selected regions in NUTS-3 format
40
    efficiency_gain: float
41
        Reduction factor for heatload due to increased CTS building efficiency
42
        (0.99 equals 99% reduction, 0% equals no reduction)
43
44
    Returns: pd.DataFrame
45
        Dataframe containing yearly heat CTS heat consumption by NUTS-3 region
46
    -------
47
    """
48
49
    # Define year of interest
50
    data.cfg["base_year"] = 2015
51
    # Get gas consumption of defined year and divide by gas-share in end energy use for heating
52
    heatload_hh = data.gas_consumption_HH().sum() / 0.47
53
    # Multiply with CTS heatload share, Assumption: Share is constant because heatload mainly depends on wheather
54
    heatload_CTS_2015 = 0.37 * heatload_hh  # Verhältnis aus dem Jahr 2017
55
    # Assumption: Heatload is reduced equally for all regions
56
    heatload_CTS = heatload_CTS_2015 * (1-efficiency_gain)
57
    # Calculate CTS gas consumption by economic branch and NUTS3-region
58
    gc_CTS = spatial.disagg_CTS_industry(
59
        sector="CTS", source="gas", use_nuts3code=True
60
    )
61
    # Sum up the gas consumption per NUTS3-region
62
    sum_gas_CTS = gc_CTS.sum().sum()
63
    # Calculate scaling factor
64
    inc_fac = heatload_CTS / sum_gas_CTS
65
    # Calculate CTS heatload: Assumption: Heatload correlates strongly with gas consumption
66
    gc_CTS_new = gc_CTS.multiply(inc_fac)
67
    # Select heatload of NUTS3-regions of interest
68
    gc_CTS_combined = gc_CTS_new.sum()
69
    df = gc_CTS_combined[region_pick]
70
71
    return df
72
73
74
def get_industry_heating_hotwater_scenario(region_pick, efficiency_gain=0.5):
75
    """
76
    Parameters
77
    ----------
78
    region_pick : list
79
        Selected regions in NUTS-3 format
80
    efficiency_gain: float
81
        Reduction factor for heatload due to increased CTS building efficiency
82
        (0.99 equals 99% reduction, 0% equals no reduction)
83
84
    Returns: pd.DataFrame
85
        Dataframe containing yearly industry heat consumption by NUTS-3 region
86
    -------
87
    """
88
89
    # Define year of interest
90
    data.cfg["base_year"] = 2015
91
    # Get gas consumption of defined year and divide by gas-share in end energy use for heating
92
    heatload_hh = data.gas_consumption_HH().sum() / 0.47
93
    # Multiply with industries heatload share, Assumption: Share is constant because heatload mainly depends on wheather
94
    heatload_industry_2015 = 0.089 * heatload_hh  # Verhältnis aus dem Jahr 2017
95
    heatload_industry = heatload_industry_2015 * (1-efficiency_gain)
96
    # Calculate industry gas consumption by economic branch and NUTS3-region
97
    gc_industry = spatial.disagg_CTS_industry(
98
        sector="industry", source="gas", use_nuts3code=True
99
    )
100
    # Sum up the gas consumption per NUTS3-region
101
    sum_gas_industry = gc_industry.sum().sum()
102
    # Calculate scaling factor
103
    inc_fac = heatload_industry / sum_gas_industry
104
    # Calculate indsutries heatload: Assumption: Heatload correlates strongly with gas consumption
105
    gc_industry_new = gc_industry.multiply(inc_fac)
106
    gc_industry_combined = gc_industry_new.sum()
107
    # Select heatload of NUTS3-regions of interest
108
    df = gc_industry_combined[region_pick]
109
110
    return df
111
112
113
def get_industry_CTS_process_heat_scenario(region_pick, efficiency_gain=0.2):
114
    """
115
    Parameters
116
    ----------
117
    region_pick : list
118
        Selected regions in NUTS-3 format
119
    efficiency_gain: float
120
        Reduction factor for heatload due to increased CTS building efficiency
121
        (0.99 equals 99% reduction, 0% equals no reduction)
122
123
    Returns: pd.DataFrame
124
        Dataframe containing yearly industry heat consumption by NUTS-3 region
125
    -------
126
    """
127
128
    # Select year
129
    data.cfg["base_year"] = 2015
130
    # Get industrial gas consumption by NUTS3
131
    gc_industry = spatial.disagg_CTS_industry(
132
        sector="industry", source="gas", use_nuts3code=True
133
    )
134
    sum_gas_industry = gc_industry.sum().sum()
135
    # Calculate factor of process heat consumption to gas consumption.
136
    # Assumption: Process heat demand correlates with gas demand
137
    process_heat_2015 = (515 + 42) * 1e6
138
    process_heat = process_heat_2015 * (1-efficiency_gain)
139
    inc_fac = process_heat / sum_gas_industry
140
    # Calculate process heat with factor
141
    ph_industry = gc_industry.multiply(inc_fac)
142
    ph_industry_combined = ph_industry.sum()
143
    # Select process heat consumptions for NUTS3-Regions of interest
144
    df = ph_industry_combined[region_pick]
145
146
    return df
147
148
149
def get_combined_heatload_for_region_scenario(name, region_pick=None, m_type=2 , eff_gain_CTS=0,
150
                                              eff_gain_ph=0, eff_gain_ihw=0):
151
    """
152
    Parameters
153
    ----------
154
    year : int
155
        Year of interest, so far only 2015 and 2016 are valid inputs
156
    name: string
157
        Name of scenario
158
    region_pick : list
159
        Selected regions in NUTS-3 format, if None function will return demand for all regions
160
161
    Returns: pd.DataFrame
162
        Dataframe containing aggregated yearly low temperature heat demand (households, CTS, industry) as well
163
        as high temperature heat demand (ProcessHeat) for selection
164
    -------
165
    """
166
    if region_pick is None:
167
        nuts3_index = data.database_shapes().index  # Select all NUTS3 Regions
168
169
    fn_pattern = "heat_consumption_by_nuts3_{name}.csv".format(name=name)
170
    fn = os.path.join(cfg.get("paths", "disaggregator"), fn_pattern)
171
172
    if not os.path.isfile(fn):
173
        tmp0 = get_household_heatload_by_NUTS3_scenario(
174
            m_type, weight_by_income=True
175
        )  # Nur bis 2016
176
        tmp1 = get_CTS_heatload_scenario(nuts3_index, eff_gain_CTS)  # 2015 - 2035 (projection)
0 ignored issues
show
introduced by
The variable nuts3_index does not seem to be defined in case region_pick is None on line 166 is False. Are you sure this can never be the case?
Loading history...
177
        tmp2 = get_industry_heating_hotwater_scenario(nuts3_index, eff_gain_ihw)
178
        tmp3 = get_industry_CTS_process_heat_scenario(nuts3_index, eff_gain_ph)
179
180
        df_heating = pd.concat([tmp0, tmp1, tmp2, tmp3], axis=1)
181
        df_heating.columns = ["Households", "CTS", "Industry", "ProcessHeat"]
182
        df_heating.to_csv(fn)
183
184
    else:
185
        df_heating = pd.read_csv(fn)
186
        df_heating.set_index("nuts3", drop=True, inplace=True)
187
188
    return df_heating
189
190
191
test = get_combined_heatload_for_region_scenario('test123', region_pick=None, m_type=2 , eff_gain_CTS=0,
192
                                              eff_gain_ph=0, eff_gain_ihw=0)
193