ebm 0.99.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ebm/__init__.py +0 -0
- ebm/__main__.py +152 -0
- ebm/__version__.py +1 -0
- ebm/cmd/__init__.py +0 -0
- ebm/cmd/calibrate.py +83 -0
- ebm/cmd/calibrate_excel_com_io.py +128 -0
- ebm/cmd/heating_systems_by_year.py +18 -0
- ebm/cmd/helpers.py +134 -0
- ebm/cmd/initialize.py +167 -0
- ebm/cmd/migrate.py +92 -0
- ebm/cmd/pipeline.py +227 -0
- ebm/cmd/prepare_main.py +174 -0
- ebm/cmd/result_handler.py +272 -0
- ebm/cmd/run_calculation.py +221 -0
- ebm/data/area.csv +92 -0
- ebm/data/area_new_residential_buildings.csv +3 -0
- ebm/data/area_per_person.csv +12 -0
- ebm/data/building_code_parameters.csv +9 -0
- ebm/data/energy_need_behaviour_factor.csv +6 -0
- ebm/data/energy_need_improvements.csv +7 -0
- ebm/data/energy_need_original_condition.csv +534 -0
- ebm/data/heating_system_efficiencies.csv +13 -0
- ebm/data/heating_system_forecast.csv +9 -0
- ebm/data/heating_system_initial_shares.csv +1113 -0
- ebm/data/holiday_home_energy_consumption.csv +24 -0
- ebm/data/holiday_home_stock.csv +25 -0
- ebm/data/improvement_building_upgrade.csv +9 -0
- ebm/data/new_buildings_residential.csv +32 -0
- ebm/data/population_forecast.csv +51 -0
- ebm/data/s_curve.csv +40 -0
- ebm/energy_consumption.py +307 -0
- ebm/extractors.py +115 -0
- ebm/heating_system_forecast.py +472 -0
- ebm/holiday_home_energy.py +341 -0
- ebm/migrations.py +224 -0
- ebm/model/__init__.py +0 -0
- ebm/model/area.py +403 -0
- ebm/model/bema.py +149 -0
- ebm/model/building_category.py +150 -0
- ebm/model/building_condition.py +78 -0
- ebm/model/calibrate_energy_requirements.py +84 -0
- ebm/model/calibrate_heating_systems.py +180 -0
- ebm/model/column_operations.py +157 -0
- ebm/model/construction.py +827 -0
- ebm/model/data_classes.py +223 -0
- ebm/model/database_manager.py +410 -0
- ebm/model/dataframemodels.py +115 -0
- ebm/model/defaults.py +30 -0
- ebm/model/energy_need.py +6 -0
- ebm/model/energy_need_filter.py +182 -0
- ebm/model/energy_purpose.py +115 -0
- ebm/model/energy_requirement.py +353 -0
- ebm/model/energy_use.py +202 -0
- ebm/model/enums.py +8 -0
- ebm/model/exceptions.py +4 -0
- ebm/model/file_handler.py +388 -0
- ebm/model/filter_scurve_params.py +83 -0
- ebm/model/filter_tek.py +152 -0
- ebm/model/heat_pump.py +53 -0
- ebm/model/heating_systems.py +20 -0
- ebm/model/heating_systems_parameter.py +17 -0
- ebm/model/heating_systems_projection.py +3 -0
- ebm/model/heating_systems_share.py +28 -0
- ebm/model/scurve.py +224 -0
- ebm/model/tek.py +1 -0
- ebm/s_curve.py +515 -0
- ebm/services/__init__.py +0 -0
- ebm/services/calibration_writer.py +262 -0
- ebm/services/console.py +106 -0
- ebm/services/excel_loader.py +66 -0
- ebm/services/files.py +38 -0
- ebm/services/spreadsheet.py +289 -0
- ebm/temp_calc.py +99 -0
- ebm/validators.py +565 -0
- ebm-0.99.3.dist-info/METADATA +217 -0
- ebm-0.99.3.dist-info/RECORD +80 -0
- ebm-0.99.3.dist-info/WHEEL +5 -0
- ebm-0.99.3.dist-info/entry_points.txt +3 -0
- ebm-0.99.3.dist-info/licenses/LICENSE +21 -0
- ebm-0.99.3.dist-info/top_level.txt +1 -0
ebm/s_curve.py
ADDED
@@ -0,0 +1,515 @@
|
|
1
|
+
import numpy as np
|
2
|
+
import pandas as pd
|
3
|
+
from pandas import Series
|
4
|
+
|
5
|
+
from ebm.model.area import building_condition_accumulated_scurves, building_condition_scurves
|
6
|
+
from ebm.model.data_classes import YearRange
|
7
|
+
|
8
|
+
|
9
|
+
def original_condition(s_curve_cumulative_demolition, s_curve_renovation,
|
10
|
+
s_curve_renovation_and_small_measure, s_curve_small_measure):
|
11
|
+
"""
|
12
|
+
Calculates buildings remaining as original condition by subtracting every other condition
|
13
|
+
|
14
|
+
Parameters
|
15
|
+
----------
|
16
|
+
s_curve_cumulative_demolition : pandas.Series
|
17
|
+
s_curve_renovation : pandas.Series
|
18
|
+
s_curve_renovation_and_small_measure : pandas.Series
|
19
|
+
s_curve_small_measure : pandas.Series
|
20
|
+
|
21
|
+
Returns
|
22
|
+
-------
|
23
|
+
pandas.Series
|
24
|
+
buildings remaining as original condition
|
25
|
+
"""
|
26
|
+
return (1.0 -
|
27
|
+
s_curve_cumulative_demolition -
|
28
|
+
s_curve_renovation -
|
29
|
+
s_curve_renovation_and_small_measure -
|
30
|
+
s_curve_small_measure).rename('s_curve_original_condition')
|
31
|
+
|
32
|
+
|
33
|
+
def small_measure(s_curve_renovation_and_small_measure: Series, s_curve_small_measure_total: Series) -> Series:
|
34
|
+
"""
|
35
|
+
Calculates the remaining small measure share by subtracting renovation and small measure values from
|
36
|
+
the total small measure curve.
|
37
|
+
|
38
|
+
Parameters
|
39
|
+
----------
|
40
|
+
s_curve_renovation_and_small_measure : Series
|
41
|
+
s_curve_small_measure_total : Series
|
42
|
+
|
43
|
+
Returns
|
44
|
+
-------
|
45
|
+
Series
|
46
|
+
s_curve_small_measure
|
47
|
+
|
48
|
+
Notes
|
49
|
+
-----
|
50
|
+
- This function currently does not implement logic to zero out values before the building year.
|
51
|
+
- Assumes both input Series are aligned on the index year.
|
52
|
+
"""
|
53
|
+
|
54
|
+
# ### SharesPerCondition calc_small_measure
|
55
|
+
# - ❌ sett til 0 før byggeår
|
56
|
+
# ```python
|
57
|
+
# construction_year = self.building_code_params[tek].building_year
|
58
|
+
# shares.loc[self.period_index <= construction_year] = 0
|
59
|
+
# ```
|
60
|
+
|
61
|
+
return (s_curve_small_measure_total - s_curve_renovation_and_small_measure).rename('small_measure')
|
62
|
+
|
63
|
+
|
64
|
+
def renovation_and_small_measure(s_curve_renovation: Series, s_curve_renovation_total: Series) -> Series:
|
65
|
+
"""
|
66
|
+
Calculates the remaining renovation_and_small_measure share by subtracting renovation
|
67
|
+
from the total renovation total curve.
|
68
|
+
|
69
|
+
Parameters
|
70
|
+
----------
|
71
|
+
s_curve_renovation : pandas.Series
|
72
|
+
A time series representing the S-curve of exclusive renovation condition.
|
73
|
+
|
74
|
+
s_curve_renovation_total : pandas.Series
|
75
|
+
A time series representing the total S-curve for the total renovation condition.
|
76
|
+
|
77
|
+
Returns
|
78
|
+
-------
|
79
|
+
pandas.Series
|
80
|
+
A time series representing the difference between the total and renovation-only S-curves.
|
81
|
+
Values before the building year should be set to 0 (not yet implemented).
|
82
|
+
|
83
|
+
Notes
|
84
|
+
-----
|
85
|
+
- This function currently does not implement logic to zero out values before the building year.
|
86
|
+
- Assumes both input Series are aligned on index year.
|
87
|
+
"""
|
88
|
+
# ### SharesPerCondition calc_renovation_and_small_measure
|
89
|
+
# - ❌ Sett til 0 før byggeår
|
90
|
+
|
91
|
+
return s_curve_renovation_total - s_curve_renovation
|
92
|
+
|
93
|
+
|
94
|
+
def trim_renovation_from_renovation_total(s_curve_renovation: Series,
|
95
|
+
s_curve_renovation_max: Series,
|
96
|
+
s_curve_renovation_total: Series,
|
97
|
+
scurve_total: Series) -> Series:
|
98
|
+
"""
|
99
|
+
Adjust the renovation S-curve by incorporating values from the total renovation curve
|
100
|
+
where the total share is less than the maximum renovation share.
|
101
|
+
|
102
|
+
This function identifies time points where the total S-curve (`scurve_total`) is less than
|
103
|
+
the maximum renovation S-curve (`s_curve_renovation_max`). For those points, it replaces
|
104
|
+
the corresponding values in `s_curve_renovation` with values from `s_curve_renovation_total`.
|
105
|
+
|
106
|
+
Parameters
|
107
|
+
----------
|
108
|
+
s_curve_renovation : pandas.Series
|
109
|
+
The original renovation S-curve to be adjusted.
|
110
|
+
|
111
|
+
s_curve_renovation_max : pandas.Series
|
112
|
+
The maximum allowed values for the renovation S-curve.
|
113
|
+
|
114
|
+
s_curve_renovation_total : pandas.Series
|
115
|
+
The total renovation S-curve including all measures.
|
116
|
+
|
117
|
+
scurve_total : pandas.Series
|
118
|
+
The actual total S-curve values to compare against the max renovation curve.
|
119
|
+
|
120
|
+
Returns
|
121
|
+
-------
|
122
|
+
pandas.Series
|
123
|
+
The adjusted renovation S-curve with values merged from the total renovation curve
|
124
|
+
where the total share is less than the maximum renovation share.
|
125
|
+
|
126
|
+
Notes
|
127
|
+
-----
|
128
|
+
- Assumes all input Series are aligned on the index year.
|
129
|
+
"""
|
130
|
+
|
131
|
+
adjusted_values = np.where(scurve_total < s_curve_renovation_max,
|
132
|
+
s_curve_renovation_total,
|
133
|
+
s_curve_renovation)
|
134
|
+
trimmed_renovation = pd.Series(adjusted_values, index=s_curve_renovation.index).rename('renovation')
|
135
|
+
return trimmed_renovation
|
136
|
+
|
137
|
+
|
138
|
+
def renovation_from_small_measure(s_curve_renovation_max: Series, s_curve_small_measure_total: Series) -> Series:
|
139
|
+
"""
|
140
|
+
Calculate the renovation S-curve by subtracting small measures from the max renovation curve.
|
141
|
+
|
142
|
+
Parameters
|
143
|
+
----------
|
144
|
+
s_curve_renovation_max : pandas.Series
|
145
|
+
The maximum yearly values for the renovation S-curve.
|
146
|
+
|
147
|
+
s_curve_small_measure_total : pandas.Series
|
148
|
+
The yearly total S-curve for small measures.
|
149
|
+
|
150
|
+
Returns
|
151
|
+
-------
|
152
|
+
pandas.Series
|
153
|
+
The resulting renovation S-curve with values clipped at 0
|
154
|
+
"""
|
155
|
+
# ## small_measure and renovation to scurve_small_measure_total, RN
|
156
|
+
# ## SharesPerCondition calc_renovation
|
157
|
+
#
|
158
|
+
# - ❌ Ser ut som det er edge case for byggeår.
|
159
|
+
# - ❌ Årene før byggeår må settes til 0 for scurve_renovation?
|
160
|
+
s_curve_renovation = (s_curve_renovation_max - s_curve_small_measure_total).clip(lower=0.0)
|
161
|
+
return s_curve_renovation.rename('s_curve_renovation')
|
162
|
+
|
163
|
+
|
164
|
+
def total(s_curve_renovation_total: Series, s_curve_small_measure_total: Series) -> Series:
|
165
|
+
"""
|
166
|
+
Calculates the yearly sum of renovation and small_measure
|
167
|
+
|
168
|
+
Parameters
|
169
|
+
----------
|
170
|
+
s_curve_renovation_total : pandas.Series
|
171
|
+
s_curve_small_measure_total : pandas.Series
|
172
|
+
|
173
|
+
Returns
|
174
|
+
-------
|
175
|
+
pandas.Series
|
176
|
+
yearly sum of renovation and small_measure
|
177
|
+
"""
|
178
|
+
|
179
|
+
return (s_curve_small_measure_total + s_curve_renovation_total).clip(lower=0.0).rename('s_curve_total')
|
180
|
+
|
181
|
+
|
182
|
+
def trim_max_value(s_curve_cumulative_small_measure: Series, s_curve_small_measure_max: Series) ->Series:
|
183
|
+
s_curve_cumulative_small_measure_max = s_curve_cumulative_small_measure.combine(s_curve_small_measure_max, min)
|
184
|
+
return s_curve_cumulative_small_measure_max.clip(0) # type: ignore
|
185
|
+
|
186
|
+
|
187
|
+
def small_measure_max(s_curve_cumulative_demolition: Series, s_curve_small_measure_never_share: Series):
|
188
|
+
"""
|
189
|
+
Calculates the maximum possible value for small_measure condition
|
190
|
+
|
191
|
+
Parameters
|
192
|
+
----------
|
193
|
+
s_curve_cumulative_demolition : pandas.Series
|
194
|
+
s_curve_small_measure_never_share : pandas.Series
|
195
|
+
|
196
|
+
Returns
|
197
|
+
-------
|
198
|
+
pandas.Series
|
199
|
+
Yearly maximum possible value for small_measure
|
200
|
+
"""
|
201
|
+
return 1.0 - s_curve_cumulative_demolition - s_curve_small_measure_never_share
|
202
|
+
|
203
|
+
|
204
|
+
def renovation_max(s_curve_cumulative_demolition: Series, s_curve_renovation_never_share: Series):
|
205
|
+
"""
|
206
|
+
Calculates the maximum possible value for renovation condition
|
207
|
+
|
208
|
+
Parameters
|
209
|
+
----------
|
210
|
+
s_curve_cumulative_demolition : pandas.Series
|
211
|
+
s_curve_renovation_never_share : pandas.Series
|
212
|
+
|
213
|
+
Returns
|
214
|
+
-------
|
215
|
+
pandas.Series
|
216
|
+
Yearly maximum possible value for renovation
|
217
|
+
"""
|
218
|
+
return 1.0 - s_curve_cumulative_demolition - s_curve_renovation_never_share
|
219
|
+
|
220
|
+
|
221
|
+
def cumulative_renovation(s_curves_with_building_code: Series, years: YearRange) -> Series:
|
222
|
+
"""
|
223
|
+
Return the yearly cumulative sum of renovation condition.
|
224
|
+
|
225
|
+
|
226
|
+
Parameters
|
227
|
+
----------
|
228
|
+
s_curves_with_building_code : pandas.Series
|
229
|
+
years : pandas.Series
|
230
|
+
|
231
|
+
Returns
|
232
|
+
-------
|
233
|
+
pandas.Series
|
234
|
+
cumulative sum of renovation
|
235
|
+
|
236
|
+
Notes
|
237
|
+
-----
|
238
|
+
NaN values are replaced by float 0.0
|
239
|
+
"""
|
240
|
+
return s_curves_with_building_code.renovation_acc.loc[(slice(None), slice(None), list(years.year_range))].fillna(0.0)
|
241
|
+
|
242
|
+
|
243
|
+
def cumulative_small_measure(s_curves_with_building_code: Series, years: YearRange) -> Series:
|
244
|
+
"""
|
245
|
+
Return the yearly cumulative sum of small_measure condition.
|
246
|
+
|
247
|
+
|
248
|
+
Parameters
|
249
|
+
----------
|
250
|
+
s_curves_with_building_code : pandas.Series
|
251
|
+
years : YearRange
|
252
|
+
|
253
|
+
Returns
|
254
|
+
-------
|
255
|
+
pandas.Series
|
256
|
+
cumulative sum of small_measure
|
257
|
+
|
258
|
+
Notes
|
259
|
+
-----
|
260
|
+
NaN values are replaced by float 0.0
|
261
|
+
"""
|
262
|
+
s_curve_cumulative_small_measure = s_curves_with_building_code.small_measure_acc.loc[(slice(None), slice(None), list(years.year_range))].fillna(0.0)
|
263
|
+
return s_curve_cumulative_small_measure
|
264
|
+
|
265
|
+
|
266
|
+
def transform_demolition(demolition: Series, years: YearRange) -> Series:
|
267
|
+
"""
|
268
|
+
Filter yearly demolition for years
|
269
|
+
Parameters
|
270
|
+
----------
|
271
|
+
demolition : pandas.Series
|
272
|
+
years : YearRange
|
273
|
+
|
274
|
+
Returns
|
275
|
+
-------
|
276
|
+
demolition for years
|
277
|
+
|
278
|
+
"""
|
279
|
+
return demolition.demolition.loc[(slice(None), slice(None), list(years.year_range))].fillna(0.0)
|
280
|
+
|
281
|
+
|
282
|
+
def transform_to_cumulative_demolition(cumulative_demolition: pd.DataFrame, years:YearRange) -> Series:
|
283
|
+
"""
|
284
|
+
Filter yearly cumulative demolition for years
|
285
|
+
Parameters
|
286
|
+
----------
|
287
|
+
cumulative_demolition : pandas.DataFrame
|
288
|
+
years : YearRange
|
289
|
+
|
290
|
+
Returns
|
291
|
+
-------
|
292
|
+
pandas.Series
|
293
|
+
cumulative demolition for years
|
294
|
+
|
295
|
+
"""
|
296
|
+
s_curve_cumulative_demolition = cumulative_demolition.demolition_acc.loc[
|
297
|
+
(slice(None), slice(None), list(years.year_range))].fillna(0.0)
|
298
|
+
return s_curve_cumulative_demolition
|
299
|
+
|
300
|
+
|
301
|
+
def scurve_parameters_to_never_share(s_curves: pd.DataFrame, scurve_parameters: pd.DataFrame) -> pd.DataFrame:
|
302
|
+
"""
|
303
|
+
Transform scurve_parameters with s_curve to never_share.
|
304
|
+
Parameters
|
305
|
+
----------
|
306
|
+
s_curves : pandas.DataFrame
|
307
|
+
scurve_parameters : pandas.DataFrame
|
308
|
+
|
309
|
+
Returns
|
310
|
+
-------
|
311
|
+
pandas.DataFrame
|
312
|
+
|
313
|
+
Notes
|
314
|
+
-----
|
315
|
+
Age is padded from -max age to 0
|
316
|
+
|
317
|
+
"""
|
318
|
+
max_age = s_curves.index.get_level_values(level='age').max()
|
319
|
+
df_never_share = pd.DataFrame(
|
320
|
+
# noinspection PyTypeChecker
|
321
|
+
[(row.building_category, idx, row.condition + '_never_share', row.never_share) for idx in range(-max_age, max_age + 1)
|
322
|
+
for row in
|
323
|
+
scurve_parameters.itertuples()],
|
324
|
+
columns=['building_category', 'age', 'building_condition', 'scurve']).sort_values(
|
325
|
+
['building_category', 'building_condition', 'age']).set_index(
|
326
|
+
['building_category', 'age', 'building_condition'])
|
327
|
+
return df_never_share
|
328
|
+
|
329
|
+
|
330
|
+
def scurve_parameters_to_scurve(scurve_parameters: pd.DataFrame) -> Series:
|
331
|
+
"""
|
332
|
+
Create scurve new dataframe from scurve_parameters using ebm.model.area.building_condition_scurves and
|
333
|
+
ebm.model.area.building_condition_accumulated_scurves
|
334
|
+
|
335
|
+
Each row represent a building_category and building_condition at a certain age.
|
336
|
+
|
337
|
+
Parameters
|
338
|
+
----------
|
339
|
+
scurve_parameters : pandas.DataFrame
|
340
|
+
|
341
|
+
Returns
|
342
|
+
-------
|
343
|
+
pandas.Series
|
344
|
+
"""
|
345
|
+
scurve_by_year = building_condition_scurves(scurve_parameters)
|
346
|
+
scurve_accumulated = building_condition_accumulated_scurves(scurve_parameters)
|
347
|
+
s_curves = pd.concat([scurve_by_year, scurve_accumulated])
|
348
|
+
|
349
|
+
return s_curves
|
350
|
+
|
351
|
+
|
352
|
+
def accumulate_demolition(s_curves_long: pd.DataFrame, years: YearRange) -> pd.DataFrame:
|
353
|
+
"""
|
354
|
+
Sets demolition in year 0 (2020) to 0.0 and sums up the yearly demolition using years
|
355
|
+
|
356
|
+
Parameters
|
357
|
+
----------
|
358
|
+
s_curves_long : pandas.DataFrame
|
359
|
+
years : YearRange
|
360
|
+
|
361
|
+
Returns
|
362
|
+
-------
|
363
|
+
pandas.DataFrame
|
364
|
+
"""
|
365
|
+
demolition_acc = s_curves_long
|
366
|
+
demolition_acc.loc[demolition_acc.query(f'year<={years.start}').index, 'demolition'] = 0.0
|
367
|
+
demolition_acc['demolition_acc'] = demolition_acc.groupby(by=['building_category', 'building_code'])[['demolition']].cumsum()[
|
368
|
+
['demolition']]
|
369
|
+
|
370
|
+
return demolition_acc
|
371
|
+
|
372
|
+
# noinspection PyTypeChecker
|
373
|
+
def merge_s_curves_and_building_code(s_curves: pd.DataFrame, df_never_share: pd.DataFrame, building_code_parameters: pd.DataFrame) -> pd.DataFrame:
|
374
|
+
"""
|
375
|
+
Cross merge s_curves and df_never_share with all building_code in building_code_parameters
|
376
|
+
|
377
|
+
Parameters
|
378
|
+
----------
|
379
|
+
s_curves : pandas.DataFrame
|
380
|
+
df_never_share : pandas.DataFrame
|
381
|
+
building_code_parameters : pandas.DataFrame
|
382
|
+
|
383
|
+
Returns
|
384
|
+
-------
|
385
|
+
pandas.DataFrame
|
386
|
+
"""
|
387
|
+
s_curves = pd.concat([s_curves, df_never_share])
|
388
|
+
|
389
|
+
s_curves_by_building_code = s_curves.reset_index().join(building_code_parameters, how='cross')
|
390
|
+
s_curves_by_building_code['year'] = s_curves_by_building_code['building_year'] + s_curves_by_building_code['age']
|
391
|
+
s_curves_long = s_curves_by_building_code.pivot(index=['building_category', 'building_code', 'year'],
|
392
|
+
columns=['building_condition'],
|
393
|
+
values='scurve').reset_index()
|
394
|
+
s_curves_long = (s_curves_long
|
395
|
+
.reset_index(drop=True)
|
396
|
+
.set_index(['building_category', 'building_code', 'year'], drop=True)
|
397
|
+
.rename_axis(None, axis=1))
|
398
|
+
return s_curves_long
|
399
|
+
|
400
|
+
|
401
|
+
def transform_to_dataframe(s_curve_cumulative_demolition: Series, s_curve_original_condition: Series, s_curve_renovation: Series,
|
402
|
+
s_curve_renovation_and_small_measure: Series, s_curve_small_measure: Series, s_curve_demolition: Series) -> pd.DataFrame:
|
403
|
+
"""
|
404
|
+
Creates a pandas DataFrame from the parameters
|
405
|
+
|
406
|
+
Parameters
|
407
|
+
----------
|
408
|
+
s_curve_cumulative_demolition : pandas.Series
|
409
|
+
s_curve_original_condition : pandas.Series
|
410
|
+
s_curve_renovation : pandas.Series
|
411
|
+
s_curve_renovation_and_small_measure : pandas.Series
|
412
|
+
s_curve_small_measure : pandas.Series
|
413
|
+
s_curve_demolition : pandas.Series
|
414
|
+
|
415
|
+
Returns
|
416
|
+
-------
|
417
|
+
pandas.DataFrame
|
418
|
+
"""
|
419
|
+
s_curves_by_condition = pd.DataFrame({
|
420
|
+
'original_condition': s_curve_original_condition,
|
421
|
+
'demolition': s_curve_cumulative_demolition,
|
422
|
+
'small_measure': s_curve_small_measure,
|
423
|
+
'renovation': s_curve_renovation,
|
424
|
+
'renovation_and_small_measure': s_curve_renovation_and_small_measure,
|
425
|
+
's_curve_demolition': s_curve_demolition
|
426
|
+
})
|
427
|
+
return s_curves_by_condition
|
428
|
+
|
429
|
+
|
430
|
+
def transform_to_long(s_curves_by_condition: pd.DataFrame) -> pd.DataFrame:
|
431
|
+
"""
|
432
|
+
|
433
|
+
Parameters
|
434
|
+
----------
|
435
|
+
s_curves_by_condition : pandas.DataFrame
|
436
|
+
|
437
|
+
Returns
|
438
|
+
-------
|
439
|
+
pandas.DataFrame
|
440
|
+
transformed to long, on condition for each row
|
441
|
+
"""
|
442
|
+
df_long = s_curves_by_condition.stack().to_frame(name='s_curve')
|
443
|
+
|
444
|
+
df_long.index.names = ['building_category', 'building_code', 'year', 'building_condition']
|
445
|
+
return df_long
|
446
|
+
|
447
|
+
|
448
|
+
def calculate_s_curves(scurve_parameters, building_code_parameters, years, **kwargs):
|
449
|
+
# Transform s_curve_parameters into long form with each row representing a building_condition at a certain age
|
450
|
+
s_curves = scurve_parameters_to_scurve(scurve_parameters)
|
451
|
+
df_never_share = scurve_parameters_to_never_share(s_curves, scurve_parameters)
|
452
|
+
|
453
|
+
s_curves_with_building_code = merge_s_curves_and_building_code(s_curves, df_never_share, building_code_parameters)
|
454
|
+
s_curves_with_building_code = s_curves_with_building_code.loc[(slice(None), slice(None), [y for y in years])]
|
455
|
+
|
456
|
+
s_curves_with_demolition_acc = accumulate_demolition(s_curves_with_building_code, years)
|
457
|
+
s_curve_demolition = s_curves_with_building_code.demolition
|
458
|
+
|
459
|
+
s_curve_cumulative_demolition = transform_to_cumulative_demolition(s_curves_with_demolition_acc, years)
|
460
|
+
s_curve_renovation_never_share = s_curves_with_building_code.renovation_never_share
|
461
|
+
s_curve_small_measure_never_share = kwargs.get('small_measure_never_share', s_curves_with_building_code.small_measure_never_share)
|
462
|
+
s_curve_cumulative_small_measure = kwargs.get('cumulative_small_measure', cumulative_small_measure(s_curves_with_building_code, years))
|
463
|
+
s_curve_cumulative_renovation = cumulative_renovation(s_curves_with_building_code, years)
|
464
|
+
|
465
|
+
s_curve_renovation_max = renovation_max(s_curve_cumulative_demolition, s_curve_renovation_never_share)
|
466
|
+
s_curve_small_measure_max = kwargs.get('s_curve_small_measure_max', small_measure_max(s_curve_cumulative_demolition, s_curve_small_measure_never_share))
|
467
|
+
|
468
|
+
|
469
|
+
s_curve_small_measure_total = trim_max_value(s_curve_cumulative_small_measure, s_curve_small_measure_max)
|
470
|
+
s_curve_renovation_total = trim_max_value(s_curve_cumulative_renovation, s_curve_renovation_max)
|
471
|
+
scurve_total = total(s_curve_renovation_total, s_curve_small_measure_total)
|
472
|
+
|
473
|
+
s_curve_renovation_from_small_measure = renovation_from_small_measure(s_curve_renovation_max, s_curve_small_measure_total)
|
474
|
+
s_curve_renovation = trim_renovation_from_renovation_total(s_curve_renovation=s_curve_renovation_from_small_measure,
|
475
|
+
s_curve_renovation_max=s_curve_renovation_max,
|
476
|
+
s_curve_renovation_total=s_curve_renovation_total,
|
477
|
+
scurve_total=scurve_total)
|
478
|
+
|
479
|
+
s_curve_renovation_and_small_measure = renovation_and_small_measure(s_curve_renovation, s_curve_renovation_total)
|
480
|
+
|
481
|
+
s_curve_small_measure = small_measure(s_curve_renovation_and_small_measure, s_curve_small_measure_total)
|
482
|
+
|
483
|
+
s_curve_original_condition = original_condition(s_curve_cumulative_demolition, s_curve_renovation,
|
484
|
+
s_curve_renovation_and_small_measure,
|
485
|
+
s_curve_small_measure)
|
486
|
+
|
487
|
+
s_curves_by_condition = transform_to_dataframe(s_curve_cumulative_demolition,
|
488
|
+
s_curve_original_condition,
|
489
|
+
s_curve_renovation,
|
490
|
+
s_curve_renovation_and_small_measure,
|
491
|
+
s_curve_small_measure,
|
492
|
+
s_curve_demolition)
|
493
|
+
|
494
|
+
s_curves_by_condition['original_condition'] = s_curve_original_condition
|
495
|
+
s_curves_by_condition['demolition'] = s_curve_cumulative_demolition
|
496
|
+
s_curves_by_condition['small_measure'] = s_curve_small_measure
|
497
|
+
s_curves_by_condition['renovation'] = s_curve_renovation
|
498
|
+
s_curves_by_condition['renovation_and_small_measure'] = s_curve_renovation_and_small_measure
|
499
|
+
|
500
|
+
s_curves_by_condition['s_curve_sum'] = s_curve_original_condition + s_curve_cumulative_demolition + s_curve_small_measure + s_curve_renovation + s_curve_renovation_and_small_measure
|
501
|
+
|
502
|
+
s_curves_by_condition['s_curve_demolition'] = s_curve_demolition
|
503
|
+
s_curves_by_condition['s_curve_cumulative_demolition'] = s_curve_cumulative_demolition
|
504
|
+
s_curves_by_condition['s_curve_small_measure_total'] = s_curve_small_measure_total
|
505
|
+
s_curves_by_condition['s_curve_small_measure_max'] = s_curve_small_measure_max
|
506
|
+
s_curves_by_condition['s_curve_cumulative_small_measure'] = s_curve_cumulative_small_measure
|
507
|
+
s_curves_by_condition['s_curve_small_measure_never_share'] = s_curve_small_measure_never_share
|
508
|
+
s_curves_by_condition['scurve_total'] = scurve_total
|
509
|
+
s_curves_by_condition['s_curve_renovation_max'] = s_curve_renovation_max
|
510
|
+
s_curves_by_condition['s_curve_cumulative_renovation'] = s_curve_cumulative_renovation
|
511
|
+
s_curves_by_condition['s_curve_renovation_total'] = s_curve_renovation_total
|
512
|
+
s_curves_by_condition['renovation_never_share'] = s_curve_renovation_never_share
|
513
|
+
|
514
|
+
|
515
|
+
return s_curves_by_condition
|
ebm/services/__init__.py
ADDED
File without changes
|