Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dynamic function parameter to get_profiles function #21

Merged
merged 1 commit into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions demandlib/bdew.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,40 @@ def create_bdew_load_profiles(self, dt_index, slp_types, holidays=None):
new_df.drop('date', axis=1, inplace=True)
return new_df.div(new_df.sum(axis=0), axis=1)

def get_profile(self, ann_el_demand_per_sector):
def get_profile(self, ann_el_demand_per_sector,
dyn_function_h0: bool = True):
""" Get the profiles for the given annual demand

Parameters
----------
ann_el_demand_per_sector : dictionary
Key: sector, value: annual value
dyn_function_h0: bool, default True
Uses the dynamisation function of the BDEW to smoothen the
seasonal edges. Functions resolution is daily.
f(x) = -3.916649251 * 10^-10 * x^4 + 3,2 * 10^-7 * x³ - 7,02
* 10^-5 * x²+0,0021 * x +1,24
Adjustment of accuracy: from -3,92 to -3.916649251

Returns
-------
pandas.DataFrame : Table with all profiles

"""
return self.slp_frame.multiply(pd.Series(
ann_el_demand_per_sector), axis=1).dropna(how='all', axis=1) * 4
if dyn_function_h0 == True:
quartersinyear = len(self.slp_frame)
for quarter in range(quartersinyear):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way of doing it is rather inefficient. You should rather calculate an array of all smoothing factors and multiply the SLP by that. The following might work (did not verify):

day_of_year = [(quarter + 1) / (24 * 4) for quarter in range(len(self.slp_frame))]
smoothing_factor = [-3.916649251 * 10 ** -10
                                   * timestep ** 4 + 3.2 * 10 ** -7
                                   * timestep ** 3 - 7.02 * 10 ** -5
                                   * timestep ** 2 + 0.0021
                                   * timestep + 1.24 for timestep in day_of_year]
self.slp_frame['h0'][quarter] = self.slp_frame['h0'] * smoothing_factor

(Or - preferably - using numpy.)

quarterhour_to_day = (quarter + 1) / (24 * 4)
smoothing_factor = -3.916649251 * 10 ** -10 \
* quarterhour_to_day ** 4 + 3.2 * 10 ** -7 \
* quarterhour_to_day ** 3 - 7.02 * 10 ** -5 \
* quarterhour_to_day ** 2 + 0.0021 \
* quarterhour_to_day + 1.24

self.slp_frame['h0'][quarter] = self.slp_frame['h0'][
quarter] * smoothing_factor
return self.slp_frame.multiply(pd.Series(ann_el_demand_per_sector),
axis=1).dropna(how='all', axis=1) * 4


class HeatBuilding:
Expand Down Expand Up @@ -188,7 +207,7 @@ def weighted_temperature(self, how='geometric_series'):
Notes
-----
Equation for the mathematical series of the average
tempaerature [1]_:
temperature [1]_:

.. math::
T=\frac{T_{D}+0.5\cdot T_{D-1}+0.25\cdot T_{D-2}+
Expand Down Expand Up @@ -263,10 +282,12 @@ def get_sf_values(self, filename='shlp_hour_factors.csv'):

# drop unnecessary columns
drop_cols = (
['hour_of_day', 'hour', 'building_class', 'shlp_type',
'date', 'temperature'] + (['weekday_x'] if residential else []) +
(['weekday_y'] if residential else []) +
(['weekday'] if not residential else []))
['hour_of_day', 'hour', 'building_class', 'shlp_type',
'date', 'temperature']
+ (['weekday_x'] if residential else [])
+ (['weekday_y'] if residential else [])
+ (['weekday'] if not residential else []))

sf_mat = sf_mat.drop(drop_cols, 1)

# Determine the h values
Expand Down
3 changes: 2 additions & 1 deletion demandlib/examples/power_demand_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def power_example():
e_slp = bdew.ElecSlp(year, holidays=holidays)

# multiply given annual demand with timeseries
elec_demand = e_slp.get_profile(ann_el_demand_per_sector)
elec_demand = e_slp.get_profile(ann_el_demand_per_sector,
dyn_function_h0=True)

# Add the slp for the industrial group
ilp = profiles.IndustrialLoadProfile(e_slp.date_time_index,
Expand Down