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

feat: add interconnection map and improve lmp map performance #136

Merged
merged 1 commit into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions postreise/plot/demo/plot_lmp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"outputs": [],
"source": [
"from powersimdata.scenario.scenario import Scenario \n",
"from postreise.plot.plot_lmp import plot_lmp"
"from postreise.plot.plot_lmp import map_lmp"
]
},
{
Expand Down Expand Up @@ -446,7 +446,7 @@
}
],
"source": [
"plot_lmp(s_grid, lmp)"
"map_lmp(s_grid, lmp)"
]
}
],
Expand Down
28 changes: 15 additions & 13 deletions postreise/plot/plot_carbon_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def get_borders(us_states_dat, state_list=None):
return a, b


def plot_states(state_list, col_list, labels_list, us_states_dat=us_states.data):
def plot_states(
state_list, col_list, labels_list, font_size, us_states_dat=us_states.data
):
"""Plots US state borders and allows color coding by state,
for example to represent different emissions goals.

Expand Down Expand Up @@ -97,7 +99,7 @@ def plot_states(state_list, col_list, labels_list, us_states_dat=us_states.data)
y=(max(b1[0]) + min(b1[0])) / 2,
x_units="data",
y_units="data",
text_font_size="20pt",
text_font_size=font_size,
text=labels_list[n],
render_mode="css",
border_line_color="black",
Expand All @@ -106,8 +108,7 @@ def plot_states(state_list, col_list, labels_list, us_states_dat=us_states.data)
background_fill_alpha=0.8,
)
p.add_layout(citation)
output_notebook()
show(p)
return p


def group_lat_lon(bus_map):
Expand Down Expand Up @@ -323,8 +324,7 @@ def map_carbon_emission_bar(
)
p_legend.add_layout(labels)

output_notebook()
show(row(p_legend, p))
return row(p_legend, p)


def map_carbon_emission(
Expand All @@ -335,6 +335,7 @@ def map_carbon_emission(
label_coal="Coal: tons",
label_ng="NG: tons",
us_states_dat=us_states.data,
size_factor=1,
):
"""Makes map of carbon emissions, color code by fuel type. Size/area
indicates emissions.
Expand All @@ -357,8 +358,8 @@ def map_carbon_emission(
{
"x": bus_map["x"],
"y": bus_map["y"],
"coal": (bus_map["coal"] / 1000) ** 0.5,
"ng": (bus_map["ng"] / 1000) ** 0.5,
"coal": (bus_map["coal"] / 1000 * size_factor) ** 0.5,
"ng": (bus_map["ng"] / 1000 * size_factor) ** 0.5,
}
)

