Skip to content

Commit

Permalink
working on plot for min and max day
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Eggimann authored and Sven Eggimann committed Jul 18, 2018
1 parent 6cd6a04 commit d895280
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
40 changes: 37 additions & 3 deletions energy_demand/charts/resilience_multiple_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import csv
import os
from collections import defaultdict
from energy_demand.plotting import plotting_styles
import matplotlib.pyplot as plt
from energy_demand.plotting import plotting_styles
from energy_demand.plotting import plotting_results
from energy_demand.plotting import plotting_program
from energy_demand.read_write import write_data
Expand All @@ -30,6 +30,22 @@ def read_csv_max_min(path_to_csv):

return out_dict

def read_csv_average(path_to_csv):
"""read average value from csv
"""
out_dict = {}
with open(path_to_csv, 'r') as csvfile:
rows = csv.reader(csvfile, delimiter=',')

for row in rows:
out_dict["name"] = row
break
for row in rows:
out_dict["average_value"] = row[0]
break

return out_dict

def generate_min_max_resilience_plot(path_to_scenarios):
# Iterate result folder

Expand All @@ -49,7 +65,7 @@ def generate_min_max_resilience_plot(path_to_scenarios):
# Read in min and max day
# ----
path_fist_scenario = os.path.join(path_to_scenarios, scenario)

data_container[scenario] = defaultdict(dict)

# Folders with Resilience min and max day
Expand All @@ -59,8 +75,15 @@ def generate_min_max_resilience_plot(path_to_scenarios):

# Get all max day files
for result_file in result_files:

if result_file.split("__")[0] != 'result_day':
pass

# Get average value from file
if result_file == 'average_nr.csv':
average_demands_dict = read_csv_average(os.path.join(result_folder, result_file))
average_demands_by = float(average_demands_dict['average_value'])
else:
pass
else:
if result_file.split("__")[0] == 'result_day' and result_file.split("__")[1] == 'max':
dict_values = read_csv_max_min(os.path.join(result_folder, result_file))
Expand All @@ -75,6 +98,7 @@ def generate_min_max_resilience_plot(path_to_scenarios):
data_container[scenario][year]['min_values'] = dict_values['values_list']
data_container[scenario][year]['min_yearday'] = dict_values['yearday']
data_container[scenario][year]['min_date'] = dict_values['date']

# ------------------
# Calculate statistics
# --------------------
Expand All @@ -87,6 +111,10 @@ def generate_min_max_resilience_plot(path_to_scenarios):
data_container[scenario][year]['max_date'],
data_container[scenario][year]['min_date']))

# Average demand of base year

flat_y_data = 24 * [average_demands_by]

# ------------------
# Write statiscs to txt
# --------------------
Expand Down Expand Up @@ -123,6 +151,9 @@ def generate_min_max_resilience_plot(path_to_scenarios):
x_data_smoothed, y_data_smoothed = plotting_results.smooth_data(x_data, scenario_data[2015]['max_values'], num=40000)
plt.plot(x_data_smoothed, list(y_data_smoothed), color='black', label='{}__{}'.format(scenario, plot_yr))

# Add flat line
plt.plot(x_data, list(flat_y_data), color='grey', label='{}__{}'.format("flat", 2015))

plt.tight_layout()
plt.ylim(ymin=0, ymax=ymax)
plt.xlim(xmin=0, xmax=23)
Expand Down Expand Up @@ -170,6 +201,9 @@ def generate_min_max_resilience_plot(path_to_scenarios):
x_data_smoothed, y_data_smoothed = plotting_results.smooth_data(x_data, scenario_data[2015]['min_values'], num=40000)
plt.plot(x_data_smoothed, list(y_data_smoothed), color='black', label='{}__{}'.format(scenario, plot_yr))

# Add flat line
plt.plot(x_data, list(flat_y_data), color='grey', label='{}__{}'.format("flat", 2015))

plt.tight_layout()
plt.ylim(ymin=0, ymax=ymax)
plt.xlim(xmin=0, xmax=23)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
enduse,tech,service_share_ey,switch_yr,sector
is_space_heating,heat_pumps_electricity,0.2,2050
2 changes: 0 additions & 2 deletions energy_demand/config_data/07-switches/rs_switches_service.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
enduse,tech,service_share_ey,switch_yr,sector
rs_space_heating,heat_pumps_electricity,0.2,2050
rs_water_heating,heat_pumps_electricity,0.2,2050
2 changes: 0 additions & 2 deletions energy_demand/config_data/07-switches/ss_switches_service.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
enduse,tech,service_share_ey,switch_yr,sector
ss_space_heating,heat_pumps_electricity,0.2,2050
ss_water_heating,heat_pumps_electricity,0.2,2050
2 changes: 1 addition & 1 deletion energy_demand/read_write/write_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def resilience_paper(
path_to_txt_flat = os.path.join(
path_result_sub_folder,
"{}{}".format(
'averge_nr',
'average_nr',
".csv"))

file = open(path_to_txt_flat, "w")
Expand Down

0 comments on commit d895280

Please sign in to comment.