Skip to content
Snippets Groups Projects
Commit f0a91a38 authored by Martin Schnitzler's avatar Martin Schnitzler
Browse files

Updated demand_generator.py to work with different profiles

Updated shlp_hour_factors.csv with additional data
Updated shlp.csv with new entries
Updated selp.csv with new entries
Refactored .gitignore and added .vscode and test.py
parent f78c4512
No related branches found
No related tags found
No related merge requests found
__pycache__
.vscode
test.py
......@@ -39,10 +39,15 @@ class ElectricityDemandGenerator:
os.path.join(os.path.dirname(__file__), "selp.csv"), index_col=[0, 1]
)
self.profiles = dict()
profile_columns = profiles_df.columns
#loading profiles into self.profiles dictionary, indexed py period, weekday and profile
for profile in profile_columns:
for period in ["winter", "transition", "summer"]:
for weekday in ["working_day", "saturday", "sunday"]:
self.profiles[period, weekday] = profiles_df.loc[
(period, weekday), "H0"
self.profiles[period, weekday, profile] = profiles_df.loc[
(period, weekday), profile
].values
# set standart period ranges
......@@ -64,11 +69,12 @@ class ElectricityDemandGenerator:
)
self.dynamic_factor = factor_function(np.arange(1, 366, dtype=float))
def generate(self, year, annual_demand):
def generate(self, year, annual_demand, profile_type="H0"):
# year: year to generate the data for in astronomical numbering
# annual_demand: annual electricity demand in kWh
# days in the year, depending on wehter the given year a leap year
days_in_year = 365 if not calendar.isleap(year) else 366
# generate series of days in the year and to which period they belong
......@@ -89,15 +95,15 @@ class ElectricityDemandGenerator:
weekday = date.weekday()
if weekday < 5:
profile[i * 24 * 4 : (i + 1) * 24 * 4] = (
self.profiles[period, "working_day"] * self.dynamic_factor[i]
self.profiles[period, "working_day", profile_type] * self.dynamic_factor[i]
)
elif weekday == 5:
profile[i * 24 * 4 : (i + 1) * 24 * 4] = (
self.profiles[period, "saturday"] * self.dynamic_factor[i]
self.profiles[period, "saturday", profile_type] * self.dynamic_factor[i]
)
else:
profile[i * 24 * 4 : (i + 1) * 24 * 4] = (
self.profiles[period, "sunday"] * self.dynamic_factor[i]
self.profiles[period, "sunday", profile_type] * self.dynamic_factor[i]
)
# normalize profile and convert to kW
......@@ -121,20 +127,32 @@ class HeatingDemandGenerator:
index_col=[0, 1],
)
self.a = profiles_df["A"]["D13"]
self.b = profiles_df["B"]["D13"]
self.c = profiles_df["C"]["D13"]
self.d = profiles_df["D"]["D13"]
self.a = profiles_df["A"]
self.b = profiles_df["B"]
self.c = profiles_df["C"]
self.d = profiles_df["D"]
self.theta_0 = profiles_df["theta_0"]
self.theta_0 = profiles_df["theta_0"]["D13"]
self.weekday_factors = dict()
self.weekday_factors = profiles_df.loc[
"D13", ["F_Mon", "F_Tue", "F_Wed", "F_Thu", "F_Fri", "F_Sat", "F_Sun"]
for profile in profiles_df.index:
self.weekday_factors[profile] = profiles_df.loc[
profile, ["F_Mon", "F_Tue", "F_Wed", "F_Thu", "F_Fri", "F_Sat", "F_Sun"]
].values
self.hour_factors = hour_factors_df.loc["D13"].values
# self.weekday_factors = profiles_df.loc[
# "D13", ["F_Mon", "F_Tue", "F_Wed", "F_Thu", "F_Fri", "F_Sat", "F_Sun"]
# ].values
def generate(self, year, annual_demand, temperatures, seperate_warm_water=False):
self.hour_factors = dict()
for profile in hour_factors_df.index.get_level_values(0).unique():
self.hour_factors[profile] = hour_factors_df.loc[profile].values
#self.hour_factors = hour_factors_df.loc["D13"].values
def generate(self, year, annual_demand, temperatures, seperate_warm_water=False, profile_type="D13"):
# year: year to generate the data for in astronomical numbering
# annual_demand: annual heating demand in kWh
# temperatures: daily temperatures in °C
......@@ -154,18 +172,20 @@ class HeatingDemandGenerator:
+ 0.125 * np.roll(temperatures, 3)
) / 1.875
# compute sigmoid function, weeday factors and hour factors
temp = self.b / (allocation_temperatures - 40.0)
h = (self.a / (1.0 + np.sign(temp) * (np.abs(temp) ** self.c))) + self.d
# compute sigmoid function, weekday factors and hour factors
temp = self.b[profile_type] / (allocation_temperatures - 40.0)
h = (self.a[profile_type] / (1.0 + np.sign(temp) * (np.abs(temp) ** self.c[profile_type]))) + self.d[profile_type]
f_wd = np.array(
pd.date_range(datetime.datetime(year, 1, 1), periods=days_in_year).map(
lambda a: self.weekday_factors[a.weekday()]
lambda a: self.weekday_factors[profile_type][a.weekday()]
),
dtype=float,
)
f_h = self.hour_factors[
hour_factors = self.hour_factors[profile_type] if profile_type in self.hour_factors.keys() else self.hour_factors["D13"]
f_h = hour_factors[
(
(allocation_temperatures <= -15.0) * 1
+ (
......@@ -196,11 +216,11 @@ class HeatingDemandGenerator:
]
# compute reference daily demand (kundenwert)
reference_temp = self.b / (np.full(days_in_year, 8.0, dtype=float) - 40.0)
reference_temp = self.b[profile_type] / (np.full(days_in_year, 8.0, dtype=float) - 40.0)
reference_h = (
self.a
/ (1.0 + np.sign(reference_temp) * (np.abs(reference_temp) ** self.c))
) + self.d
self.a[profile_type]
/ (1.0 + np.sign(reference_temp) * (np.abs(reference_temp) ** self.c[profile_type]))
) + self.d[profile_type]
reference_daily_demand = annual_demand / np.sum(reference_h * f_wd)
......@@ -213,7 +233,7 @@ class HeatingDemandGenerator:
reference_daily_demand * h[i] * f_wd[i] * (f_h[i] / 100.0)
)
profile_warm_water[i * 24 : (i + 1) * 24] = (
reference_daily_demand * self.d * f_wd[i] * (f_h[i] / 100.0)
reference_daily_demand * self.d[profile_type] * f_wd[i] * (f_h[i] / 100.0)
)
return profile_sum - profile_warm_water, profile_warm_water
......
This diff is collapsed.
code,A,B,C,D,theta_0,F_Mon,F_Tue,F_Wed,F_Thu,F_Fri,F_Sat,F_Sun
D13,3.0469695,-37.1833141,5.6727847,0.0961931,40.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
D14,3.1850191,-37.4124155,6.1723179,0.0761096,40.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
D15,3.0469695,-37.1833141,5.6727847,0.0961931,40.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
D23,2.3877618,-34.7213605,5.8164304,0.1208194,40.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
D24,2.5187775,-35.0333754,6.2240634,0.1010782,40.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
D25,2.6564406,-35.2516927,6.5182659,0.0812059,40.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
HK3,0.4040932,-24.4392968,6.5718175,0.7107710,40.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
KO5,4.3624833,-38.6634022,7.5974644,0.0083264,40.0,1.0354,1.0523,1.0449,1.0494,0.9885,0.8860,0.9435
KO4,3.4428943,-36.6590504,7.6083226,0.0746850,40.0,1.0354,1.0523,1.0449,1.0494,0.9885,0.8860,0.9435
KO3,2.7172288,-35.1412563,7.1303395,0.1418472,40.0,1.0354,1.0523,1.0449,1.0494,0.9885,0.8860,0.9435
KO2,2.0660501,-33.6016520,6.6753610,0.2309125,40.0,1.0354,1.0523,1.0449,1.0494,0.9885,0.8860,0.9435
KO1,1.4159571,-30.8425192,6.3467557,0.3211791,40.0,1.0354,1.0523,1.0449,1.0494,0.9885,0.8860,0.9435
HA5,4.8252376,-39.2802564,8.6240217,0.0099945,40.0,1.0358,1.0232,1.0252,1.0295,1.0253,0.9675,0.8935
HA4,4.0196902,-37.8282037,8.1593369,0.0472845,40.0,1.0358,1.0232,1.0252,1.0295,1.0253,0.9675,0.8935
HA3,3.5811214,-36.9650065,7.2256947,0.0448416,40.0,1.0358,1.0232,1.0252,1.0295,1.0253,0.9675,0.8935
HA2,2.8544749,-35.6294231,7.0058264,0.1164772,40.0,1.0358,1.0232,1.0252,1.0295,1.0253,0.9675,0.8935
HA1,2.3742828,-34.7595501,5.9987037,0.1494411,40.0,1.0358,1.0232,1.0252,1.0295,1.0253,0.9675,0.8935
MK5,3.5862355,-37.0802994,8.2420572,0.0146008,40.0,1.0699,1.0365,0.9933,0.9948,1.0659,0.9362,0.9034
MK4,3.1177248,-35.8715062,7.5186829,0.0343301,40.0,1.0699,1.0365,0.9933,0.9948,1.0659,0.9362,0.9034
MK3,2.7882424,-34.8806130,6.5951899,0.0540329,40.0,1.0699,1.0365,0.9933,0.9948,1.0659,0.9362,0.9034
MK2,2.2908184,-33.1476867,6.3714765,0.0810023,40.0,1.0699,1.0365,0.9933,0.9948,1.0659,0.9362,0.9034
MK1,1.8644534,-30.7071633,6.4626937,0.1048339,40.0,1.0699,1.0365,0.9933,0.9948,1.0659,0.9362,0.9034
BD5,4.5699506,-38.5353392,7.5976991,0.0066314,40.0,1.1052,1.0857,1.0378,1.0622,1.0266,0.7629,0.9196
BD4,3.7500000,-37.5000000,6.8000000,0.0609113,40.0,1.1052,1.0857,1.0378,1.0622,1.0266,0.7629,0.9196
BD3,2.9177027,-36.1794117,5.9265162,0.1151912,40.0,1.1052,1.0857,1.0378,1.0622,1.0266,0.7629,0.9196
BD2,2.1095878,-35.8444508,5.2154672,0.2854583,40.0,1.1052,1.0857,1.0378,1.0622,1.0266,0.7629,0.9196
BD1,1.2903505,-35.2349868,2.1064247,0.4557253,40.0,1.1052,1.0857,1.0378,1.0622,1.0266,0.7629,0.9196
BH5,2.9800000,-35.8000000,5.6340581,0.0000000,40.0,0.9767,1.0389,1.0028,1.0162,1.0024,1.0043,0.9587
BH4,2.4595181,-35.2532124,6.0587001,0.1647370,40.0,0.9767,1.0389,1.0028,1.0162,1.0024,1.0043,0.9587
BH3,2.0102472,-35.2532124,6.1544406,0.3294741,40.0,0.9767,1.0389,1.0028,1.0162,1.0024,1.0043,0.9587
BH2,1.7005279,-35.1500000,6.1632739,0.4298261,40.0,0.9767,1.0389,1.0028,1.0162,1.0024,1.0043,0.9587
BH1,1.4771786,-35.0834447,5.4123425,0.4744264,40.0,0.9767,1.0389,1.0028,1.0162,1.0024,1.0043,0.9587
WA5,1.2768854,-34.3424371,5.4518822,0.5572660,40.0,1.2457,1.2615,1.2707,1.2430,1.1276,0.3877,0.4638
WA4,1.0535875,-35.3000000,4.8662747,0.6811042,40.0,1.2457,1.2615,1.2707,1.2430,1.1276,0.3877,0.4638
WA3,0.7657290,-36.0237912,4.8662747,0.8049425,40.0,1.2457,1.2615,1.2707,1.2430,1.1276,0.3877,0.4638
WA2,0.6166229,-38.4000000,3.8705352,0.8700250,40.0,1.2457,1.2615,1.2707,1.2430,1.1276,0.3877,0.4638
WA1,0.4000000,-40.5149482,2.8747957,0.9351076,40.0,1.2457,1.2615,1.2707,1.2430,1.1276,0.3877,0.4638
GA5,3.3295575,-36.0146211,8.7767465,0.0000000,40.0,0.9322,0.9894,1.0033,1.0109,1.0180,1.0356,1.0106
GA4,2.8195656,-36.0000000,7.7368518,0.1572810,40.0,0.9322,0.9894,1.0033,1.0109,1.0180,1.0356,1.0106
GA3,2.2850165,-36.2878584,6.5885126,0.3150535,40.0,0.9322,0.9894,1.0033,1.0109,1.0180,1.0356,1.0106
GA2,1.6487623,-36.3992736,6.2149172,0.4877637,40.0,0.9322,0.9894,1.0033,1.0109,1.0180,1.0356,1.0106
GA1,1.1770345,-39.1599914,4.2076110,0.6604739,40.0,0.9322,0.9894,1.0033,1.0109,1.0180,1.0356,1.0106
BA5,1.2779567,-34.5173920,5.7212303,0.5457333,40.0,1.0848,1.1211,1.0769,1.1353,1.1402,0.4852,0.9565
BA4,0.9315889,-33.3500000,5.7212303,0.6656494,40.0,1.0848,1.1211,1.0769,1.1353,1.1402,0.4852,0.9565
BA3,0.6261962,-33.0000000,5.7212303,0.7855655,40.0,1.0848,1.1211,1.0769,1.1353,1.1402,0.4852,0.9565
BA2,0.3879191,-35.5000000,4.0000000,0.9054815,40.0,1.0848,1.1211,1.0769,1.1353,1.1402,0.4852,0.9565
BA1,0.1500000,-36.0000000,2.0000000,1.0000000,40.0,1.0848,1.1211,1.0769,1.1353,1.1402,0.4852,0.9565
GB5,3.9320532,-38.1433248,7.6185871,0.0230297,40.0,0.9897,0.9627,1.0507,1.0552,1.0297,0.9767,0.9353
GB4,3.6017736,-37.8825368,6.9836070,0.0548262,40.0,0.9897,0.9627,1.0507,1.0552,1.0297,0.9767,0.9353
GB3,3.2572742,-37.5000000,6.3462148,0.0866227,40.0,0.9897,0.9627,1.0507,1.0552,1.0297,0.9767,0.9353
GB2,3.3904645,-39.2875216,4.4905740,0.0834783,40.0,0.9897,0.9627,1.0507,1.0552,1.0297,0.9767,0.9353
GB1,3.1761945,-40.8366609,3.6785892,0.1502156,40.0,0.9897,0.9627,1.0507,1.0552,1.0297,0.9767,0.9353
PD5,4.7462814,-38.7504294,10.2753334,0.0000000,40.0,1.0214,1.0866,1.0720,1.0557,1.0117,0.9001,0.8525
PD4,3.8500000,-37.0000000,10.2405021,0.0469243,40.0,1.0214,1.0866,1.0720,1.0557,1.0117,0.9001,0.8525
PD3,3.2000000,-35.8000000,8.4000000,0.0938486,40.0,1.0214,1.0866,1.0720,1.0557,1.0117,0.9001,0.8525
PD2,2.5784173,-34.7321261,6.4805035,0.1407729,40.0,1.0214,1.0866,1.0720,1.0557,1.0117,0.9001,0.8525
PD1,1.4894022,-32.4252678,8.1732612,0.3905987,40.0,1.0214,1.0866,1.0720,1.0557,1.0117,0.9001,0.8525
MF5,2.6564406,-35.2516927,6.5182659,0.0812059,40.0,1.0354,1.0523,1.0449,1.0494,0.9885,0.8860,0.9435
MF4,2.5187775,-35.0333754,6.2240634,0.1010782,40.0,1.0354,1.0523,1.0449,1.0494,0.9885,0.8860,0.9435
MF3,2.3877618,-34.7213605,5.8164304,0.1208194,40.0,1.0354,1.0523,1.0449,1.0494,0.9885,0.8860,0.9435
MF2,2.2486333,-34.5428431,5.5545245,0.1408220,40.0,1.0354,1.0523,1.0449,1.0494,0.9885,0.8860,0.9435
MF1,2.1163531,-34.2628623,5.1763874,0.1606945,40.0,1.0354,1.0523,1.0449,1.0494,0.9885,0.8860,0.9435
HD4,3.0084346,-36.6078453,7.3211870,0.1549660,40.0,1.0300,1.0300,1.0200,1.0300,1.0100,0.9300,0.9500
HD3,2.5792510,-35.6816144,6.6857976,0.1995541,40.0,1.0300,1.0300,1.0200,1.0300,1.0100,0.9300,0.9500
\ No newline at end of file
......@@ -9,3 +9,13 @@ D13,6,1.42,1.55,1.67,2.0,2.98,5.41,6.85,6.79,5.78,5.27,4.78,4.35,4.15,4.02,3.99,
D13,7,0.96,1.05,1.12,1.62,2.89,6.62,8.21,7.57,6.09,6.01,5.13,4.83,4.42,3.97,3.78,3.59,4.0,4.28,4.56,5.13,5.19,4.42,3.09,1.47
D13,8,0.45,0.54,0.44,0.81,1.91,6.01,9.39,8.09,6.14,5.87,5.33,5.41,5.21,4.2,4.03,3.6,4.23,4.98,4.82,5.08,5.26,4.5,2.62,1.08
D13,9,0.45,0.54,0.44,0.81,1.91,6.01,9.39,8.09,6.14,5.87,5.33,5.41,5.21,4.2,4.03,3.6,4.23,4.98,4.82,5.08,5.26,4.5,2.62,1.08
D23,0,2.99,2.96,2.94,3.04,3.55,5.43,5.49,4.59,4.59,4.47,4.23,4.36,4.27,4.23,4.19,4.30,4.36,4.58,4.53,4.63,4.55,4.32,4.17,3.21
D23,1,2.98,2.94,2.92,3.02,3.55,5.43,5.25,4.62,4.61,4.49,4.25,4.38,4.29,4.24,4.21,4.32,4.38,4.60,4.57,4.66,4.58,4.34,4.18,3.19
D23,2,2.91,2.88,2.85,2.96,3.52,5.50,5.27,4.65,4.63,4.51,4.26,4.39,4.30,4.24,4.21,4.32,4.39,4.62,4.58,4.69,4.61,4.35,4.19,3.15
D23,3,2.58,2.66,2.70,2.91,3.51,5.10,5.05,4.78,4.87,4.79,4.64,4.52,4.48,4.38,4.37,4.41,4.59,4.73,4.79,4.76,4.61,4.23,3.77,2.77
D23,4,2.35,2.50,2.54,2.74,3.39,5.06,5.04,4.90,4.85,4.75,4.62,4.46,4.42,4.41,4.43,4.47,4.66,4.82,4.92,4.91,4.80,4.39,3.79,2.78
D23,5,2.25,2.47,2.35,2.58,3.46,5.13,5.24,5.07,4.94,4.67,4.50,4.34,4.26,4.20,4.20,4.32,4.55,4.78,4.99,5.13,5.09,4.65,3.93,2.89
D23,6,2.21,2.15,2.08,2.31,3.43,5.26,6.05,5.50,5.21,4.87,4.63,4.39,4.29,4.16,4.01,4.04,4.15,4.36,4.70,5.05,5.18,4.96,4.09,2.92
D23,7,2.22,2.20,2.07,2.23,3.70,5.48,6.02,5.70,5.17,5.07,4.74,4.52,4.49,4.09,4.04,3.85,3.91,4.10,4.44,4.74,5.00,4.94,4.19,3.07
D23,8,2.46,2.55,2.47,2.37,3.80,5.19,4.40,5.55,4.96,5.04,4.78,4.64,4.66,4.28,4.39,3.98,3.92,4.20,4.42,4.55,4.96,4.81,4.37,3.26
D23,9,2.46,2.55,2.47,2.37,3.80,5.19,4.40,5.55,4.96,5.04,4.78,4.64,4.66,4.28,4.39,3.98,3.92,4.20,4.42,4.55,4.96,4.81,4.37,3.26
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment