Skip to content

Commit

Permalink
- moved procesing files to own folder
Browse files Browse the repository at this point in the history
- corrected readthedocs
- improve tests
  • Loading branch information
Sven Eggimann committed Apr 4, 2018
1 parent 6cc5ebd commit b85d1b9
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 51 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ omit =
energy_demand/cli/*
energy_demand/validation/*
energy_demand/plotting/*
energy_demand/processing/*
8 changes: 4 additions & 4 deletions energy_demand/basic/conversions.py
Original file line number Diff line number Diff line change
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
6 changes: 3 additions & 3 deletions energy_demand/enduse_func.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
1 change: 0 additions & 1 deletion energy_demand/scripts/init_scripts.py
Original file line number Diff line number Diff line change
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 Down
12 changes: 4 additions & 8 deletions energy_demand/scripts/s_disaggregation.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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: 2 additions & 6 deletions energy_demand/technologies/diffusion_technologies.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 b85d1b9

Please sign in to comment.