Expand All @@ -371,6 +372,7 @@ def map_carbon_emission(
y_axis_location=None,
plot_width=800,
plot_height=800,
output_backend="webgl",
)
p_legend = figure(
x_axis_location=None,
Expand All @@ -380,6 +382,7 @@ def map_carbon_emission(
plot_height=400,
y_range=(0, 4),
x_range=(0, 2),
output_backend="webgl",
)
p.add_tile(get_provider(Vendors.CARTODBPOSITRON_RETINA))
# state borders
Expand Down Expand Up @@ -416,9 +419,9 @@ def map_carbon_emission(
color=np.repeat([color_coal, color_ng], 3),
alpha=0.25,
size=[
(10000000 / 1000) ** 0.5,
(5000000 / 1000) ** 0.5,
(1000000 / 1000) ** 0.5,
(10000000 / 1000 * size_factor) ** 0.5,
(5000000 / 1000 * size_factor) ** 0.5,
(1000000 / 1000 * size_factor) ** 0.5,
]
* 2,
)
Expand All @@ -441,8 +444,7 @@ def map_carbon_emission(
)
p_legend.add_layout(labels)

output_notebook()
show(row(p_legend, p))
return row(p_legend, p)


def map_carbon_emission_comparison(bus_info_and_emission_1, bus_info_and_emission_2):
Expand Down
130 changes: 130 additions & 0 deletions postreise/plot/plot_interconnection_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
from postreise.plot.projection_helpers import project_branch
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.sampledata import us_states
from postreise.plot import plot_carbon_map
from bokeh.tile_providers import get_provider, Vendors


def map_interconnections(grid, us_states_dat=us_states.data):
"""Makes map of transmission color coded by interconnection

:param grid: grid object
:param dict us_states_dat: us_states data file, imported from bokeh.
:return: -- map of transmission
"""
# projection steps for mapping
branch = grid.branch
branch_bus = grid.bus
branch_map = project_branch(branch)
branch_west = branch_map.loc[branch_map.interconnect == "Western"]
branch_east = branch_map.loc[branch_map.interconnect == "Eastern"]
branch_tx = branch_map.loc[branch_map.interconnect == "Texas"]
branch_mdc = grid.dcline

branch_mdc["from_lon"] = branch_bus.loc[branch_mdc.from_bus_id, "lon"].values
branch_mdc["from_lat"] = branch_bus.loc[branch_mdc.from_bus_id, "lat"].values
branch_mdc["to_lon"] = branch_bus.loc[branch_mdc.to_bus_id, "lon"].values
branch_mdc["to_lat"] = branch_bus.loc[branch_mdc.to_bus_id, "lat"].values
branch_mdc = project_branch(branch_mdc)
# state borders
a, b = plot_carbon_map.get_borders(us_states_dat.copy())

# transmission data sources
multi_line_source = ColumnDataSource(
{
"xs": branch_west[["from_x", "to_x"]].values.tolist(),
"ys": branch_west[["from_y", "to_y"]].values.tolist(),
"capacity": (branch_west.rateA) * 0.000225 + 0.1,
}
)

multi_line_source2 = ColumnDataSource(
{
"xs": branch_east[["from_x", "to_x"]].values.tolist(),
"ys": branch_east[["from_y", "to_y"]].values.tolist(),
"capacity": (branch_east.rateA) * 0.000225 + 0.1,
}
)

multi_line_source3 = ColumnDataSource(
{
"xs": branch_tx[["from_x", "to_x"]].values.tolist(),
"ys": branch_tx[["from_y", "to_y"]].values.tolist(),
"capacity": (branch_tx.rateA) * 0.000225 + 0.1,
}
)

multi_line_source4 = ColumnDataSource(
{
"xs": branch_mdc[["from_x", "to_x"]].values.tolist(),
"ys": branch_mdc[["from_y", "to_y"]].values.tolist(),
"capacity": (branch_mdc.Pmax.astype(float)) * 0.000225 + 0.1,
}
)

# Set up figure
tools: str = "pan,wheel_zoom,reset,hover,save"

p = figure(
title="Interconnections",
tools=tools,
x_axis_location=None,
y_axis_location=None,
plot_width=800,
plot_height=800,
output_backend="webgl",
)

# for legend
p.multi_line(
[-1.084288e07, -1.084288e07],
[4.639031e06, 4.639031e06],
color="blue",
line_width=5,
legend="Western",
)
p.multi_line(
[-1.084288e07, -1.084288e07],
[4.639031e06, 4.639031e06],
color="red",
line_width=5,
legend="Eastern",
)
p.multi_line(
[-1.084288e07, -1.084288e07],
[4.639031e06, 4.639031e06],
color="purple",
line_width=5,
legend="ERCOT",
)
p.multi_line(
[-1.084288e07, -1.084288e07],
[4.639031e06, 4.639031e06],
color="green",
line_width=5,
legend="HVDC",
)
p.square(
x=[-1.084288e07], y=[4.639031e06], size=170, fill_color="white", color="white"
)
p.add_tile(get_provider(Vendors.CARTODBPOSITRON))

# state borders
p.patches(a, b, fill_alpha=0.0, line_color="black", line_width=2)
# branches
p.multi_line(
"xs", "ys", color="blue", line_width="capacity", source=multi_line_source
)
p.multi_line(
"xs", "ys", color="red", line_width="capacity", source=multi_line_source2
)
p.multi_line(
"xs", "ys", color="purple", line_width="capacity", source=multi_line_source3
)
p.multi_line(
"xs", "ys", color="green", line_width="capacity", source=multi_line_source4
)
p.legend.location = "bottom_right"

return p
Loading