-
Notifications
You must be signed in to change notification settings - Fork 3
/
MakeChargingLoadByZone.py
106 lines (78 loc) · 3.57 KB
/
MakeChargingLoadByZone.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed May 30 20:31:00 2024
@author: danikam
"""
import numpy as np
import pandas as pd
import geopandas as gpd
from CommonTools import get_top_dir
from scipy.interpolate import UnivariateSpline
import matplotlib.pyplot as plt
def get_ev_load_profile(top_dir, load_profile_path):
load_profile_df = pd.read_csv(load_profile_path)
# Sort the DataFrame based on the 'Hours' column
load_profile_df = load_profile_df.sort_values(by="Hours", ascending=True)
# Reset the index of the DataFrame after sorting
load_profile_df = load_profile_df.reset_index(drop=True)
# Get a spline interpolation
spline = UnivariateSpline(
load_profile_df["Hours"], load_profile_df["Power (kW)"], s=500, ext=3
)
hours_fine = np.linspace(0, 24, 300)
power_smooth = spline(hours_fine)
fig, ax = plt.subplots(figsize=(10, 8))
ax.set_ylabel("Power (kW)", fontsize=20)
ax.set_xlabel("Hours", fontsize=20)
ax.set_title("Original Data from Borlaug et al.", fontsize=24)
ax.tick_params(axis="both", which="major", labelsize=18)
ax.plot(load_profile_df["Hours"], load_profile_df["Power (kW)"], "o")
ax.plot(
hours_fine, power_smooth, label="Spline Interpolation", color="red", linewidth=2
)
plt.savefig(f"{top_dir}/plots/extreme_load_profile.png", dpi=300)
# Normalize the profile such that its average is 1
power_smooth = power_smooth / np.average(power_smooth)
fig, ax = plt.subplots(figsize=(10, 8))
ax.set_ylabel("Normalize Units", fontsize=20)
ax.set_xlabel("Hours", fontsize=20)
ax.set_title("Normalize to Unit Average", fontsize=24)
ax.tick_params(axis="both", which="major", labelsize=18)
ax.plot(
hours_fine, power_smooth, label="Spline Interpolation", color="red", linewidth=2
)
plt.savefig(f"{top_dir}/plots/extreme_load_profile_normalized.png", dpi=300)
# Save the normalized load profile to a file
load_profile_smooth_df = pd.DataFrame({"Hours": hours_fine, "Power": power_smooth})
load_profile_smooth_df.to_csv("data/extreme_load_profile_smooth.csv")
return load_profile_smooth_df
def get_daily_ev_demands(top_dir, ev_load_data_gpd, ev_daily_load_profile_df):
# Drop the geometry data (we don't care about it anymore)
ev_load_data_df = ev_load_data_gpd.drop(columns=["geometry"])
zones = ev_load_data_df["zone"].unique()
for zone in zones:
ev_load_data_zone_df = ev_load_data_df[ev_load_data_df["zone"] == zone]
daily_ev_load_dict = {}
for center in ev_load_data_zone_df["Nearest Center"]:
daily_ev_load_dict[center] = (
float(
ev_load_data_zone_df["Av P Dem"][
ev_load_data_zone_df["Nearest Center"] == center
].iloc[0]
)
* ev_daily_load_profile_df["Power"]
)
daily_ev_load_df = pd.DataFrame(daily_ev_load_dict)
daily_ev_load_df["Hours"] = ev_daily_load_profile_df["Hours"]
daily_ev_load_df["Total (MW)"] = daily_ev_load_df.sum(axis=1)
daily_ev_load_df.to_csv(f"{top_dir}/data/daily_ev_load_{zone}.csv", index=False)
def main():
# Get the path to the top level of the Git repo
top_dir = get_top_dir()
ev_load_data_gpd = gpd.read_file(f"{top_dir}/geojsons/TT_charger_locations.json")
ev_daily_load_profile_df = get_ev_load_profile(
top_dir, f"{top_dir}/data/Borlaug_et_al_most_extreme_HDEV_load_profile.csv"
)
get_daily_ev_demands(top_dir, ev_load_data_gpd, ev_daily_load_profile_df)
main()