Skip to content

Commit

Permalink
Merge pull request #96 from nismod/feature/improvements
Browse files Browse the repository at this point in the history
Feature/improvements
  • Loading branch information
eggimasv committed Apr 4, 2018
2 parents 6cc5ebd + 8c6398f commit a38cea7
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 64 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Expand Up @@ -10,3 +10,4 @@ omit =
energy_demand/cli/*
energy_demand/validation/*
energy_demand/plotting/*
energy_demand/processing/*
2 changes: 1 addition & 1 deletion energy_demand/assumptions/assumptions_fuel_shares.py
Expand Up @@ -280,7 +280,7 @@ def assign_by_fuel_tech_p(enduses, sectors, fueltypes, fueltypes_nr):
# ----------------
# Industrial High temporal processes (is_high_temp_process)
# ----------------

# Todays share is about: 17% electric furnace, 82% basic oxygen (Key Statistics 2016, appea, EnergyQuest)
#-- basic_metals (sector)
is_fuel_tech_p_by['is_high_temp_process']['basic_metals'][fueltypes['solid_fuel']] = {
'basic_oxygen_furnace': 1.0}
Expand Down
9 changes: 4 additions & 5 deletions energy_demand/assumptions/non_param_assumptions.py
Expand Up @@ -386,15 +386,14 @@ def __init__(
#BAT - iron & steel - Coke ovens Sectoral share (%)
#BAT - iron & steel - EAF/BOF Sectoral share - EOF %
#BAT - iron & steel - continous/Ingot casting Sectoral share - continuous %
#BAT - iron & steel - cold/hot rolling Sectoral share - cold % #DONE
#BAT - iron & steel - substitute Sectoral share - substitute %
# --------------------------------------------

# Share of cold rolling in steel manufacturing (total = hot and cold)
# *****************
self.p_cold_rolling_steel_by = 0.5 #TODO
self.eff_cold_rolling_process = 1.0 #TODO
self.eff_hot_rolling_process = 1.0 #TODO
# ***************** #BAT - iron & steel - cold/hot rolling
self.p_cold_rolling_steel_by = 0.5 # https://aceroplatea.es/docs/EuropeanSteelFigures_2015.pdf
self.eff_cold_rolling_process = 1.8 # 80% more efficient than hot rolling Fruehan et al. (2002)
self.eff_hot_rolling_process = 1.0 # 100% assumed efficiency

# Steel production - Enduse: is_high_temp_process, Sector: basic_metals
# *****************
Expand Down
8 changes: 4 additions & 4 deletions energy_demand/basic/conversions.py
Expand Up @@ -66,8 +66,8 @@ def gwh_to_ktoe(gwh):
def kwh_to_gwh(kwh):
""""Conversion of MW to GWh
Input
-----
Arguments
---------
kwh : float
Kilowatthours
Expand All @@ -83,8 +83,8 @@ def kwh_to_gwh(kwh):
def mw_to_gwh(megawatt, number_of_hours):
""""Conversion of MW to GWh
Input
-----
Arguments
---------
kwh : float
Kilowatthours
number_of_hours : float
Expand Down
4 changes: 2 additions & 2 deletions energy_demand/cli/__init__.py
Expand Up @@ -46,7 +46,7 @@ def parse_arguments():
parser_init.add_argument(
'-d',
'--local_data',
default='./data_energy_demand',
default='./data',
help='Path to the local data folder')

parser_init.set_defaults(func=post_install_setup)
Expand All @@ -59,7 +59,7 @@ def parse_arguments():
parser_init2.add_argument(
'-d',
'--local_data',
default='./data_energy_demand',
default='./data',
help='Path to the local data folder')

parser_init2.set_defaults(func=post_install_setup_minimum)
Expand Down
6 changes: 3 additions & 3 deletions energy_demand/enduse_func.py
Expand Up @@ -1560,8 +1560,8 @@ def apply_climate_change(
depending on changes in HDD and CDD within a region
(e.g. climate change induced)
Paramters
---------
Arguments
----------
enduse : str
Enduse
fuel_y : array
Expand Down Expand Up @@ -1739,7 +1739,7 @@ def calc_service_switch(
technologies proportionally to the base year distribution
of these technologies.
Paramters
Arguments
---------
tot_s_yh_cy : array
Hourly service of all technologies
Expand Down
12 changes: 4 additions & 8 deletions energy_demand/geography/spatial_diffusion.py
Expand Up @@ -100,7 +100,7 @@ def spatial_diffusion_values(regions, real_values, speed_con_max):
spatial_diff_urban_rural = realdata_to_spatialdiffval(
regions=regions, # Regions
real_values=real_values, # Real values
speed_con_max=speed_con_max) # TODOsomehow not works if set to 1.0 (meanign all value are the same)
speed_con_max=speed_con_max) # TODOsomehow not works if set to 1.0 (meanign all value are the same)

for region in regions:
spatial_diff[region] = spatial_diff_urban_rural[region]
Expand Down Expand Up @@ -352,22 +352,18 @@ def calc_regional_services(
# C.) Calculate regional fraction
# ---------------------------------------------
for tech, service_tech in reg_enduse_tech_p_ey[region].items():

# ----------------------------------
#MAYBE ADD CAPPING VALUE TODO
# ----------------------------------
capping_val = 1

#service_share = service_tech / tot_service_reg_enduse
service_share = service_tech

if service_share > capping_val:
reg_enduse_tech_p_ey[region][tech] = capping_val
logging.warning("CAPPING VALUE REACHED {} {} ".format(region, service_share))
else:
reg_enduse_tech_p_ey[region][tech] = service_share
#OlD
#reg_enduse_tech_p_ey[region][tech] = service_tech / tot_service_reg_enduse

return dict(reg_enduse_tech_p_ey)

Expand Down Expand Up @@ -609,13 +605,13 @@ def factor_improvements_single(
round(np.sum(fuel_regs_enduse[region]),3)))
except:
pass

reg_enduse_tech_p_ey[region] = factor_uk * spatial_factor[region]

logging.info("spatial single factor reg: {} val: {}".format(
region,
round(reg_enduse_tech_p_ey[region],3)))

# ---------
# PROBLEM THAT MORE THAN 100 percent could be reached if nt normed
# ---------
Expand Down
5 changes: 2 additions & 3 deletions energy_demand/model.py
Expand Up @@ -12,9 +12,8 @@
from energy_demand.charts import figure_HHD_gas_demand

class EnergyDemandModel(object):
"""Energy Model of a simulation yearly run.
Main function of energy demand model. All submodels are executed here
and all aggregation functions of the results
""" Main function of energy demand model. All submodels
are executed here and all aggregation functions of the results
Arguments
----------
Expand Down
4 changes: 2 additions & 2 deletions energy_demand/plotting/plotting_results.py
Expand Up @@ -788,8 +788,8 @@ def plt_fuels_enduses_week(
input GWh per h are provided, which cancels out to
GW.
Input
-----
Arguments
---------
year_to_plot : int
2015 --> 0
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions energy_demand/profiles/load_profile.py
Expand Up @@ -595,8 +595,8 @@ def calc_av_lp(demand_yh, seasons, model_yeardays_daytype):
def calc_yh(shape_yd, shape_y_dh, model_yeardays):
"""Calculate the shape based on yh and y_dh shape
Inputs
-------
Arguments
---------
shape_yd : array
Shape with fuel amount for every day (365)
shape_y_dh : array
Expand Down
4 changes: 2 additions & 2 deletions energy_demand/scripts/init_scripts.py
Expand Up @@ -183,7 +183,6 @@ def scenario_initalisation(path_data_ed, data=False):
# ===========================================
if data['criterias']['spatial_exliclit_diffusion']:

#TODO MAYBE f_reg enduse region specific
f_reg, f_reg_norm, f_reg_norm_abs = spatial_diffusion.calc_spatially_diffusion_factors(
regions=data['regions'],
fuel_disagg=fuel_disagg,
Expand All @@ -193,7 +192,8 @@ def scenario_initalisation(path_data_ed, data=False):
# ---------------------
# Plot figure for paper
# ---------------------
plot_fig_paper = True
plot_fig_paper = True #FALSE
plot_fig_paper = False #FALSE
if plot_fig_paper:

# Global value to distribute
Expand Down
12 changes: 4 additions & 8 deletions energy_demand/scripts/s_disaggregation.py
Expand Up @@ -323,12 +323,9 @@ def ss_disaggr(
# logging.debug(" ... Disaggregation ss: populaton, HDD, floor_area")
# ----
if enduse == 'ss_cooling_humidification':
#reg_diasg_factor = (reg_pop * reg_cdd) / tot_pop_cdd[sector]
reg_diasg_factor = (reg_floor_area * reg_cdd) / tot_floor_area_cdd[sector] #TODO TEST IF REALLY BETTER
#reg_diasg_factor = reg_floor_area / tot_floor_area[sector]
reg_diasg_factor = (reg_floor_area * reg_cdd) / tot_floor_area_cdd[sector]
elif enduse == 'ss_space_heating':
reg_diasg_factor = (reg_floor_area * reg_hdd) / tot_floor_area_hdd[sector] #TODO TEST IF REALLY BETTER
reg_diasg_factor = reg_floor_area / tot_floor_area[sector] #Best (better than if including hdd)
reg_diasg_factor = (reg_floor_area * reg_hdd) / tot_floor_area_hdd[sector]
elif enduse == 'ss_lighting':
reg_diasg_factor = reg_floor_area / tot_floor_area[sector]
else:
Expand Down Expand Up @@ -678,11 +675,10 @@ def rs_disaggr(
elif crit_full_disagg:

# -------------------
#logging.warning(" ... Disaggregation rss: populaton, hdd, floor_area")
#logging.debug(" ... Disaggregation rss: populaton, hdd, floor_area")
# -------------------
if enduse == 'rs_space_heating':
reg_diasg_factor = (reg_hdd * reg_floor_area) / total_hdd_floorarea #TODO TEST IF REALLY BETTER
#reg_diasg_factor = reg_floor_area / total_floor_area
reg_diasg_factor = (reg_hdd * reg_floor_area) / total_hdd_floorarea
elif enduse == 'rs_lighting':
reg_diasg_factor = reg_floor_area / total_floor_area
else:
Expand Down
13 changes: 3 additions & 10 deletions energy_demand/scripts/s_generate_sigmoid.py
Expand Up @@ -560,23 +560,19 @@ def tech_sigmoid_parameters(
xdata = np.array([point_x_by, point_x_ey])
ydata = np.array([point_y_by, point_y_ey])

logging.info(
'''logging.info(
"... create sigmoid diffusion %s - %s - %s - %s - l_val: %s - %s - %s",
tech,
xdata,
ydata,
fit_assump_init,
l_values[tech],
point_y_by, point_y_ey)
point_y_by, point_y_ey)'''

# Test if end year share is larger than technological maximum
logging.info("----------")
logging.info(ydata[1])
logging.info(l_values[tech])

# Test wheter maximum diffusion is larger than simulated end year share
assert ydata[1] <= l_values[tech] + linear_approx_crit

# If no change in by to ey but not zero (lineare change)
if (round(point_y_by, rounding_accuracy) == round(point_y_ey, rounding_accuracy)) and (
point_y_ey != fit_assump_init) and (
Expand Down Expand Up @@ -612,7 +608,6 @@ def tech_sigmoid_parameters(
fit_assump_init=fit_assump_init,
error_range=error_range)

# Insert parameters
sig_params[tech]['midpoint'] = fit_parameter[0] # midpoint (x0)
sig_params[tech]['steepness'] = fit_parameter[1] # Steepnes (k)
sig_params[tech]['l_parameter'] = l_values[tech] # maximum p
Expand All @@ -628,15 +623,13 @@ def tech_sigmoid_parameters(
plot_crit=True,
close_window_crit=True)
except:

"""If sigmoid fitting failed, implement linear diffusion
The sigmoid diffusion may fail if the fitting does not work
because the points to fit are too similar.
"""
logging.warning(
"Instead of sigmoid a linear approximation is used %s %s", xdata, ydata)
prnt(".")
sig_params[tech]['midpoint'] = 'linear'
sig_params[tech]['steepness'] = 'linear'
sig_params[tech]['l_parameter'] = 'linear'
Expand Down
8 changes: 4 additions & 4 deletions energy_demand/scripts/s_post_installation.py
Expand Up @@ -34,10 +34,10 @@ def post_install_setup(args):
path_results = resource_filename(Requirement.parse("energy_demand"), "results")
local_data_path = args.local_data

# Initialise logger
logger_setup.set_up_logger(
os.path.join(local_data_path, "logging_post_install_setup.log"))
logging.info("... start local energy demand calculations")
# Initialise logger TODO
#logger_setup.set_up_logger(
# os.path.join(local_data_path, "logging_post_install_setup.log"))
#logging.info("... start local energy demand calculations")

# Load data
base_yr = 2015
Expand Down
8 changes: 2 additions & 6 deletions energy_demand/technologies/diffusion_technologies.py
Expand Up @@ -38,9 +38,9 @@ def linear_diff(base_yr, curr_yr, value_start, value_end, yr_until_changed):
return fract_cy

def sigmoid_function(x_value, l_value, midpoint, steepness):
"""Sigmoid function
"""Sigmoid function used for fitting and plotting.
Paramters
Arguments
---------
x_value : float
X-Value
Expand All @@ -56,10 +56,6 @@ def sigmoid_function(x_value, l_value, midpoint, steepness):
y-value : float
Y-Value
Notes
-----
This function is used for fitting and plotting.
Warning
-------
Because 2000 is substracted, the start year can not be before 2001.
Expand Down
8 changes: 4 additions & 4 deletions energy_demand/technologies/tech_related.py
Expand Up @@ -187,8 +187,8 @@ def eff_heat_pump(temp_diff, efficiency_intersect, m_slope=-.08, h_diff=10):
def get_fueltype_str(fueltype_lu, fueltype_nr):
"""Read from dict the fueltype string based on fueltype KeyError
Inputs
------
Arguments
---------
fueltype : dict
Fueltype lookup dictionary
fueltype_nr : int
Expand All @@ -206,8 +206,8 @@ def get_fueltype_str(fueltype_lu, fueltype_nr):
def get_fueltype_int(fueltypes, fueltype_string):
"""Read from dict the fueltype string based on fueltype KeyError
Inputs
------
Arguments
---------
fueltype : dict
Fueltype lookup dictionary
fueltype_string : int
Expand Down

0 comments on commit a38cea7

Please sign in to comment.