Skip to content

Commit

Permalink
working on shift
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Eggimann committed Jan 11, 2019
1 parent 0b64caa commit 3c69b2d
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 66 deletions.
84 changes: 52 additions & 32 deletions energy_demand/enduse_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import math
import numpy as np
import matplotlib.pyplot as plt

from energy_demand.basic import date_prop
from energy_demand.profiles import load_factors as lf
Expand Down Expand Up @@ -235,6 +236,20 @@ def __init__(
mode_constrained=False,
make_all_flat=make_all_flat)
#print("FUEL TRAIN Y" + str(np.sum(fuel_yh)))

'''print("-----otside-------------")
if curr_yr > 2015 and enduse == 'rs_space_heating':
plt.plot(self.fuel_yh.reshape(8760), label="after")
plt.plot(fuel_yh.reshape(8760), label="before")
plt.legend()
plt.show()
print("----")'''

#if curr_yr > 2015:
# _a = np.max(fuel_yh)
# _b = np.max(self.fuel_yh)
# print("AFTER SHIFTING : {} {}".format(_a, _b))

else:
#If technologies are defined for an enduse

Expand Down Expand Up @@ -400,18 +415,9 @@ def load_shifting(
"""
# Get assumed load shift
if dm_improvement[enduse][curr_yr] == 0:

if curr_yr >= 2015:
print(fuel_yh.shape)
_sum_dayily = np.sum(fuel_yh, axis=0)
_peak_day = np.argmax(_sum_dayily)
print("aa " + str(_peak_day))
print(fuel_yh[int(_peak_day)])
__max_after = fuel_yh.argmax(fuel_yh[int(_peak_day)])
print("peak zero {}".format(__max_after))

pass # no load management
else:

# Calculate average for every day
if mode_constrained:
average_fuel_yd = np.average(fuel_yh, axis=1)
Expand All @@ -424,39 +430,54 @@ def load_shifting(

# Load factor improvement parameter in current year
param_lf_improved_cy = dm_improvement[enduse][curr_yr]
#param_lf_improved_cy = 0.1
print("Loading shifting .. {} {} {}".format(enduse, curr_yr, param_lf_improved_cy))

# Calculate current year load factors
lf_improved_cy = calc_lf_improvement(
param_lf_improved_cy,
loadfactor_yd_cy)

import copy
_a = copy.copy(fuel_yh)
#import copy
#_a = copy.copy(fuel_yh)

fuel_yh = lf.peak_shaving_max_min(
lf_improved_cy,
average_fuel_yd,
fuel_yh,
mode_constrained)


#'''
import matplotlib.pyplot as plt
print(fuel_yh.shape)

plt.plot(fuel_yh[10], label="after")
plt.plot(_a[10], label="before")
plt.legend()
plt.show()
print("----")

# Get maximum hour for electricity demand
_sum_dayily = np.sum(fuel_yh, axis=0)
_peak_day = np.argmax(_sum_dayily)
__max_after = fuel_yh.argmax(fuel_yh[_peak_day])
__max_before = fuel_yh.argmax(_a[_peak_day])
print("befire; {} after: {}".format(__max_before, __max_after))
#'''
'''
if enduse == "rs_space_heating":
print("ENDUSE " + str(enduse))
print(curr_yr)
print(fuel_yh.shape)
_sum_dayily = np.sum(fuel_yh, axis=1)
print(_sum_dayily.shape)
_peak_day = np.argmax(_sum_dayily)
print(_peak_day)
print(lf_improved_cy[_peak_day])
#plt.plot(fuel_yh[_peak_day], label="after")
#plt.plot(_a[_peak_day], label="before")
plt.plot(fuel_yh.reshape(8760), label="after")
plt.plot(_a.reshape(8760), label="before")
plt.legend()
plt.show()
print("----")
print(param_lf_improved_cy)
print(loadfactor_yd_cy[_peak_day])
print(lf_improved_cy[_peak_day])
# Get maximum hour for electricity demand
__max_after = np.max(fuel_yh[_peak_day])
__max_before = np.max(_a[_peak_day])
print("before; {} after: {}".format(__max_before, __max_after))
_new_lf = lf.calc_lf_y_8760(fuel_yh[_peak_day])
_old_lf = lf.calc_lf_y_8760(_a[_peak_day])
print("before; {} after: {}".format(_old_lf, _new_lf))
'''

# -------------------------------------------------
# Convert all load profiles into flat load profiles
Expand Down Expand Up @@ -497,10 +518,9 @@ def calc_lf_improvement(
True: Peak is shifted, False: Peak isn't shifed
"""
# Add load factor improvement to current year load factor
lf_improved_cy = loadfactor_yd_cy + param_lf_improved_cy #* 100
lf_improved_cy = loadfactor_yd_cy + param_lf_improved_cy

# Where load factor larger than zero, set to 1
#lf_improved_cy[lf_improved_cy > 1] = 100
lf_improved_cy[lf_improved_cy > 1] = 1

return lf_improved_cy
Expand Down
4 changes: 2 additions & 2 deletions energy_demand/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ def energy_demand_model(
data = {}
sim_yrs = [2015, 2020, 2025, 2030, 2035, 2040, 2045, 2050]
#sim_yrs = [2015, 2020, 2050] #, 2050]
sim_yrs = [2015, 2050]
sim_yrs = [2015, 2030, 2050]

if len(sys.argv) > 3: #user defined arguments are provide
scenario_name = str(sys.argv[2])
weather_realisation = str(sys.argv[3]) # Weather realisation
else:
scenario_name = "_dm_0_"
scenario_name = "_dm_0P_"
weather_realisation = 'NF1'

print("-------------------------------------")
Expand Down
13 changes: 0 additions & 13 deletions energy_demand/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,6 @@ def aggregate_across_all_regs(
# -----------------------------
# Aggregate residential demand [fueltype, region]
# -----------------------------
'''array_init = np.zeros((fueltypes_nr, reg_nrs)) #Annual
for submodel in aggr_results['ed_submodel_enduse_fueltype_regs_yh']:
if submodel == 0:
for enduse in aggr_results['ed_submodel_enduse_fueltype_regs_yh'][submodel]:
enduse_array_nr = lookup_enduses[enduse]
# Sum across all hours in a year
array_init += np.sum(aggr_results['ed_submodel_enduse_fueltype_regs_yh'][submodel][enduse], axis=2)
else:
pass
'''
fueltypes = lookup_tables.basic_lookups()['fueltypes']
submodel_nr = 0
array_init = np.zeros((fueltypes_nr, reg_nrs))
Expand Down
4 changes: 2 additions & 2 deletions energy_demand/plotting/fig_3_plot_over_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ def scenario_over_time(
"""
statistics_to_print = []

fig = plt.figure(
figsize=basic_plot_functions.cm2inch(10, 10)) #width, height
fig = plt.figure(figsize=basic_plot_functions.cm2inch(10, 10)) #width, height

ax = fig.add_subplot(1, 1, 1)

for cnt_scenario, i in enumerate(scenario_result_container):
scenario_name = i['scenario_name']
national_peak = i['national_peak']

# dataframe with national peak (columns= simulation year, row: Realisation)
# Calculate quantiles
quantile_95 = 0.95
Expand Down
25 changes: 12 additions & 13 deletions energy_demand/profiles/load_factors.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def calc_lf_y(fuel_yh):
Returns
-------
load_factor_y : array
Yearly load factors as percentage (100% = 100)
Yearly load factors as percentage (100% = 1)
Note
-----
Expand Down Expand Up @@ -158,7 +158,7 @@ def calc_lf_y_8760(fuel_yh_8760):
Returns
-------
load_factor_y : array
Yearly load factors as percentage (100% = 100)
Yearly load factors as percentage (100% = 1)
Note
-----
Expand All @@ -167,7 +167,7 @@ def calc_lf_y_8760(fuel_yh_8760):
https://circuitglobe.com/load-factor.html
"""
# Get total sum per fueltype
tot_load_y = np.sum(fuel_yh_8760) #, axis=2)
tot_load_y = np.sum(fuel_yh_8760)

# Calculate maximum hour in every day of a year
max_load_h = np.max(fuel_yh_8760)
Expand All @@ -178,9 +178,8 @@ def calc_lf_y_8760(fuel_yh_8760):

if np.isnan(load_factor_y):
load_factor_y = 0
#load_factor_y[np.isnan(load_factor_y)] = 0

return load_factor_y #* 100
return load_factor_y

def calc_lf_season(seasons, fuel_region_yh, average_fuel_yd):
"""Calculate load factors per fueltype per region.
Expand Down Expand Up @@ -223,8 +222,8 @@ def calc_lf_season(seasons, fuel_region_yh, average_fuel_yd):
# Unable local RuntimeWarning: divide by zero encountered
with np.errstate(divide='ignore', invalid='ignore'):

#convert to percentage
season_lf = (average_fuel_yd_full_year / max_load_h_season) #* 100
#convert to decimal
season_lf = (average_fuel_yd_full_year / max_load_h_season)

# Replace
season_lf[np.isinf(season_lf)] = 0
Expand Down Expand Up @@ -264,8 +263,8 @@ def calc_lf_d(fuel_yh, average_fuel_yd, mode_constrained):
# Unable local RuntimeWarning: divide by zero encountered
with np.errstate(divide='ignore', invalid='ignore'):

#convert to percentage
daily_lf = (average_fuel_yd / max_load_yd) #* 100
#convert to decimal
daily_lf = (average_fuel_yd / max_load_yd)

# Replace by zero
daily_lf[np.isinf(daily_lf)] = 0
Expand Down Expand Up @@ -296,15 +295,15 @@ def calc_lf_d_8760(fuel_yh):
"""
# Get maximum hours in every day
fuel_yh = fuel_yh.reshape(365, 24)

max_load_yd = np.max(fuel_yh, axis=1)
average_fuel_yd = np.average(fuel_yh, axis=1)

# Unable local RuntimeWarning: divide by zero encountered
with np.errstate(divide='ignore', invalid='ignore'):

#convert to percentage
daily_lf = (average_fuel_yd / max_load_yd) #* 100
#convert to decimal
daily_lf = (average_fuel_yd / max_load_yd)

# Replace by zero
daily_lf[np.isinf(daily_lf)] = 0
Expand Down Expand Up @@ -349,7 +348,7 @@ def calc_lf_season_8760(seasons, fuel_region_yh):

# Unable local RuntimeWarning: divide by zero encountered
with np.errstate(divide='ignore', invalid='ignore'):
season_lf = (average_fuel_yd / max_load_h_season) #* 100 #convert to percentage
season_lf = (average_fuel_yd / max_load_h_season)

# Replace
season_lf[np.isinf(season_lf)] = 0
Expand Down
1 change: 0 additions & 1 deletion energy_demand/read_write/read_weather_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def read_in_weather_results(
path_result, 'only_total')

#print(results_container['ed_reg_tot_y'][2015].shape)

results_container['ed_reg_peakday'] = read_data.read_results_yh(
os.path.join('simulation_results', path_result), 'only_peak')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def main(
Year to generate comparison plots
"""
print("Start creating plots")

# -------------------
# Create result folder
# -------------------
Expand Down Expand Up @@ -205,8 +206,7 @@ def main(
seperate_legend=False)

# ------------------------------
# Plot national peak change over time for each scenario
# including weather variability
# Plot national peak change over time for each scenario including weather variability
# ------------------------------
fig_3_plot_over_time.scenario_over_time(
scenario_result_container=scenario_result_container,
Expand Down Expand Up @@ -290,6 +290,7 @@ def main(
path_shapefile_input="C:/Users/cenv0553/ED/data/energy_demand/region_definitions/lad_2016_uk_simplified.shp"

main(
#scenarios_path="C:/_FFF_local", #_local",
scenarios_path="C:/_FFF",
path_shapefile_input=path_shapefile_input,
base_yr=2015,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_enduse_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def test_enduse():
"""testing"""
out = enduse_func.Enduse(
submodel_name ='test_name',
submodel_name='test_name',
region='test',
scenario_data='test',
assumptions='test',
Expand Down

0 comments on commit 3c69b2d

Please sign in to comment.