Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Eggimann authored and Sven Eggimann committed Sep 13, 2018
1 parent 9589f2a commit 7b24342
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 124 deletions.
2 changes: 1 addition & 1 deletion energy_demand/assumptions/general_assumptions.py
Expand Up @@ -55,7 +55,7 @@ def __init__(
# or technologies having a spatial explicit diffusion need
# to be defined.
# ============================================================
self.spatial_explicit_diffusion = 1 #0: False, 1: True TODO
self.spatial_explicit_diffusion = 0 #0: False, 1: True TODO

# Define all variables which are affected by regional diffusion
self.spatially_modelled_vars = [] # ['smart_meter_improvement_p']
Expand Down
2 changes: 0 additions & 2 deletions energy_demand/config_data/06-switches/_dummy.txt
@@ -1,8 +1,6 @@
==============
Fuel switches rs_space_heating,heat_pumps_electricity,0.5,2050
==============

TODO:
rs_space_heating,gas,boiler_hydrogen,2050,0.99

test that this is not possbiel (no larger shares than allowed)
Expand Down
6 changes: 5 additions & 1 deletion energy_demand/config_data/06-switches/switches_service.csv
@@ -1,3 +1,7 @@
enduse,tech,service_share_ey,switch_yr,sector
rs_space_heating,heat_pumps_electricity,0.4,2030
rs_space_heating,heat_pumps_electricity,0.6,2050
rs_water_heating,heat_pumps_electricity,0.2,2050
ss_space_heating,heat_pumps_electricity,0.2,2050
ss_water_heating,heat_pumps_electricity,0.2,2050
ss_water_heating,heat_pumps_electricity,0.2,2050
is_space_heating,heat_pumps_electricity,0.2,2050
34 changes: 20 additions & 14 deletions energy_demand/enduse_func.py
Expand Up @@ -137,7 +137,7 @@ def __init__(
assumptions.enduse_space_heating,
assumptions.ss_enduse_space_cooling)
self.fuel_y = _fuel_new_y
logging.debug("FUEL TRAIN B0: " + str(np.sum(self.fuel_y)))
#logging.debug("FUEL TRAIN B0: " + str(np.sum(self.fuel_y)))

_fuel_new_y = apply_smart_metering(
enduse,
Expand All @@ -146,15 +146,15 @@ def __init__(
strategy_vars,
curr_yr)
self.fuel_y = _fuel_new_y
logging.debug("FUEL TRAIN C0: " + str(np.sum(self.fuel_y)))
#logging.debug("FUEL TRAIN C0: " + str(np.sum(self.fuel_y)))

_fuel_new_y = apply_specific_change(
enduse,
self.fuel_y,
strategy_vars,
curr_yr)
self.fuel_y = _fuel_new_y
logging.debug("FUEL TRAIN D0: " + str(np.sum(self.fuel_y)))
#logging.debug("FUEL TRAIN D0: " + str(np.sum(self.fuel_y)))

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

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

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

# Generic fuel switch of an enduse
_fuel_new_y = generic_fuel_switch(
Expand Down Expand Up @@ -1361,22 +1361,28 @@ def calc_service_switch(
):
"""Apply change in service depending on defined service switches.
The service which is fulfilled by new technologies as defined
in the service switches is substracted of the replaced
technologies proportionally to the base year distribution
of these technologies.
The service which is newly fulfilled by new technologies (as defined
in the service switches) is substracted of the replaced
technologies proportionally to their base year contribution.
Arguments
---------
TODO
tot_s_yh_cy : array
Hourly service of all technologies
enduse : str
Enduse
s_tech_y_cy : dict
Service per technology
all_technologies : dict
Technologies to iterate
curr_yr : int
Current year
base_yr : int
Base year
sector : str
Sector
annual_tech_diff_params : dict
Sigmoid technology specific calculated annual diffusion values
crit_switch_happening : bool
Criteria wheter switch is defined or not
Returns
-------
Expand Down Expand Up @@ -1405,7 +1411,7 @@ def calc_service_switch(

for tech in all_technologies:

# Ger service share per tech of cy of sigmoid parameter calculations
# Get service share per tech of cy of sigmoid parameter calculations
p_s_tech_cy = annual_tech_diff_params[enduse][sector][tech][curr_yr]

if p_s_tech_cy == 'identical':
Expand Down
1 change: 0 additions & 1 deletion energy_demand/geography/spatial_diffusion.py
Expand Up @@ -206,7 +206,6 @@ def calc_diffusion_f(regions, f_reg, spatial_diff_values, fuels):

f_reg_norm[enduse] = {}
for region, fuel_p in regions_fuel_p.items():
rounded_val = round(f_reg[region] / sum_p_f_all_regs, 6) #Nr of digits # TODO NEW
f_reg_norm[enduse][region] = f_reg[region] / sum_p_f_all_regs

# ----------
Expand Down
15 changes: 11 additions & 4 deletions energy_demand/initalisations/helpers.py
Expand Up @@ -3,8 +3,13 @@
from collections import defaultdict
from energy_demand.basic import basic_functions

def copy_fractions_all_sectors(fuel_tech_p_by, sectors, affected_enduses):
"""Copy all defined fractions for an enduse to all setors
def copy_fractions_all_sectors(
fuel_tech_p_by,
sectors,
affected_enduses
):
"""Copy all defined fractions
for an enduse to all setors
Arguments
---------
Expand All @@ -13,12 +18,14 @@ def copy_fractions_all_sectors(fuel_tech_p_by, sectors, affected_enduses):
sectors : list
All sectors with this induse where the identical
shares want to be transferred
affected_enduses : list
Enduses for which the values should be copied
Returns
-------
out_dict : dict TODO UPDATE
out_dict : dict
Fuel shares for all sectors
{enduse: {sector: {fueltype: {tech: {share}}}}}
i.e. {enduse: {sector: {fueltype: {tech: {share}}}}}
"""
out_dict = defaultdict(dict)

Expand Down
39 changes: 25 additions & 14 deletions energy_demand/model.py
Expand Up @@ -3,6 +3,7 @@
import logging
from collections import defaultdict
import numpy as np

import energy_demand.enduse_func as endusefunctions
from energy_demand.geography.region import Region
from energy_demand.geography.weather_region import WeatherRegion
Expand All @@ -27,6 +28,7 @@ def __init__(self, regions, data, assumptions):
"""Constructor
"""
logging.info("... start main energy demand function")

self.curr_yr = assumptions.curr_yr

# ----------------------------
Expand All @@ -47,24 +49,22 @@ def __init__(self, regions, data, assumptions):
# ------------------------
# Create Dwelling Stock
# ------------------------
logging.info("... Generate dwelling stocks")
if data['criterias']['virtual_building_stock_criteria']:
logging.info("... Generate virtual dwelling stocks")

# Virtual dwelling stocks
rs_dw_stock, ss_dw_stock = create_virtual_dwelling_stocks(
regions, assumptions.curr_yr, data)

data['dw_stocks'] = {
'residential': rs_dw_stock,
'service': ss_dw_stock,
'industry': None}
data['lookups']['submodels_names'][0]: rs_dw_stock,
data['lookups']['submodels_names'][1]: ss_dw_stock,
data['lookups']['submodels_names'][2]: None}
else:
# Create dwelling stock from imported data from newcastle
data = create_dwelling_stock(
regions, assumptions.curr_yr, data)

logging.info("... finished generating dwelling stock")

# --------------------
# Initialise result container to aggregate results
# --------------------
Expand All @@ -86,13 +86,11 @@ def __init__(self, regions, data, assumptions):
all_submodel_objs = simulate_region(
region, data, assumptions, weather_regions)

# Get specific submodels
reg_rs_submodel = get_all_submodels(all_submodel_objs, 'residential')
reg_ss_submodel = get_all_submodels(all_submodel_objs, 'service')
reg_is_submodel = get_all_submodels(all_submodel_objs, 'industry')

# Store submodel results
all_submodels = [reg_rs_submodel, reg_ss_submodel, reg_is_submodel]
# Collect all submodels with respect to submodel names
all_submodels = []
for submodel in data['lookups']['submodels_names']:
submodels = get_all_submodels(all_submodel_objs, submodel)
all_submodels.append(submodels)

# ---------------------------------------------
# Aggregate results
Expand Down Expand Up @@ -124,7 +122,20 @@ def __init__(self, regions, data, assumptions):
## figure_HHD_gas_demand.main(regions, weather_regions, data)

def get_all_submodels(submodels, submodel_name):
"""TODO
"""Collect all submodel objects for a
specific submodel name
Arguments
---------
submodels : list
All calculated model objects
submodel_name : str
Name of submodels to collect
Returns
-------
specific_submodels : list
Contains all submodels
"""
specific_submodels = []

Expand Down
6 changes: 3 additions & 3 deletions energy_demand/read_write/data_loader.py
Expand Up @@ -729,19 +729,19 @@ def load_fuels(submodels_names, paths, lookups):
enduses, sectors, fuels = {}, {}, {}

# -------------------------------
# submodel_names[0]: Residential SubmodelSubmodel
# submodels_names[0]: Residential SubmodelSubmodel
# -------------------------------
rs_fuel_raw, sectors[submodels_names[0]], enduses[submodels_names[0]] = read_data.read_fuel_rs(
paths['rs_fuel_raw'])

# -------------------------------
# submodel_names[1]: Service Submodel
# submodels_names[1]: Service Submodel
# -------------------------------
ss_fuel_raw, sectors[submodels_names[1]], enduses[submodels_names[1]] = read_data.read_fuel_ss(
paths['ss_fuel_raw'], lookups['fueltypes_nr'])

# -------------------------------
# submodel_names[2]: Industry
# submodels_names[2]: Industry
# -------------------------------
is_fuel_raw, sectors[submodels_names[2]], enduses[submodels_names[2]] = read_data.read_fuel_is(
paths['is_fuel_raw'], lookups['fueltypes_nr'])
Expand Down

0 comments on commit 7b24342

Please sign in to comment.