Skip to content

Commit

Permalink
before morging
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Eggimann committed Oct 16, 2018
1 parent dd043da commit 6a8f593
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 146 deletions.
20 changes: 20 additions & 0 deletions energy_demand/basic/date_prop.py
Expand Up @@ -32,6 +32,26 @@ def convert_h_to_day_year_and_h(hour):

return day, day_h

def get_8760_hrs_from_yeardays(yeardays):
"""Get from yeadays all yearhours
Arguments
---------
yeardays : list
Listh with year days (0 - 364)
Returns
---------
year_hrs : list
All year hours (0 - 8759)
"""
year_hrs = []
for day in yeardays:
hrs = list(range((day * 24), ((day + 1) * 24)))
year_hrs += hrs

return year_hrs

def get_seasonal_weeks():
"""
"""
Expand Down
14 changes: 4 additions & 10 deletions energy_demand/enduse_func.py
Expand Up @@ -1096,13 +1096,13 @@ def apply_scenario_drivers(
by_driver_data = gva_per_head[base_yr][region]
cy_driver_data = gva_per_head[curr_yr][region]

logging.info("gva {} {}".format(by_driver_data, cy_driver_data))
#logging.info("gva {} {}".format(by_driver_data, cy_driver_data))

elif scenario_driver == 'population':
by_driver_data = population[base_yr][region]
cy_driver_data = population[curr_yr][region]

logging.info("pop {} {}".format(population[base_yr][region], population[curr_yr][region]))
#logging.info("pop {} {}".format(population[base_yr][region], population[curr_yr][region]))

# Multiply drivers
by_driver *= by_driver_data
Expand All @@ -1118,15 +1118,9 @@ def apply_scenario_drivers(
except ZeroDivisionError:
factor_driver = 1

logging.info(" eda {} {} {} {}".format(
scenario_drivers,
factor_driver,
by_driver_data,
cy_driver_data
#logging.info(" eda {} {} {} {}".format(
# scenario_drivers, factor_driver, by_driver_data, cy_driver_data))

))


fuel_y = fuel_y * factor_driver
else:
"""Scenario driver calculation based on dwelling stock
Expand Down
10 changes: 5 additions & 5 deletions energy_demand/plotting/fig_p2_spatial_val.py
@@ -1,5 +1,6 @@
"""
"""
import os
import operator
import logging
import numpy as np
Expand Down Expand Up @@ -71,19 +72,19 @@ def run(
subnational_elec,
regions,
'electricity',
fig_path=fig_path,
fig_path=os.path.join(fig_path, "spatial_validation_electricity.pdf"),
label_points=False,
plotshow=plot_crit)

# Gas TODO
# Gas
plot_spatial_validation(
simulation_yr_to_plot,
fuel_gas_regs_yh,
demand_year_regional,
subnational_gas,
regions,
'gas',
fig_path=fig_path,
fig_path=os.path.join(fig_path, "spatial_validation_gas.pdf"),
label_points=False,
plotshow=plot_crit)

Expand Down Expand Up @@ -244,7 +245,6 @@ def plot_spatial_validation(
for region_vals in y_modelled_demands_non_regional:
station_vals.append(region_vals[station_nr])


plt.plot(
x_values,
station_vals,
Expand Down Expand Up @@ -377,7 +377,7 @@ def plot_spatial_validation(
# Tight layout
plt.margins(x=0)
plt.tight_layout()
#plt.savefig(fig_name)
plt.savefig(fig_path)

if plotshow:
plt.show()
Expand Down
116 changes: 63 additions & 53 deletions energy_demand/plotting/fig_p2_temporal_validation.py
Expand Up @@ -2,14 +2,13 @@
"""
import numpy as np
import matplotlib.pyplot as plt
#from scipy.stats import mstats
import pandas as pd
from scipy import stats

from energy_demand.technologies import tech_related
from energy_demand.plotting import basic_plot_functions

def run(
def run_fig_p2_temporal_validation(
data_input,
weather_yr,
fueltype_str,
Expand All @@ -18,18 +17,20 @@ def run(
validation_elec_2015,
non_regional_elec_2015,
fig_name,
titel="titel",
y_lim_val=100,
plot_validation=False,
plot_show=False
):
"""
"""
# Select period and fueltype
fueltype_int = tech_related.get_fueltype_int(fueltype_str)

# -----------------------------------------------------------
# Iterate overall weather_yrs and store data in dataframe
# (columns = timestep, rows: value of year)
# -----------------------------------------------------------
columns = period_h # hours in 8760 hours
selection_hours = period_h

# List of selected data for every weather year (which is then converted to array)
weather_yrs_data = []
Expand All @@ -40,15 +41,15 @@ def run(
# Weather year specific data
data_input_fueltype = data_weather_yr[simulation_yr_to_plot][fueltype_int] # Select fueltype
data_input_reshape = data_input_fueltype.reshape(8760) # reshape
data_input_selection_hrs = data_input_reshape[period_h] # select period
data_input_selection_hrs = data_input_reshape[selection_hours] # select period

weather_yrs_data.append(data_input_selection_hrs)
weather_yrs_full_year.append(data_input_reshape)

weather_yrs_data = np.array(weather_yrs_data)

# Create dataframe
df = pd.DataFrame(weather_yrs_data, columns=columns)
df = pd.DataFrame(weather_yrs_data, columns=period_h)

df_full_year = pd.DataFrame(weather_yrs_full_year, columns=range(8760))

Expand All @@ -64,13 +65,10 @@ def run(
df_q_95 = df_q_95.T
df_q_05 = df_q_05.T

fig = plt.figure() #(figsize = cm2inch(10,10))
fig = plt.figure()

ax = fig.add_subplot(111)

# 2015 weather year
#data_2015 = data_weather_yr[2015][fueltype_int].reshape(8760)[period_h]

# ---------------
# Smoothing lines
# ---------------
Expand All @@ -82,7 +80,6 @@ def run(
period_h_smoothed = period_h
df_q_95_smoothed = df_q_95
df_q_05_smoothed = df_q_05
#data_2015_smoothed = data_2015

#plt.plot(period_h_smoothed, data_2015_smoothed, color='tomato', linestyle='-', linewidth=2, label="2015 weather_yr")
plt.plot(period_h_smoothed, df_q_05_smoothed, color='black', linestyle='--', linewidth=0.5, label="0.05")
Expand All @@ -95,30 +92,54 @@ def run(
period_h_smoothed, #x
df_q_95_smoothed, #y1
df_q_05_smoothed, #y2
alpha=.25,
facecolor="grey",
alpha=1,
facecolor="lightgrey",
label="uncertainty band")

# -----------------
# Validation data
# All weather stations are used for this data
# -----------------
validation_2015 = validation_elec_2015.reshape(8760)[period_h]

try:
period_h_smoothed, validation_2015_smoothed = basic_plot_functions.smooth_data(period_h, validation_2015, num=40000)
except:
period_h_smoothed = period_h
validation_2015_smoothed = validation_2015

plt.plot(
period_h_smoothed,
validation_2015_smoothed,
color='green', linestyle='--', linewidth=3, label="validation 2015")
all_weather_stations_2015 = non_regional_elec_2015.reshape(8760)[period_h]

# -----------------
# All weather stations are used for this data
# Validation data
# -----------------
all_weather_stations_2015 = non_regional_elec_2015.reshape(8760)[period_h]
if plot_validation:
validation_2015 = validation_elec_2015.reshape(8760)[selection_hours]

try:
period_h_smoothed, validation_2015_smoothed = basic_plot_functions.smooth_data(period_h, validation_2015, num=40000)
except:
period_h_smoothed = period_h
validation_2015_smoothed = validation_2015

plt.plot(
period_h_smoothed,
validation_2015_smoothed,
color='green',
linestyle='--',
linewidth=1.5, label="validation 2015")

# -----------
# statistics
# -----------
# Calculate mean of all all single station runs
mean_all_single_runs = df_full_year.mean(axis=0).tolist()
mean_all_single_runs = np.array(mean_all_single_runs)[period_h]

slope, intercept, r_value, p_value, std_err = stats.linregress(
validation_2015,
all_weather_stations_2015)
slope, intercept, r_value2, p_value, std_err = stats.linregress(
validation_2015,
mean_all_single_runs)

print("R_Value_all_stations: " + str(r_value))
print("R_Value_single_stations: " + str(r_value2))
plt.title(
"R_value: all stations: {} mean_single_weather_stations: {}".format(
round(r_value, 2),
round(r_value2, 2)))

try:
period_h_smoothed, all_weather_stations_2015_smoothed = basic_plot_functions.smooth_data(
Expand All @@ -127,36 +148,25 @@ def run(
period_h_smoothed = period_h
all_weather_stations_2015_smoothed = all_weather_stations_2015

# -----------
# statistics
# -----------
# Calculate mean of all all single station runs
mean_all_single_runs = df_full_year.mean(axis=0).tolist()
mean_all_single_runs = np.array(mean_all_single_runs)

slope, intercept, r_value, p_value, std_err = stats.linregress(
validation_2015,
all_weather_stations_2015)
slope, intercept, r_value2, p_value, std_err = stats.linregress(
validation_2015,
mean_all_single_runs)

print("R_Value_all_stations: " + str(r_value))
print("R_Value_single_stations: " + str(r_value2))

plt.title(
"R_value: all stations: {} mean_single_weather_stations: {}".format(
round(r_value, 2),
round(r_value2, 2)))

plt.plot(
period_h_smoothed,
all_weather_stations_2015_smoothed,
color='blue',
linestyle='--',
linewidth=1,
label="all weather stations 2015")

linewidth=1.2,
label="all stations")

# Ticks for single day
#major_ticks_days, major_ticks_labels = get_date_strings(
# days_to_plot,
# daystep=1)
#plt.xticks(major_ticks_days, major_ticks_labels)
zero_entry = period_h[0]
plt.xticks([0 + zero_entry, 5 + zero_entry, 11 + zero_entry, 17 + zero_entry, 23 + zero_entry], ['1', '6', '12', '18', '24'])

plt.ylim(0, y_lim_val)
plt.xlim(period_h[0], period_h[-1])
plt.title("Peak day: " + str(titel))
plt.legend(
prop={
'family':'arial',
Expand Down
7 changes: 1 addition & 6 deletions energy_demand/plotting/fig_spatial_distribution_of_peak.py
Expand Up @@ -15,7 +15,7 @@
from energy_demand.plotting import result_mapping
from energy_demand.plotting import fig_p2_weather_val

def run(
def run_fig_spatial_distribution_of_peak(
scenarios,
path_to_folder_with_scenarios,
path_shapefile,
Expand Down Expand Up @@ -48,12 +48,9 @@ def run(
# -----------
# Used across different plots
# -----------

#Fueltype to consider
fueltype_str = 'electricity'
fueltype_int = tech_related.get_fueltype_int(fueltype_str)

#results_container['ed_fueltype_regs_yh']
container = {}
container['abs_demand_in_peak_h'] = {}
container['p_demand_in_peak_h'] = {}
Expand All @@ -69,8 +66,6 @@ def run(
data['assumptions']['seasons'] = date_prop.get_season(year_to_model=2015)
data['assumptions']['model_yeardays_daytype'], data['assumptions']['yeardays_month'], data['assumptions']['yeardays_month_days'] = date_prop.get_yeardays_daytype(year_to_model=2015)

path_out_plots = os.path.abspath(os.path.join(path_data_ed, '..', '_results_PDF_figs'))

# Population
population_data = read_data.read_scenaric_population_data(os.path.join(path_data_ed, 'model_run_pop'))

Expand Down

0 comments on commit 6a8f593

Please sign in to comment.