Skip to content

Commit

Permalink
started implementing load reshaping module - error with copying
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Eggimann committed Oct 24, 2017
1 parent 3ea8175 commit 4cad99e
Show file tree
Hide file tree
Showing 17 changed files with 256 additions and 81 deletions.
18 changes: 9 additions & 9 deletions energy_demand/assumptions/base_assumptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ def load_assumptions(data, write_sim_param):

# --Industry Submodel
assumptions['scenario_drivers']['is_submodule'] = {
'is_high_temp_process': ['GVA'],
'is_low_temp_process': ['GVA'],
'is_drying_separation': ['GVA'],
'is_motors': ['GVA'],
'is_compressed_air': ['GVA'],
'is_lighting': ['GVA'],
'is_space_heating': ['GVA'],
'is_other': ['GVA'],
'is_refrigeration': ['GVA']
'is_high_temp_process': ['gva'],
'is_low_temp_process': ['gva'],
'is_drying_separation': ['gva'],
'is_motors': ['gva'],
'is_compressed_air': ['gva'],
'is_lighting': ['gva'],
'is_space_heating': ['gva'],
'is_other': ['gva'],
'is_refrigeration': ['gva']
}

# Change in floor depending on sector (if no change set to 1, if e.g. 10% decrease change to 0.9)
Expand Down
2 changes: 1 addition & 1 deletion energy_demand/basic/logger_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def set_up_logger(path_log_file):
logging.basicConfig(
filename=path_log_file,
filemode='w', #'a, w'
level=logging.DEBUG, #INFO, DEBUG
level=logging.INFO, #INFO, DEBUG
format=('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
)

Expand Down
6 changes: 3 additions & 3 deletions energy_demand/dwelling_stock/dw_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def ss_dw_stock(region, data, curr_yr):
enduses=data['enduses']['ss_all_enduses'],
driver_assumptions=data['assumptions']['scenario_drivers']['ss_submodule'],
sector_type=sector,
gva=data['GVA'][curr_yr][region]))
gva=data['gva'][curr_yr][region]))

# Add regional base year dwelling to dwelling stock
dwelling_stock = DwellingStock(
Expand Down Expand Up @@ -703,7 +703,7 @@ def generate_dw_existing(
population=pop_dwtype_age_class,
age=float(dwtype_age_id),
dwtype=dw_type_name,
gva=data['GVA'][curr_yr][region]
gva=data['gva'][curr_yr][region]
)
)

Expand Down Expand Up @@ -779,7 +779,7 @@ def generate_dw_new(data, region, curr_yr, floorarea_p_by, floorarea_pp_cy, dw_s
population=pop_dwtype_new_build_cy,
age=curr_yr,
dwtype=dw_type_name,
gva=data['GVA'][curr_yr][region]
gva=data['gva'][curr_yr][region]
)
)

Expand Down
116 changes: 71 additions & 45 deletions energy_demand/enduse_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from energy_demand.technologies import diffusion_technologies
from energy_demand.initalisations import helpers as init
from energy_demand.profiles import load_profile as lp
from energy_demand.profiles import load_factors
from energy_demand.technologies import fuel_service_switch
from energy_demand.basic import testing_functions as testing

Expand All @@ -34,7 +35,7 @@ class Enduse(object):
----------
region_name : str
Region name
data : dict
data : dict TODO
Data container
enduse : str
Enduse name
Expand Down Expand Up @@ -91,7 +92,11 @@ class Enduse(object):
def __init__(
self,
region_name,
data,
scenario_data,
lookups,
assumptions,
non_regional_lp_stock,
sim_param,
enduse,
sector,
fuel,
Expand All @@ -110,27 +115,27 @@ def __init__(
regional_lp_stock,
dw_stock=False,
reg_scen_drivers=None,
crit_flat_profile=False
crit_flat_profile=False,
):
"""Enduse class constructor
"""
self.enduse = enduse
self.sector = sector
self.fuel_new_y = fuel #copy
#self.fuel_new_y = np.copy(fuel) #copy
self.fuel_new_y = fuel
self.crit_flat_profile = crit_flat_profile
print("crit_flat_profile: {} {} {}".format(crit_flat_profile, enduse, sector))

if np.sum(fuel) == 0: #If enduse has no fuel return empty shapes
self.crit_flat_profile = True
self.fuel_y = np.zeros((data['lookups']['fueltypes_nr']), dtype=float)
self.fuel_y = np.zeros((lookups['fueltypes_nr']), dtype=float)
self.fuel_yh = 0
self.fuel_peak_dh = np.zeros((data['lookups']['fueltypes_nr'], 24), dtype=float)
self.fuel_peak_dh = np.zeros((lookups['fueltypes_nr'], 24), dtype=float)
self.fuel_peak_h = 0
else:

# Get correct parameters depending on model configuration
load_profiles = get_lp_stock(
enduse,
data['non_regional_lp_stock'],
non_regional_lp_stock,
regional_lp_stock)

self.enduse_techs = get_enduse_tech(fuel_tech_p_by)
Expand All @@ -144,24 +149,24 @@ def __init__(
self.fuel_new_y,
cooling_factor_y,
heating_factor_y,
data['assumptions'])
assumptions)
logging.debug("Fuel train B: " + str(np.sum(self.fuel_new_y)))

