Skip to content

Commit

Permalink
updated fuel switch from str to int
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Eggimann committed Dec 7, 2018
1 parent c3a8e48 commit e092f66
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 44 deletions.
10 changes: 6 additions & 4 deletions energy_demand/enduse_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -1584,12 +1584,14 @@ def generic_fuel_switch(
if fuel_switch[curr_yr] != 0:

# Get fueltype to switch (old)
fueltype_replace_str = fuel_switch['param_info']['fueltype_replace']
fueltype_replace_int = tech_related.get_fueltype_int(fueltype_replace_str)
#fueltype_replace_str = fuel_switch['param_info']['fueltype_replace']
#fueltype_replace_int = tech_related.get_fueltype_int(fueltype_replace_str)
fueltype_replace_int = int(fuel_switch['param_info']['fueltype_replace'])

# Get fueltype to switch to (new)
fueltype_new_str = fuel_switch['param_info']['fueltype_new']
fueltype_new_int = tech_related.get_fueltype_int(fueltype_new_str)
#fueltype_new_str = fuel_switch['param_info']['fueltype_new']
#fueltype_new_int = tech_related.get_fueltype_int(fueltype_new_str)
fueltype_new_int = int(fuel_switch['param_info']['fueltype_new'])

# Value of current year
fuel_share_switched_cy = fuel_switch[curr_yr]
Expand Down
24 changes: 13 additions & 11 deletions energy_demand/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def energy_demand_model(
user_defined_simulation_end_yr = config['CONFIG']['user_defined_simulation_end_yr']

# Simulated yrs
#sim_yrs = [base_yr, user_defined_simulation_end_yr]
sim_yrs = [2015, 2025, 2035, 2045, 2050]
sim_yrs = [base_yr, user_defined_simulation_end_yr]
#sim_yrs = [2015, 2025, 2035, 2045, 2050]
weather_yr_scenario = 2015 # Default weather year

if len(sys.argv) > 1: #user defined arguments are provide
Expand All @@ -125,18 +125,17 @@ def energy_demand_model(

local_scenario = 'pop-baseline16_econ-c16_fuel-c16' #pop-f_econ-c_fuel-c #pop-b_econ-c_fuel-c
name_config_path = 'high_electrification'
name_config_path = 'low_electrification'
name_config_path = 'h_l'

path_strategy_vars = os.path.join(local_data_path, 'energy_demand', '00_user_defined_variables', 'default')
#path_strategy_vars = os.path.join(local_data_path, 'energy_demand', '00_user_defined_variables', 'name_config_path')
path_strategy_vars = os.path.join(local_data_path, 'energy_demand', '00_user_defined_variables', 'high_electrification')
path_strategy_vars = os.path.join(local_data_path, 'energy_demand', '00_user_defined_variables', name_config_path)

# --- Region definition configuration
name_region_set = os.path.join(local_data_path, 'energy_demand', 'region_definitions', "lad_2016_uk_simplified.shp")
name_population_dataset = os.path.join(local_data_path, 'scenarios', 'MISTRAL_pop_gva', 'data', '{}/population__lad.csv'.format(local_scenario))
name_gva_dataset = os.path.join(local_data_path, 'scenarios', 'MISTRAL_pop_gva', 'data', '{}/gva_per_head__lad_sector.csv'.format(local_scenario))
name_gva_dataset_per_head = os.path.join(local_data_path, 'scenarios', 'MISTRAL_pop_gva', 'data', '{}/gva_per_head__lad.csv'.format(local_scenario))

#simulation_name = str(weather_realisation) + "__" + "all_stations"
simulation_name = "simulation_results"

name_scenario_run = "{}_result_local_{}".format(scenario_name, str(time.ctime()).replace(":", "_").replace(" ", "_"))
Expand All @@ -160,7 +159,6 @@ def energy_demand_model(
# Load data
# ----------------------------------------------------------------------
data['scenario_data'] = defaultdict(dict)
print(data['paths'])
data['enduses'], data['sectors'], data['fuels'], lookup_enduses, lookup_sector_enduses = data_loader.load_fuels(data['paths'])

data['regions'] = read_data.get_region_names(name_region_set)
Expand Down Expand Up @@ -353,7 +351,10 @@ def energy_demand_model(
# ------------------------------------------------
service_switches_raw = pd.read_csv(os.path.join(data['local_paths']['path_strategy_vars'], "switches_service.csv"))
service_switches = read_data.service_switch(service_switches_raw)

print(".---------")
for i in service_switches:
print(i.__dict__)
#raise Exception("FF")
fuel_switches = read_data.read_fuel_switches(os.path.join(data['local_paths']['path_strategy_vars'], "switches_fuel.csv"), data['enduses'], data['assumptions'].fueltypes, data['assumptions'].technologies)
capacity_switches = read_data.read_capacity_switch(os.path.join(data['local_paths']['path_strategy_vars'], "switches_capacity.csv"))

Expand All @@ -372,9 +373,10 @@ def energy_demand_model(
f_reg_norm,
f_reg_norm_abs,
crit_all_the_same,
fuel_switches,
service_switches,
capacity_switches)
service_switches=service_switches,
fuel_switches=fuel_switches,
capacity_switches=capacity_switches)

for region in data['regions']:
regional_vars[region]['annual_tech_diff_params'] = annual_tech_diff_params[region]

Expand Down
18 changes: 6 additions & 12 deletions energy_demand/plotting/fig_3_weather_map.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@

import os
import logging
import copy
import math
import numpy as np
import geopandas as gpd
import pandas as pd
import palettable
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from matplotlib.patches import Circle
from matplotlib.colors import LinearSegmentedColormap
from collections import defaultdict

from energy_demand.plotting import fig_p2_weather_val, result_mapping
from energy_demand.basic import basic_functions
Expand All @@ -34,8 +29,12 @@ def total_annual_demand(
"""
if unit == 'GW':
conversion_factor = 1
if unit == 'kWh':
elif unit == 'kW':
conversion_factor = conversions.gwh_to_kwh(gwh=1) #GW to KW
elif unit == 'percentage':
conversion_factor = 1
else:
raise Exception("Not defined unit")

df_data_input = df_data_input * conversion_factor

Expand Down Expand Up @@ -137,12 +136,7 @@ def total_annual_demand(
# plot with face color attribute
uk_gdf.plot(ax=ax, facecolor=uk_gdf['bin_color'], edgecolor='black', linewidth=0.5)

#shp_gdp_merged.plot(column='diff_av_max', scheme='QUANTILES', k=5, cmap='OrRd', linewidth=0.1)
#ax = uk_gdf.plot(column='diff_av_max', scheme='QUANTILES', k=5, cmap='OrRd', linewidth=0.1)
#uk_gdf[uk_gdf['name'] == 'E06000024'].plot(ax=ax, facecolor='green', edgecolor='black')
#uk_gdf[uk_gdf['diff_av_max'] < 0.01].plot(ax=ax, facecolor='blue', edgecolor='black')

# Get legend patches TODO IMPROVE
# TODO IMRPVE: MAKE CORRECT ONE FOR NEW PROCESSING
legend_handles = result_mapping.get_legend_handles(
bin_values[1:-1],
Expand Down Expand Up @@ -175,7 +169,7 @@ def total_annual_demand(
# --------
# Labeling
# --------
#plt.title("tttt")
plt.title("Peak demand over time")

plt.tight_layout()
#plt.show()
Expand Down
21 changes: 13 additions & 8 deletions energy_demand/read_write/read_weather_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
"""
import os
import logging
import numpy as np

from energy_demand.read_write import data_loader, read_data
from energy_demand.basic import date_prop
from energy_demand.plotting import plotting_results, result_mapping
from energy_demand.basic import basic_functions
from energy_demand.basic import lookup_tables
from energy_demand.read_write import read_data
from energy_demand.technologies import tech_related

def read_in_weather_results(
path_result,
seasons,
model_yeardays_daytype
model_yeardays_daytype,
fueltype_str
):
"""Read and post calculate results from txt files
and store into container
Expand All @@ -30,7 +27,7 @@ def read_in_weather_results(
"""
logging.info("... Reading in results")

fueltype_int = tech_related.get_fueltype_int('electricity')
fueltype_int = tech_related.get_fueltype_int(fueltype_str)


results_container = {}
Expand All @@ -53,18 +50,26 @@ def read_in_weather_results(
print(results_container['ed_reg_peakday'][2015].shape)
results_container['ed_reg_peakday_peak_hour'] = {}
results_container['national_peak'] = {}
results_container['regional_share_national_peak'] = {}

for year in results_container['ed_reg_peakday']:

# Get peak demand of each region
results_container['ed_reg_peakday_peak_hour'][year] = results_container['ed_reg_peakday'][year].max(axis=2)

# Get national peak
national_demand_per_hour = results_container['ed_reg_peakday'][year].sum(axis=1) #Aggregate houraly across all regions
national_demand_per_hour = results_container['ed_reg_peakday'][year].sum(axis=1) #Aggregate hourly across all regions

# Get maximum hour for electricity demand
max_hour = national_demand_per_hour[fueltype_int].argmax()

results_container['national_peak'][year] = national_demand_per_hour[:, max_hour]

# Calculate regional share of peak hour to national peak
national_peak = results_container['national_peak'][year][fueltype_int]
regional_peak = results_container['ed_reg_peakday'][year][fueltype_int][:, max_hour]
results_container['regional_share_national_peak'][year] = (100 / national_peak) * regional_peak #1 = 1 %


logging.info("... Reading in results finished")
return results_container
43 changes: 38 additions & 5 deletions energy_demand/result_processing/weather_result_charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def main(
total_regional_demand = pd.DataFrame()
peak_hour_demand = pd.DataFrame()
national_peak = pd.DataFrame()

regional_share_national_peak = pd.DataFrame()

for path_result_folder in paths_folders_result:
print("path_result_folder: " + str(path_result_folder))

Expand Down Expand Up @@ -115,7 +116,8 @@ def main(
results_container = read_weather_results.read_in_weather_results(
data['result_paths']['data_results_model_runs'],
data['assumptions']['seasons'],
data['assumptions']['model_yeardays_daytype'])
data['assumptions']['model_yeardays_daytype'],
fueltype_str='electricity')

# --Total demand (dataframe with row: realisation, column=region)
realisation_data = pd.DataFrame(
Expand All @@ -139,13 +141,20 @@ def main(
columns=data['assumptions']['sim_yrs'])
national_peak = national_peak.append(realisation_data)

# --Regional percentage of national peak demand
realisation_data = pd.DataFrame(
[results_container['regional_share_national_peak'][simulation_yr_to_plot]],
columns=data['regions'])

regional_share_national_peak = regional_share_national_peak.append(realisation_data)

# Add to scenario container
scenario_result_container.append({
'scenario_name': scenario_name,
'total_regional_demand': total_regional_demand,
'peak_hour_demand': peak_hour_demand,
'national_peak': national_peak
'national_peak': national_peak,
'regional_share_national_peak': regional_share_national_peak
})

plotting_dict_info = {}
Expand All @@ -160,14 +169,14 @@ def main(
fig_name="scenarios_peak_over_time_{}.pdf".format(fueltype_str),
result_path=result_path)


# ------------------------------
# Plotting spatial results
# ------------------------------
for i in scenario_result_container:
scenario_name = i['scenario_name']
total_regional_demand = i['total_regional_demand']
peak_hour_demand = i['peak_hour_demand']
regional_share_national_peak = i['regional_share_national_peak']

print("... plot spatial map of total annual demand")
field_to_plot = 'std_dev'
Expand All @@ -191,10 +200,34 @@ def main(
pop_data=pop_data,
simulation_yr_to_plot=simulation_yr_to_plot,
result_path=result_path,
fig_name="{}peak_h_demand_{}_{}.pdf".format(scenario_name, field_to_plot, fueltype_str),
fig_name="{}_peak_h_demand_{}_{}.pdf".format(scenario_name, field_to_plot, fueltype_str),
field_to_plot=field_to_plot,
unit='GW')

print("... plot spatial map of percentage of regional peak hour demand")
field_to_plot = 'mean'
fig_3_weather_map.total_annual_demand(
regional_share_national_peak,
path_shapefile_input,
data['regions'],
pop_data=pop_data,
simulation_yr_to_plot=simulation_yr_to_plot,
result_path=result_path,
fig_name="{}_regional_share_national_peak_{}_{}.pdf".format(scenario_name, field_to_plot, fueltype_str),
field_to_plot=field_to_plot,
unit='percentage')

field_to_plot = 'std_dev'
fig_3_weather_map.total_annual_demand(
regional_share_national_peak,
path_shapefile_input,
data['regions'],
pop_data=pop_data,
simulation_yr_to_plot=simulation_yr_to_plot,
result_path=result_path,
fig_name="{}_regional_share_national_peak_{}_{}.pdf".format(scenario_name, field_to_plot, fueltype_str),
field_to_plot=field_to_plot,
unit='percentage')

print("===================================")
print("... finished reading and plotting results")
Expand Down
2 changes: 1 addition & 1 deletion energy_demand/technologies/fuel_service_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def autocomplete_switches(
Criteria wheter regionally specific or not
regions : list
Regions
f_diffusion :
f_diffusion : TODO
techs_affected_spatial_f :
service_switches_from_capacity : list, default=[]
Service switches stemming from capacity switches
Expand Down
6 changes: 3 additions & 3 deletions energy_demand/wrapper_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ def before_simulation(
f_reg_norm,
f_reg_norm_abs,
crit_all_the_same,
service_switches,
fuel_switches,
capacity_switches)
service_switches=service_switches,
fuel_switches=fuel_switches,
capacity_switches=capacity_switches)

for region in data['regions']:
regional_vars[region]['annual_tech_diff_params'] = annual_tech_diff_params[region]
Expand Down

0 comments on commit e092f66

Please sign in to comment.