Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FP Hahne - Changes #77

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
41b4289
try/error phase: save WIP and new .py files
hmfi3 Mar 12, 2021
0c9548f
more try and error in plots and renamed one file
hmfi3 Mar 12, 2021
6e825a6
intermediate status Friday 19.03.21
hmfi3 Mar 22, 2021
f5ad925
update inner for loops dicts instead of lists
hmfi3 Mar 22, 2021
82ae52f
adding legends, one per row of subplots
hmfi3 Mar 23, 2021
515e2f5
minor changes for running module alone
hmfi3 Mar 23, 2021
bb3e9c4
reading out and returning max and min y limits for plot function
hmfi3 Mar 24, 2021
e17d706
change of filenames of files that are read in
hmfi3 Mar 24, 2021
29961ef
implementation of dynamic y-limits and other minor changes
hmfi3 Mar 24, 2021
b89f51d
replace lists for for loop with dict for better overview
hmfi3 Mar 24, 2021
2d24177
minor changes to labels and cleared out unused variables
hmfi3 Mar 25, 2021
6ee6197
error fix (in flex price calculation)
hmfi3 Mar 25, 2021
9036496
bug fix - summer/winter split up
hmfi3 Mar 26, 2021
37969d1
bug fix in previous bug fix (su/wi differentiation)
hmfi3 Mar 29, 2021
0bcae78
cleanup (deleting unessecary file)
hmfi3 Mar 29, 2021
bf0fd8d
addition of allseasons plots and minor changes
hmfi3 Mar 29, 2021
3f07016
small bug fix (saving non-empty plots)
hmfi3 Mar 29, 2021
1244f53
bug fix: ylim-dict values calculation now for every season
hmfi3 Mar 29, 2021
e327872
option to save ylimits, other minor changes
hmfi3 Apr 9, 2021
8875435
clean up, deletion of double code
hmfi3 Apr 9, 2021
a172317
plot flex prices - code cleanup, comments update, deletion of old files
hmfi3 Apr 22, 2021
1c20407
gitignore - ignore all Data files except test data
hmfi3 Apr 22, 2021
e2da52d
bug fix - now power levels are sorted from low to high
hmfi3 Apr 22, 2021
c3e916b
small bug fix (sorted power lvls) and minor changes to save ylims dict
hmfi3 Apr 22, 2021
62447e8
Merge remote-tracking branch 'tum-ewk/master'
hmfi3 Apr 22, 2021
43d56ce
Merge branch 'master' into dev-helena
hmfi3 Apr 22, 2021
50bfe13
Plotting only allseason/average day when executing run_ev_case_study.py
hmfi3 Apr 23, 2021
fd6fe11
aggregate function, code cleanup and updated comments
hmfi3 Apr 23, 2021
e7b6d6d
Minor Changes and Code Clean Up
hmfi3 Apr 28, 2021
534b4ae
Merge branch 'dev-helena'
hmfi3 Apr 28, 2021
eda9bfc
delete double code
hmfi3 May 12, 2021
760a111
Merge branch 'dev-helena'
hmfi3 May 12, 2021
ac3d03c
calc_ev_flex_offers: bug fix and code cleanup
hmfi3 May 12, 2021
3b37b6e
bug fix - deletion of double conversion mile to km
hmfi3 May 12, 2021
b47f7c2
bug fixes, optional reading in of ylimits fixed
hmfi3 May 13, 2021
336c089
calc_ev_flex_offers: minor change for better comprehensibility
hmfi3 May 17, 2021
094331a
Merge branch 'dev-helena'
hmfi3 May 17, 2021
f4ecd33
MI-price tariffs - increment fix
hmfi3 May 20, 2021
3c239d2
change of flexibility price calculation formulas
hmfi3 May 20, 2021
19ba360
Merge branch 'dev-helena'
hmfi3 May 20, 2021
358aaa4
plot adjustments
hmfi3 May 23, 2021
86bfceb
Merge branch 'dev-helena'
hmfi3 May 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ forecast/input/
output/
tester/
*.png

