Skip to content

Commit

Permalink
before new release
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Eggimann committed Feb 27, 2019
1 parent 0ca72f6 commit 4805acb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 66 deletions.
3 changes: 3 additions & 0 deletions energy_demand/assumptions/fuel_shares.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def assign_by_fuel_tech_p(
'district_heating_CHP_gas': 0.03}

fuel_tech_p_by['rs_space_heating'][fueltypes['electricity']] = {
'district_heating_electricity' : 0,
'storage_heater_electricity': 0.62,
'secondary_heater_electricity':0.33,
'heat_pumps_electricity': 0.05}
Expand Down Expand Up @@ -222,6 +223,7 @@ def assign_by_fuel_tech_p(
'boiler_gas': 0.38}

fuel_tech_p_by['ss_space_heating'][fueltypes['electricity']] = {
'district_heating_electricity' : 0,
'secondary_heater_electricity': 0.95,
'heat_pumps_electricity': 0.05}

Expand Down Expand Up @@ -300,6 +302,7 @@ def assign_by_fuel_tech_p(
'boiler_gas': 0.38}

fuel_tech_p_by['is_space_heating'][fueltypes['electricity']] = {
'district_heating_electricity' : 0,
'secondary_heater_electricity': 0.95,
'heat_pumps_electricity': 0.05,
'storage_heater_electricity': 0}
Expand Down
34 changes: 6 additions & 28 deletions energy_demand/enduse_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def __init__(
self.enduse_techs = []
else:
#print("------INFO {} {} {} {}".format(self.enduse, sector, region, curr_yr))
#print("FUEL TRAIN A0: " + str(np.sum(self.fuel_y)))

# Get technologies of enduse
self.enduse_techs = get_enduse_techs(fuel_tech_p_by)
Expand All @@ -141,7 +140,6 @@ def __init__(
assumptions.enduse_space_heating,
assumptions.ss_enduse_space_cooling)
self.fuel_y = _fuel_new_y
#print("FUEL TRAIN B0: " + str(np.sum(self.fuel_y)))

_fuel_new_y = apply_smart_metering(
enduse,
Expand All @@ -150,7 +148,6 @@ def __init__(
strategy_vars,
curr_yr)
self.fuel_y = _fuel_new_y
#print("FUEL TRAIN C0: " + str(np.sum(self.fuel_y)))

_fuel_new_y = generic_demand_change(
enduse,
Expand All @@ -159,7 +156,6 @@ def __init__(
strategy_vars['generic_enduse_change'],
curr_yr)
self.fuel_y = _fuel_new_y
#print("FUEL TRAIN D0: " + str(np.sum(self.fuel_y)))

_fuel_new_y = apply_scenario_drivers(
enduse=enduse,
Expand All @@ -174,7 +170,6 @@ def __init__(
base_yr=base_yr,
curr_yr=curr_yr)
self.fuel_y = _fuel_new_y
#print("FUEL TRAIN E0: " + str(np.sum(self.fuel_y)))

# Apply cooling scenario variable
_fuel_new_y = apply_cooling(
Expand All @@ -184,7 +179,6 @@ def __init__(
assumptions.cooled_ss_floorarea_by,
curr_yr)
self.fuel_y = _fuel_new_y
#print("FUEL TRAIN E1: " + str(np.sum(self.fuel_y)))

# Industry related change
_fuel_new_y = industry_enduse_changes(
Expand All @@ -195,7 +189,6 @@ def __init__(
self.fuel_y,
assumptions)
self.fuel_y = _fuel_new_y
#print("FUEL TRAIN E2: " + str(np.sum(self.fuel_y)))

# Generic fuel switch of an enduse and sector
_fuel_new_y = generic_fuel_switch(
Expand All @@ -206,7 +199,7 @@ def __init__(
strategy_vars['generic_fuel_switch'],
self.fuel_y)
self.fuel_y = _fuel_new_y
#print("FUEL TRAIN E3: " + str(np.sum(self.fuel_y)))

# ----------------------------------
# Hourly Disaggregation
# ----------------------------------
Expand All @@ -224,21 +217,13 @@ def __init__(
self.fuel_y,
make_all_flat=make_all_flat)

#print("FUEL TRAIN X " + str(np.sum(fuel_yh)))
# Demand management for non-technology enduse
self.fuel_yh = load_shifting(
enduse,
fuel_yh,
mode_constrained=False,
param_lf_improved_cy=strategy_vars['dm_improvement'][enduse][curr_yr],
make_all_flat=make_all_flat)
#print("FUEL TRAIN Y" + str(np.sum(fuel_yh)))

#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 All @@ -260,8 +245,7 @@ def __init__(
tech_stock,
fueltypes,
mode_constrained)
#print(np.sum(s_tot_y_cy))
#print(np.sum(list(s_tech_y_by.values()))) #NEW

# ------------------------------------
# Reduction of service because of heat recovery
# ------------------------------------
Expand All @@ -271,8 +255,7 @@ def __init__(
s_tot_y_cy,
s_tech_y_by,
curr_yr)
#print(np.sum(s_tot_y_cy))
#print(np.sum(list(s_tech_y_cy.values()))) #NEW

# ------------------------------------
# Reduction of service because of improvement in air leakeage
# ------------------------------------
Expand All @@ -282,8 +265,7 @@ def __init__(
s_tot_y_cy,
s_tech_y_cy,
curr_yr)
#print(np.sum(s_tot_y_cy))
#print(np.sum(list(s_tech_y_cy.values()))) #NEW

# --------------------------------
# Switches
# --------------------------------
Expand All @@ -296,13 +278,10 @@ def __init__(
sector=sector,
annual_tech_diff_params=strategy_vars['annual_tech_diff_params'][enduse][sector],
crit_switch_happening=assumptions.crit_switch_happening)
#print(np.sum(s_tot_y_cy))
#print(np.sum(list(s_tech_y_cy.values()))) #NEW

# -------------------------------------------
# Convert annual service to fuel per fueltype
# -------------------------------------------
#print("--")
#print(np.sum(self.fuel_y))
self.fuel_y, fuel_tech_y = service_to_fuel(
enduse,
sector,
Expand All @@ -311,7 +290,7 @@ def __init__(
fueltypes_nr,
fueltypes,
mode_constrained)
#print("B" + str(np.sum(self.fuel_y)))

# Delete all technologies with no fuel assigned
for tech, fuel_tech in fuel_tech_y.items():
if np.sum(fuel_tech) == 0:
Expand Down Expand Up @@ -878,7 +857,6 @@ def calc_fuel_tech_yh(
enduse, sector, tech, 'shape_yh')

fuels_yh[tech] = fuel_tech_y[tech] * load_profile

else:
# --
# Unconstrained mode, i.e. not technolog specific.
Expand Down
61 changes: 33 additions & 28 deletions energy_demand/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,11 +538,11 @@ def get_fuels_yh(enduse_object, attribute_to_get):

return fuels

def aggr_complete_result(
'''def aggr_complete_result(
full_result_aggr,
lookup_enduses,
reg_array_nr,
sector_models,
all_submodels,
technologies
):
"""Aggregate full results (except technology specific)
Expand All @@ -553,7 +553,7 @@ def aggr_complete_result(
Dict to aggregat with form: submodel, enduse, region, fueltype, 8760 hours
reg_array_nr : int
Region number
sector_models : list
all_submodels : list
Sector models objects in list
technologies : dict
Technologies
Expand All @@ -563,7 +563,7 @@ def aggr_complete_result(
full_result_aggr : dict
Full result aggregation dict
"""
for model_object in sector_models:
for model_object in all_submodels:
fuels = get_fuels_yh(model_object, 'techs_fuel_yh')
enduse_array_nr = lookup_enduses[model_object.enduse]
Expand All @@ -580,7 +580,7 @@ def aggr_complete_result(
for fueltype_nr, fuels_8760 in enumerate(fueltype_yh_8760):
full_result_aggr[enduse_array_nr][fueltype_nr][reg_array_nr] += fuels_8760
return full_result_aggr
return full_result_aggr'''

def averaged_season_hourly(
fueltype_region_yh,
Expand Down Expand Up @@ -812,33 +812,25 @@ def aggregate_results_constrained(
aggr_results : dict
Contains all aggregated results
"""
#Convert generator into list #TODO TOM
all_submodels = list(all_submodels)

aggr_results['ed_submodel_enduse_fueltype_regs_yh'] = aggr_complete_result(
aggr_results['ed_submodel_enduse_fueltype_regs_yh'],
lookup_enduses,
reg_array_nr,
all_submodels,
technologies)
# Get enduse number for enduse
submodel_to_idx = {
name: idx
for idx, name in enumerate(lookup_tables.basic_lookups()['submodels_names'])
}

if mode_constrained:
submodel_to_idx = {
name: idx
for idx, name in enumerate(lookup_tables.basic_lookups()['submodels_names'])
}
# Iterate all simulation results
for enduse_object in all_submodels:
techs_fueltypes_yh = get_fuels_yh(enduse_object, 'techs_fuel_yh')
enduse_array_nr = lookup_enduses[enduse_object.enduse]
submodel_nr = submodel_to_idx[enduse_object.submodel_name]

# -----------------------------------------------------------------
# Aggregate fuel of constrained technologies for heating
# -----------------------------------------------------------------
for enduse_object in all_submodels:
submodel_nr = submodel_to_idx[enduse_object.submodel_name]

# Aggregate only over heating technologies
if mode_constrained:
if enduse_object.enduse in enduse_space_heating:

techs_fueltypes_yh = get_fuels_yh(enduse_object, 'techs_fuel_yh')

# All used heating technologies
heating_techs = enduse_object.enduse_techs

Expand All @@ -851,11 +843,24 @@ def aggregate_results_constrained(
if heating_tech in aggr_results['results_constrained'].keys():
aggr_results['results_constrained'][heating_tech][submodel_nr][reg_array_nr][fueltype_tech_int] += tech_fuel.reshape(8760)
else:
# TODO query this - are we overwriting otherwise
#if heating_tech not in aggr_results['results_constrained']:
# aggr_results['results_constrained'][heating_tech] = np.zeros((len(submodel_to_idx), reg_nrs, fueltypes_nr, 8760), dtype="float")
aggr_results['results_constrained'][heating_tech] = np.zeros((len(submodel_to_idx), reg_nrs, fueltypes_nr, 8760), dtype="float")
aggr_results['results_constrained'][heating_tech][submodel_nr][reg_array_nr][fueltype_tech_int] += tech_fuel.reshape(8760)
aggr_results['results_constrained'][heating_tech][submodel_nr][reg_array_nr][fueltype_tech_int] = tech_fuel.reshape(8760)

# -----------------------------------------------------------------
# Aggregate fuel of all technologies
# -----------------------------------------------------------------
if isinstance(techs_fueltypes_yh, dict):
for tech, fuel_tech in techs_fueltypes_yh.items():
tech_fueltype = technologies[tech].fueltype_int
aggr_results['ed_submodel_enduse_fueltype_regs_yh'][enduse_array_nr][tech_fueltype][reg_array_nr] += fuel_tech.reshape(8760)
else:
fueltype_yh_365_24 = get_fuels_yh(enduse_object, 'fuel_yh')

# Iterate over fueltype and add to region
fueltype_yh_8760 = fueltype_yh_365_24.reshape(fueltype_yh_365_24.shape[0], 8760)

for fueltype_nr, fuels_8760 in enumerate(fueltype_yh_8760):
aggr_results['ed_submodel_enduse_fueltype_regs_yh'][enduse_array_nr][fueltype_nr][reg_array_nr] += fuels_8760

return aggr_results

Expand Down
10 changes: 0 additions & 10 deletions energy_demand/plotting/fig3_weather_at_home_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,6 @@ def plotting_weather_data(path):
color=colors['t_max_max'],
alpha=0.25)

print("AAAAAAAA")
print(list(std_dev_t_max_max))
print(list(np.array(t_max_max_every_day)))
print(list(np.array(t_max_max_every_day) - (2 * np.array(std_dev_t_max_max))))
print("--")
print(list(std_dev_t_min_min))
print(list(np.array(t_min_min_every_day)))
print(list(np.array(t_min_min_every_day) - (2 * np.array(std_dev_t_min_min))))


# Legend
legend = plt.legend(
ncol=2,
Expand Down

0 comments on commit 4805acb

Please sign in to comment.