Skip to content

Commit

Permalink
changing a few things for the new function #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Tk1999s committed Mar 24, 2022
1 parent 8ae8301 commit 88302b8
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 54 deletions.
81 changes: 64 additions & 17 deletions simbev/main_simbev.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pathlib import Path
import multiprocessing as mp
import helpers.helpers as helper

from datetime import date
# regiotypes:
# Ländliche Regionen
# LR_Klein - Kleinstädtischer, dörflicher Raum
Expand All @@ -23,7 +23,7 @@


def run_simbev(region_ctr, region_id, region_data, cfg_dict, charge_prob,
regions, tech_data, main_path):
regions, tech_data, main_path, temperature):
"""Run simbev for single region"""
print(f'===== Region: {region_id} ({region_ctr + 1}/{len(regions)}) =====')

Expand All @@ -32,14 +32,8 @@ def run_simbev(region_ctr, region_id, region_data, cfg_dict, charge_prob,
eta_cp = cfg_dict['eta_cp']
rng = cfg_dict['rng']
soc_min = cfg_dict['soc_min']
heating = cfg_dict['heating']
cooling = cfg_dict['cooling']
temp_inside = cfg_dict['temp_inside']

# get temperature timeline
temperature = pd.read_csv("C:/Users/Tim.Kirschner/python_projects/simbev/simbev/simbev/scenarios"
"/Wetterdaten_Berlin.csv", sep=";", skiprows=1)
temperature = temperature[['date', 'tavg']]
# get probabilities
probdata, tseries_purpose, days = simbevMiD.get_prob(
region_data.RegioStaR7,
Expand Down Expand Up @@ -181,8 +175,6 @@ def run_simbev(region_ctr, region_id, region_data, cfg_dict, charge_prob,
soc_min,
tseries_purpose,
carstatus,
cooling,
heating,
temp_inside,
temperature,
)
Expand Down Expand Up @@ -257,11 +249,7 @@ def init_simbev(args):

# set eta cp from config
eta_cp = cfg.getfloat('basic', 'eta_cp')
cooling = cfg.getfloat('basic', 'energy_use_cooling'),
heating = cfg.getfloat('basic', 'energy_use_heating'),
temp_inside = cfg.getint('basic', 'temp_carinside'),
heating = float('.'.join(str(ele) for ele in heating))
cooling = float('.'.join(str(ele) for ele in cooling))
temp_inside = float('.'.join(str(ele) for ele in temp_inside))
# get minimum soc value in %
soc_min = cfg.getfloat('basic', 'soc_min')
Expand Down Expand Up @@ -307,8 +295,6 @@ def init_simbev(args):
'end_date': e_date,
'home_private': home_private,
'work_private': work_private,
'cooling': cooling,
'heating': heating,
'temp_inside': temp_inside,
}

Expand Down Expand Up @@ -354,7 +340,7 @@ def init_simbev(args):
if num_threads == 1:
for region_ctr, (region_id, region_data) in enumerate(regions.iterrows()):
run_simbev(region_ctr, region_id, region_data, cfg_dict, charge_prob,
regions, tech_data, main_path)
regions, tech_data, main_path, temperature)
else:
pool = mp.Pool(processes=num_threads)

Expand Down Expand Up @@ -384,6 +370,67 @@ def init_simbev(args):
helper.compile_output_by_usecase(main_path, start, end, region_mode, cfg_dict["stepsize"])


def temperture_adapting(start_date, end_date):
temperature = pd.read_csv("data/Wetterdaten_Berlin.csv", sep=";", skiprows=1)
temperature = temperature[['date', 'tavg']]
[year, month, day] = start_date.split('-')
[yeare, monthe, daye] = end_date.split('-')
startdate = day + '.' + month
enddate = daye + '.' + monthe

datums = date(int(year), int(month), int(day))
datume = date(int(yeare), int(monthe), int(daye))
days_in_period = (datume - datums).days

list1 = []
for z, it in enumerate(temperature['date']):
date_need = it[:5]
if date_need == startdate:
start_i = z
if date_need == enddate:
end_i = z
list1.append(date_need)

temp = []
for i in temperature['tavg']:
rtem = i.replace(',', '.')
rtem = float(rtem)
temp.append(rtem)

temperature_list = []
for it in range(672):
temperature_list.append(0)
if days_in_period > 365 and start_i > end_i:
for it in temp[start_i:]:
for jt in range(96):
temperature_list.append(it)
for it in temp:
for jt in range(96):
temperature_list.append(it)
for it in temp[:end_i + 1]:
for jt in range(96):
temperature_list.append(it)
elif days_in_period < 365 and start_i < end_i:
for it in temp[start_i:end_i + 1]:
for jt in range(96):
temperature_list.append(it)
elif days_in_period < 365 and start_i > end_i:
for it in temp[start_i:]:
for jt in range(96):
temperature_list.append(it)
for it in temp[:end_i + 1]:
for jt in range(96):
temperature_list.append(it)
else:
for it in temp[start_i:]:
for jt in range(96):
temperature_list.append(it)
for it in temp[:end_i + 1]:
for jt in range(96):
temperature_list.append(it)
return temperature_list