analysis/Data/
3 changes: 2 additions & 1 deletion analysis/ev_case_study/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""
This package includes all necessary modules to perform the ev case study.
"""
from .calc_ev_flex_offers import calc_ev_flex_offers, calc_ev_flex_offers_parallel
from .calc_ev_flex_offers import calc_ev_flex_offers_parallel
from .aggregate_ev_opt_flex import aggregate_ev_flex
from .plot_timeseries_results import plot_opt_flex_timeseries, plot_n_avail_veh
from .plot_flex_heatmap import plot_flex_heatmap
from .plot_overall_cost import plot_overall_cost
from .plot_flex_prices import plot_flex_prices
from .create_folder import create_output_folder, create_figures_folder
395 changes: 322 additions & 73 deletions analysis/ev_case_study/aggregate_ev_opt_flex.py

Large diffs are not rendered by default.

129 changes: 8 additions & 121 deletions analysis/ev_case_study/calc_ev_flex_offers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,116 +19,14 @@
import itertools


def calc_ev_flex_offers(veh_availabilities,
rtp_input_data_path='../analysis/input/RTP/',
output_path='output/',
power_levels=[3.7, 11, 22],
pricing_strategies={'ToU', 'Constant', 'Con_mi', 'ToU_mi', 'RTP'},
conversion_distance_2_km=1.61,
conversion_km_2_kwh=0.2,
plotting=False):
"""
This function iteratively calculates the flexibility of each vehicle availability for every power level
and pricing strategy.

:param veh_availabilities: vehicle availabilities consisting of arrival and departure times, distance travelled
:param output_path: path where output shall be stored
:param rtp_input_data_path: real time prices input file in h5 format
:param power_levels: charging power levels
:param pricing_strategies: pricing strategies for simulations
:param conversion_distance_2_km: conversion rate, e.g. 1 mile = 1.61 km
:param conversion_km_2_kwh: conversion rate from km to kwh
:param plotting: plotting parameter, default is False
:return: None
"""

# initialize with basic time settings
my_ems = opentumflex.initialize_time_setting(t_inval=15,
start_time='2012-01-01 00:00',
end_time='2012-01-01 23:00')

# Reset forecasts
my_ems['fcst'] = {}

# Counter for keeping track of insufficient time differences
t_insufficient_count = 0

# Go through all vehicle availabilities
for i in range(len(veh_availabilities)):
print('################# Vehicle availability #' + str(i) + ' #################')
# Ceil arrival time to next quarter hour
t_arrival_ceiled = pd.Timestamp(veh_availabilities['t_arrival'][i]).ceil(freq='15Min')
# Floor departure time to previous quarter hour
t_departure_floored = pd.Timestamp(veh_availabilities['t_departure'][i]).floor(freq='15Min')
# Check whether time between ceiled arrival and floored departure time are at least two time steps
if t_arrival_ceiled >= t_departure_floored:
print('### Time is not sufficient for timestep:', i, '###')
t_insufficient_count += 1
continue

# change the time interval
my_ems['time_data']['start_time'] = t_arrival_ceiled.strftime('%Y-%m-%d %H:%M')
my_ems['time_data']['end_time'] = t_departure_floored.strftime('%Y-%m-%d %H:%M')
my_ems.update(opentumflex.update_time_data(my_ems))
my_ems['fcst']['temp'] = [0] * my_ems['time_data']['nsteps']
my_ems['fcst']['solar'] = [0] * my_ems['time_data']['nsteps']
my_ems['fcst']['last_heat'] = [0] * my_ems['time_data']['nsteps']
my_ems['fcst']['last_elec'] = [0] * my_ems['time_data']['nsteps']
my_ems['fcst']['gas'] = [0] * my_ems['time_data']['nsteps']
my_ems['fcst']['ele_price_out'] = [0] * my_ems['time_data']['nsteps']

# Get simulated price forecast for given time period
price_fcst = forecast.simulate_elect_price_fcst(rtp_input_data_path=rtp_input_data_path,
t_start=t_arrival_ceiled,
t_end=t_departure_floored,
pr_constant=0.19,
pricing=pricing_strategies)
# Go through all price strategies
for price in price_fcst.columns:
# Go through all power levels
for power in power_levels:
print('#' + str(i) + ': Power=' + str(power) + ' Pricing=' + price)
# Update forecast data
my_ems['fcst']['ele_price_in'] = price_fcst[price].to_list()

# Update EV parameters
my_ems['devices'].update(opentumflex.create_device(device_name='ev', minpow=0, maxpow=power,
stocap=round(veh_availabilities['d_travelled'][i] *
conversion_distance_2_km *
conversion_km_2_kwh),
init_soc=[0], end_soc=[100], eta=0.98,
ev_aval=[my_ems['time_data']['start_time'],
my_ems['time_data']['end_time']],
timesetting=my_ems['time_data']))

# create Pyomo model from opentumflex data
m = opentumflex.create_model(my_ems)

# solve the optimization problem
m = opentumflex.solve_model(m, solver='glpk', time_limit=30, troubleshooting=False)

# extract the results from model and store them in opentumflex['optplan'] dictionary
my_ems = opentumflex.extract_res(m, my_ems)

# Calculate ev flexibility
my_ems = opentumflex.calc_flex_ev(my_ems)

# Plot flex result
if plotting:
opentumflex.plot_flex(my_ems, 'ev')

# Save results to files
opentumflex.save_ems(my_ems, path=output_path + str(power) + '/' + price + '/ev_avail_' + str(i) + '.txt')


def calc_ev_flex_offers_parallel(param_variation,
param_fix):
"""
This function calculates the flexibility of each vehicle availability for a specific power level & pricing strategy.