# --Change fuel consumption based on smart meter induced general savings
self.fuel_new_y = apply_smart_metering(
enduse,
self.fuel_new_y,
data['assumptions'],
data['sim_param'])
assumptions,
sim_param)
logging.debug("Fuel train C: " + str(np.sum(self.fuel_new_y)))

# --Enduse specific consumption change in %
self.fuel_new_y = apply_specific_change(
enduse,
self.fuel_new_y,
data['assumptions'],
assumptions,
enduse_overall_change_ey,
data['sim_param'])
sim_param)
logging.debug("Fuel train D: " + str(np.sum(self.fuel_new_y)))

# -------------------------------------------------------------------------------
Expand All @@ -172,10 +177,10 @@ def __init__(
self.fuel_new_y,
dw_stock,
region_name,
data['GVA'],
data['Population'],
scenario_data['gva'],
scenario_data['population'],
reg_scen_drivers,
data['sim_param'])
sim_param)
logging.debug("Fuel train E: " + str(np.sum(self.fuel_new_y)))

# ----------------------------------
Expand All @@ -189,9 +194,8 @@ def __init__(
Note: for heating, technologies need to be assigned. Otherwise,
here there will be problems
"""
print("EEE")
if crit_flat_profile:
self.fuel_y = self.fuel_new_y * data['assumptions']['model_yeardays_nrs'] / 365.0
self.fuel_y = self.fuel_new_y * assumptions['model_yeardays_nrs'] / 365.0
else:
self.fuel_yh, self.fuel_peak_dh, self.fuel_peak_h = assign_load_profiles_no_techs(
enduse,
Expand All @@ -205,7 +209,7 @@ def __init__(
# Get enduse specific configurations
# ----
mode_constrained, crit_switch_fuel, crit_switch_service = get_enduse_configuration(
enduse, data['assumptions'], data['sim_param'], fuel_switches, service_switches)
enduse, assumptions, sim_param, fuel_switches, service_switches)

# ------------------------------------
# Calculate regional energy service
Expand All @@ -218,30 +222,30 @@ def __init__(
self.crit_flat_profile,
fuel_tech_p_by,
tech_stock,
data['lookups']['fueltype'],
lookups['fueltype'],
load_profiles,
mode_constrained,
data['assumptions']['model_yearhours_nrs'],
data['assumptions']['model_yeardays_nrs']
assumptions['model_yearhours_nrs'],
assumptions['model_yeardays_nrs']
)
print("service_fueltype_tech_cy_p: " + str(service_fueltype_tech_cy_p))

# ------------------------------------
# Reduction of service because of heat recovery
# (standard sigmoid diffusion)
# ------------------------------------
tot_service_yh_cy = apply_heat_recovery(
enduse,
data['assumptions'],
assumptions,
tot_service_yh_cy,
'tot_service_yh_cy',
data['sim_param'])
sim_param)
#TODO: MAKE THAT service_Tech is not passed through
service_tech_cy = apply_heat_recovery(
enduse,
data['assumptions'],
assumptions,
service_tech_cy,
'service_tech',
data['sim_param'])
sim_param)

# --------------------------------
# Switches (service or fuel)
Expand All @@ -256,7 +260,7 @@ def __init__(
tech_decreased_share,
tech_constant_share,
sig_param_tech,
data['sim_param']['curr_yr'])
sim_param['curr_yr'])
elif crit_switch_fuel:
service_tech_cy = fuel_switch(
enduse,
Expand All @@ -268,7 +272,7 @@ def __init__(
service_fueltype_cy_p,
fuel_switches,
fuel_tech_p_by,
data['sim_param']['curr_yr'])
sim_param['curr_yr'])
else:
pass #No switch implemented

Expand All @@ -279,7 +283,7 @@ def __init__(
enduse,
service_tech_cy,
tech_stock,
data['lookups'],
lookups,
mode_constrained)

# ------------------------------------------
Expand All @@ -292,22 +296,43 @@ def __init__(
enduse,
tech_stock,
fuel_tech_y,
data['lookups'],
lookups,
mode_constrained)
print("tt")
else:'''
if 1 == 1:
self.fuel_y = self.fuel_new_y #NEW SHARK
self.fuel_yh, self.fuel_peak_dh, self.fuel_peak_h = assign_load_profiles_techs(
enduse,
sector,
self.enduse_techs,
tech_stock,
fuel_tech_y,
data['lookups'],
data['assumptions']['model_yeardays_nrs'],
mode_constrained,
load_profiles)
#if 1 == 1:
self.fuel_y = self.fuel_new_y #NEW SHARK
self.fuel_yh, self.fuel_peak_dh, self.fuel_peak_h = assign_load_profiles_techs(
enduse,
sector,
self.enduse_techs,
tech_stock,
fuel_tech_y,
lookups,
assumptions['model_yeardays_nrs'],
mode_constrained,
load_profiles)

# ------------------------
# Demand Management Implementation
# ------------------------
'''
_a = np.sum(self.fuel_yh)
daily_lf_cy, average_fuel_yd = load_factors.daily_load_factors(self.fuel_yh)
print(daily_lf_cy)
# Calculate load factor cy
lf_improvement = 0.1 # improvement (+) in % 50%#TODO: DIFFUSION; plus take assumpiton from enduse
daily_lf_cy_improved = daily_lf_cy + lf_improvement
self.fuel_yh = load_factors.peak_shaving_max_min(
daily_lf_cy_improved,
average_fuel_yd,
self.fuel_yh)
_b = np.sum(self.fuel_yh)
if float(round(_a, 5)) != float(round(_b, 5)):
print("..")
'''

def assign_flat_load_profiles_techs(enduse, tech_stock, fuel_tech_y, lookups, mode_constrained):
'''If a flat load profile is assigned (crit_flat_profile)
Expand Down Expand Up @@ -1068,7 +1093,7 @@ def apply_scenario_drivers(enduse, fuel_new_y, dw_stock, region_name, gva, popul
for scenario_driver in scenario_drivers:

# Get correct data depending on driver
if scenario_driver == 'GVA':
if scenario_driver == 'gva':
by_driver_data = gva[base_yr][region_name]
cy_driver_data = gva[curr_yr][region_name]
elif scenario_driver == 'population':
Expand Down Expand Up @@ -1405,6 +1430,7 @@ def fuel_switch(
logging.debug("... fuel_switch is implemented")

service_tech_switched = service_tech # copy.copy(service_tech) #np.copy?
#service_tech_switched = np.copy(service_tech) #np.copy?

# Iterate all technologies which are installed in fuel switches
for tech_installed in installed_tech:
Expand Down
6 changes: 5 additions & 1 deletion energy_demand/is_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ def create_enduse(self, region_obj, data, crit_flat_profile):
"""
industry_object = endusefunctions.Enduse(
region_name=self.region_name,
data=data,
scenario_data={'gva': data['gva'], 'population': data['population']},
lookups=data['lookups'],
assumptions=data['assumptions'],
non_regional_lp_stock=data['non_regional_lp_stock'],
sim_param=data['sim_param'],
enduse=self.enduse,
sector=self.sector,
fuel=region_obj.is_enduses_sectors_fuels[self.sector][self.enduse],
Expand Down
2 changes: 1 addition & 1 deletion energy_demand/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
The industry heating is identical to service heating
TODO: REplace 1 and zero by fueltypes test_fuel_switch
'''
'''
import os
import sys
import logging
Expand Down
3 changes: 2 additions & 1 deletion energy_demand/plotting/plotting_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,4 +386,5 @@ def plot_load_profile_dh(array_dh):

plt.plot(x_values, list(array_dh), color='green') #'ro', markersize=1,

#plt.show()
plt.show()

0 comments on commit 4cad99e

Please sign in to comment.