if __name__ == "__main__":

parser = argparse.ArgumentParser(description='SimBEV modelling tool for generating timeseries of electric '
Expand Down
50 changes: 13 additions & 37 deletions simbev/simbevMiD.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This module represents the core of SimBEV. Here you find the main functions to run simulations and
create driving profiles.
"""
from datetime import datetime
from datetime import date
import datetime as dt

import math
Expand Down Expand Up @@ -144,8 +144,6 @@ def availability(
soc_min,
tseries_purpose,
carstatus,
cooling,
heating,
temp_inside,
temperature,
):
Expand All @@ -160,7 +158,6 @@ def availability(
st = probdata["start"]
# probability for trip purpose depending on weekday
p_all = probdata["purpose"]
daykey = st.index
# p = p_all[::96]
# init car_status, 1,5 days for trips over 24h
# car_status = np.zeros(int(range_sim) + int(range_sim / 2))
Expand Down Expand Up @@ -203,7 +200,7 @@ def availability(
demand = []
# init break_key
break_key = 0

z = len(tseries_purpose)
# im = 0
# loop minutes per day
for im in range(len(tseries_purpose)):
Expand All @@ -220,28 +217,7 @@ def availability(
# st_day = st[daykey]
st_trips = st["trips"]
st_now = st_trips.iloc[im]

# get temperature
date_im = daykey
# date_im = date_im.strftime('%m-%d')
date_now = date_im[im]
date_cur = date_now.strftime('%m-%d')

#if int(date_now.month) < 10:
# date_cur = str(date_now.day) + '.' + '0' + str(date_now.month) + '.' + '2022'
#else:
# date_cur = str(date_now.day) + '.' + str(date_now.month) + '.' + '2022'
#if int(date_now.day) < 10:
# date_cur = '0' + date_cur
#else:
# date_cur = date_cur
temp_date = temperature['date']
temp_temp = temperature['tavg']
for it in range(len(temperature)):
date_temp = datetime.strptime(temp_date[it], '%d.%m.%Y')
date_temp = date_temp.strftime('%m-%d')
if date_temp == date_cur:
temperature_now = temp_temp[it]
temperature_now = temperature[im]
# get car status
go = car_status[im]

Expand Down Expand Up @@ -370,7 +346,7 @@ def availability(
distance_remaining = distance - distance_stop
drivetime = (distance_stop / speed) * 60
drivetime = math.ceil(drivetime / stepsize)
driveconsumption = total_consumption(temperature_now, drivetime, temp_inside, cooling, heating, con,
driveconsumption = total_consumption(temperature_now, drivetime, temp_inside, con,
distance)
# get timesteps for car status of driving
drive_start = im + 1
Expand Down Expand Up @@ -436,8 +412,7 @@ def availability(
distance_stop = range_bat
drivetime = (distance_stop / speed) * 60
drivetime = math.ceil(drivetime / stepsize)
driveconsumption = total_consumption(temperature_now, drivetime, temp_inside, cooling, heating, con,
distance)
driveconsumption = total_consumption(temperature_now, drivetime, temp_inside, con, distance)
purp_list.append("driving")
# get timesteps for car status of driving
drive_start = im + 1
Expand Down Expand Up @@ -501,8 +476,7 @@ def availability(
# driving
drivetime = (distance / speed) * 60
drivetime = math.ceil(drivetime / stepsize)
driveconsumption = total_consumption(temperature_now, drivetime, temp_inside, cooling, heating, con,
distance)
driveconsumption = total_consumption(temperature_now, drivetime, temp_inside, con, distance)
soc = soc_list[-1] - (driveconsumption / batcap)
if car_type == "PHEV":
# SOC can't be negative
Expand Down Expand Up @@ -1178,15 +1152,17 @@ def fast_charging_capacity(
# energie use cooling/heating: KWh verbraucht pro Einheit??


def total_consumption(temperature, timesteps, temperature_carinside, energy_use_cooling, energy_use_heating,
con, distance):
temperature = temperature.replace(',', '.')
temperature = float(temperature)
def total_consumption(temperature, timesteps, temperature_carinside, con, distance):
energy_use_cooling = 0.01575
energy_use_heating = 0.025
temperature_diff = temperature_carinside - temperature

if temperature_diff > 0:
extra_kwh = temperature_diff * energy_use_heating * timesteps
else:
extra_kwh = (temperature_diff * -1) * energy_use_cooling * timesteps
consumption = distance * con + extra_kwh
return consumption
return consumption



0 comments on commit 88302b8

Please sign in to comment.