:param param_variation: parameter variation as a list containing charging power (float), pricing strategy (string)
and vehicle availability (list)
:param param_fix: fix parameters consisting of 'conversion_distance_2_km', 'conversion_km_2_kwh', 'rtp_input_data_path',
:param param_fix: fix parameters consisting of 'conversion_km_2_kwh', 'rtp_input_data_path',
'output_path', 'pricing_strategies', 'plotting'
:return: None
"""
Expand All @@ -146,7 +44,7 @@ def calc_ev_flex_offers_parallel(param_variation,
# Floor departure time to previous quarter hour
t_departure_floored = pd.Timestamp(param_variation[2][5]).floor(freq='15Min')
# Check whether time between ceiled arrival and floored departure time are at least two time steps
if t_arrival_ceiled >= t_departure_floored:
if t_departure_floored - t_arrival_ceiled < pd.Timedelta(minutes=2*my_ems['time_data']['t_inval']):
if param_fix['info']:
print('#' + str(param_variation[2][0]) + ': Time not sufficient.')
return
Expand Down Expand Up @@ -178,7 +76,6 @@ def calc_ev_flex_offers_parallel(param_variation,
# Update EV parameters
my_ems['devices'].update(opentumflex.create_device(device_name='ev', minpow=0, maxpow=param_variation[0],
stocap=round(param_variation[2][2] *
param_fix['conversion_distance_2_km'] *
param_fix['conversion_km_2_kwh']),
init_soc=[0], end_soc=[100], eta=0.98,
ev_aval=[my_ems['time_data']['start_time'],
Expand Down Expand Up @@ -210,23 +107,13 @@ def calc_ev_flex_offers_parallel(param_variation,
# Read veh availabilities from file
veh_avail = pd.read_csv('../input/chts_veh_availability.csv')
# Extract a subsample for testing
veh_avail = veh_avail[68:88]
veh_avail = veh_avail[:]
veh_avail = veh_avail.reset_index()

# Make case study definitions
power_levels = [3.7, 11, 22]
pricing_strategies = ['ToU', 'Constant', 'Con_mi', 'ToU_mi', 'RTP']

calc_ev_flex_offers(veh_avail,
rtp_input_data_path='../input/RTP/',
output_path='../output/',
power_levels=power_levels,
pricing_strategies=pricing_strategies,
conversion_distance_2_km=1.61,
conversion_km_2_kwh=0.2,
plotting=False)


# Define case study details
params = {'power': power_levels,
'pricing': pricing_strategies,
Expand All @@ -235,12 +122,12 @@ def calc_ev_flex_offers_parallel(param_variation,
# Create all possible combinations of params
keys = list(params)
param_variations = list()
param_con = {'conversion_distance_2_km': 1.61,
'conversion_km_2_kwh': 0.2,
'rtp_input_data_path': 'C:/Users/ga47num/PycharmProjects/OpenTUMFlexPy/analysis/input/RTP/',
'output_path': 'C:/Users/ga47num/PycharmProjects/OpenTUMFlexPy/analysis/output/',
param_con = {'conversion_km_2_kwh': 0.2,
'rtp_input_data_path': '../input/RTP/',
'output_path': '../output/',
'pricing_strategies': ['ToU', 'Constant', 'Con_mi', 'ToU_mi', 'RTP'],
'plotting': False}
'plotting': False,
'info': False}
for values in itertools.product(*map(params.get, keys)):
# Store in list
param_variations.append(list(values))
Expand Down
Loading