-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscenario_builder.py
63 lines (52 loc) · 2.38 KB
/
scenario_builder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import pickle
import pandas as pd
def build_scenario(network_name: str, scenarios: int):
"""
This function is used to build the scenario for the given network and number of scenarios
:param network_name: network name
:param scenarios: number of scenarios
:return:
dict_scenario: dictionary containing the GHI values for each location for each scenario at every time_stamp
"""
# Specify the directory where your CSV files are located
folder_path = fr'./{network_name}/{scenarios}_scenario/solar_data'
# # Get a list of all files in the specified directory
files = os.listdir(folder_path)
# import charging_location.pkl
with open(f'./{network_name}/{scenarios}_scenario/overall_charging_locations_cs.pkl', 'rb') as f:
charging_location = set(pickle.load(f))
# finding the file for each charging location
dict_csv = {}
for file in files:
location = file.split('_')[0]
dict_csv[location] = file
dict_scenario = {}
# iterating over the charging locations
for location in charging_location:
# convert location to string
location = str(location)
if network_name == 'Durham_2.1k':
stops = pd.read_csv(f'./{network_name}/stops.txt')
# find the stop_code for the location
location1 = str(stops[stops.stop_id == location].stop_code.values[0])
path = dict_csv[location1]
else:
# read the csv file
path = dict_csv[location]
df = pd.read_csv(f'./{network_name}/{scenarios}_scenario/solar_data/{path}')
# create a dictionary for each location
dict_scenario[location] = {}
# average of GHI value at every hour
for i in range(1, scenarios + 1):
data = df[df['Scenario'] == i]
# for each scenario
dict_scenario[location][i] = {}
# for each hour
for j in range(24):
dict_scenario[location][i][j] = round(data[data.Hour == j]['Plane of Array '
'Irradiance (W/m2)'].mean()/60000, 5)
# save dict_scenario as pickle file
with open(f'./{network_name}/{scenarios}_scenario/gti_variation.pkl', 'wb') as f:
pickle.dump(dict_scenario, f)
return dict_scenario