Skip to content

Commit af28ea0

Browse files
committed
Make map of buildout
1 parent 4a2d6cc commit af28ea0

File tree

14 files changed

+149
-3
lines changed

14 files changed

+149
-3
lines changed

switch_model/generators/core/build.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,4 +893,18 @@ def graph_buildout_per_tech(tools):
893893
# Set the y-axis to use percent
894894
ax.yaxis.set_major_formatter(tools.mplt.ticker.PercentFormatter(1.0))
895895
# Horizontal line at 100%
896+
<<<<<<< HEAD
896897
ax.axhline(y=1, linestyle="--", color="b")
898+
=======
899+
ax.axhline(y=1, linestyle="--", color='b')
900+
901+
@graph(
902+
"buildout_map",
903+
title="Map of online capacity per load zone."
904+
)
905+
def buildout_map(tools):
906+
buildout = tools.get_dataframe("gen_cap.csv").rename({"GenCapacity": "value"}, axis=1)
907+
buildout = tools.transform.gen_type(buildout)
908+
buildout = buildout.groupby(["gen_type", "gen_load_zone"], as_index=False)["value"].sum()
909+
tools.graph_map_pychart(buildout)
910+
>>>>>>> 292648b0 (Make map of buildout)

switch_model/tools/graph/main.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,93 @@ def graph_matrix(self, df, value_column, ylabel, row_specifier, col_specifier):
962962
legend_pairs = legend.items()
963963
fig.legend([h for _, h in legend_pairs], [l for l, _ in legend_pairs])
964964
965+
def graph_map_pychart(self, df, max_size=2500):
966+
"""
967+
Graphs the data from the dataframe to a map pychart.
968+
The dataframe should have 3 columns, gen_load_zone, gen_type and value.
969+
"""
970+
# Scale the dataframe so the pie charts have the right size
971+
current_max_size = df.groupby("gen_load_zone")["value"].sum().max()
972+
df["value"] *= max_size / current_max_size
973+
974+
try:
975+
import geopandas
976+
except ModuleNotFoundError:
977+
raise Exception("Could not find package 'geopandas'. Make sure you install it through conda.")
978+
979+
# Read shape files
980+
try:
981+
wecc_lz = geopandas.read_file("inputs/maps/wecc_102009.shp", crs="ESRI:102009")
982+
wecc_states = geopandas.read_file("inputs/maps/wecc_states_4326.shp")
983+
except FileNotFoundError:
984+
raise Exception("Can't create maps, shape files are missing. Try running switch get_inputs.")
985+
986+
# Find the center point
987+
wecc_lz["Center_point"] = wecc_lz["geometry"].centroid
988+
989+
# Extract lat and lon from the centerpoint
990+
wecc_lz["lat"] = wecc_lz.Center_point.map(lambda p: p.x)
991+
wecc_lz["lng"] = wecc_lz.Center_point.map(lambda p: p.y)
992+
993+
# New dataframe with the centerpoint geometry
994+
gdf = geopandas.GeoDataFrame(
995+
wecc_lz[["LOAD_AREA", "lat", "lng"]],
996+
geometry=geopandas.points_from_xy(x=wecc_lz.lat, y=wecc_lz.lng),
997+
crs="ESRI:102009",
998+
)
999+
1000+
# REFERENC: https://tinyurl.com/app/myurls
1001+
def pie_plot(x, y, ratios, colors, size, ax=None):
1002+
# determine arches
1003+
start = 0.0
1004+
xy = []
1005+
s = []
1006+
for ratio in ratios:
1007+
x0 = [0] + np.cos(
1008+
np.linspace(2 * np.pi * start, 2 * np.pi * (start + ratio), 30)
1009+
).tolist() # 30
1010+
y0 = [0] + np.sin(
1011+
np.linspace(2 * np.pi * start, 2 * np.pi * (start + ratio), 30)
1012+
).tolist() # 30
1013+
1014+
xy1 = np.column_stack([x0, y0])
1015+
s1 = np.abs(xy1).max()
1016+
1017+
xy.append(xy1)
1018+
s.append(s1)
1019+
start += ratio
1020+
1021+
for xyi, si, c in zip(xy, s, colors):
1022+
ax.scatter(
1023+
[x], [y], marker=xyi, s=size * si ** 2, c=c, edgecolor="k", zorder=10
1024+
)
1025+
1026+
1027+
projection = "EPSG:4326"
1028+
1029+
cap_by_lz = gdf.merge(df, right_on="gen_load_zone", left_on="LOAD_AREA").to_crs(
1030+
projection
1031+
)
1032+
1033+
ax = self.get_axes(size=(15, 10))
1034+
ax.set_aspect("equal")
1035+
wecc_states.plot(ax=ax, lw=0.5, edgecolor="white", color="#E5E5E5", zorder=-999)
1036+
1037+
assert not cap_by_lz["gen_type"].isnull().values.any()
1038+
colors = self.get_colors()
1039+
for index, group in cap_by_lz.groupby(["gen_load_zone"]):
1040+
x, y = group["geometry"].iloc[0].x, group["geometry"].iloc[0].y
1041+
group_sum = group.groupby("gen_type")["value"].sum().sort_values()
1042+
group_sum = group_sum[(group_sum != 0)].copy()
1043+
1044+
tech_color = [colors[tech] for tech in group_sum.index.values]
1045+
total_size = group_sum.sum()
1046+
ratios = (group_sum / total_size).values
1047+
pie_plot(x, y, ratios, tech_color, ax=ax, size=total_size)
1048+
ax.axis("off")
1049+
1050+
1051+
9651052
@staticmethod
9661053
def sort_build_years(x):
9671054
def val(v):

switch_model/wecc/get_inputs/get_inputs.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,9 +876,7 @@ def query_db(full_config, skip_cf):
876876
# Make graphing files
877877
graph_config = os.path.join(os.path.dirname(__file__), "graph_config")
878878
print("\tgraph_config files...")
879-
for root, dirs, files in os.walk(graph_config):
880-
for name in files:
881-
shutil.copy(os.path.join(root, name), ".")
879+
shutil.copytree(graph_config, ".", dirs_exist_ok=True)
882880

883881

884882
def write_wind_to_solar_ratio(wind_to_solar_ratio):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
UTF-8
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PROJCS["North_America_Lambert_Conformal_Conic",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",20.0],PARAMETER["Standard_Parallel_2",60.0],PARAMETER["Latitude_Of_Origin",40.0],UNIT["Meter",1.0]]
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
2+
<qgis version="3.20.0-Odense">
3+
<identifier></identifier>
4+
<parentidentifier></parentidentifier>
5+
<language></language>
6+
<type>dataset</type>
7+
<title></title>
8+
<abstract></abstract>
9+
<contact>
10+
<name></name>
11+
<organization></organization>
12+
<position></position>
13+
<voice></voice>
14+
<fax></fax>
15+
<email></email>
16+
<role></role>
17+
</contact>
18+
<links/>
19+
<fees></fees>
20+
<encoding></encoding>
21+
<crs>
22+
<spatialrefsys>
23+
<wkt></wkt>
24+
<proj4></proj4>
25+
<srsid>0</srsid>
26+
<srid>0</srid>
27+
<authid></authid>
28+
<description></description>
29+
<projectionacronym></projectionacronym>
30+
<ellipsoidacronym></ellipsoidacronym>
31+
<geographicflag>false</geographicflag>
32+
</spatialrefsys>
33+
</crs>
34+
<extent>
35+
<spatial crs="" dimensions="2" minz="0" miny="0" maxy="0" minx="0" maxx="0" maxz="0"/>
36+
<temporal>
37+
<period>
38+
<start></start>
39+
<end></end>
40+
</period>
41+
</temporal>
42+
</extent>
43+
</qgis>
1.11 MB
Binary file not shown.
500 Bytes
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
UTF-8
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]

0 commit comments

Comments
 (0)