Skip to content

Commit

Permalink
add pressure control trace (#680)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkisse authored Dec 20, 2024
1 parent 3959720 commit f535608
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
17 changes: 16 additions & 1 deletion pandapipes/plotting/plotly/simple_plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pandas as pd

from pandapipes.plotting.plotly.traces import create_junction_trace, create_pipe_trace, \
create_valve_trace, create_compressor_trace
create_valve_trace, create_compressor_trace, create_press_control_trace
from pandapower.plotting.plotly.simple_plotly import _simple_plotly_generic, draw_traces

try:
Expand Down Expand Up @@ -129,15 +129,30 @@ def simple_plotly(net, use_pipe_geodata=None, on_map=False,
auto_open=auto_open,
showlegend=showlegend)
if "valve" in net.keys() and len(net.valve) > 0:
if "source_name" in net.valve.columns:
info = net.valve.apply(lambda x: f"{x['name']} <br />{x['source_name']}", axis=1)
else:
info = None
traces.extend(create_valve_trace(net, valves=net.valve.loc[net.valve.opened].index,
size=valve_size, color=valve_color,
infofunc=info,
trace_name="open valves"))
traces.extend(create_valve_trace(net, valves=net.valve.loc[~net.valve.opened].index,
size=valve_size, color=valve_color, dash="dot",
infofunc=info,
trace_name="closed valves"))

if "compressor" in net.keys() and len(net.compressor) > 0:
traces.extend(create_compressor_trace(net, size=compressor_size, color=compressor_color))
if "press_control" in net.keys() and len(net.press_control) > 0:
traces.extend(
create_press_control_trace(net, size=compressor_size, color="cyan",
trace_name='compressors SPO',
legendgroup='compressors SPO'))
traces.extend(create_junction_trace(net, net.press_control.controlled_junction.values,
color="red", size=10,
trace_name="controlled junction",
legendgroup='compressors SPO'))
if additional_traces:
if isinstance(additional_traces, dict):
traces.append(additional_traces)
Expand Down
27 changes: 26 additions & 1 deletion pandapipes/plotting/plotly/traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,29 @@ def create_compressor_trace(net, compressors=None, use_pipe_geodata=False, size=
cmap=cmap, cbar_title=cbar_title, show_colorbar=show_colorbar,
cmap_vals=cmap_vals, cmin=cmin, cmax=cmax, cpos=cpos,
branch_element=branch_element, separator_element=separator_element,
node_element=node_element, cmap_vals_category="compr_power_mw")
node_element=node_element, cmap_vals_category="compr_power_mw")


def create_press_control_trace(net, compressors=None, size=3.0,
color='cyan', infofunc=None, trace_name='pressure controller',
legendgroup='pressure controller'):
branch_element = "press_control"
node_element = "junction"
separator_element = "valve"
respect_valves = False
cmap = None
cbar_title = None
show_colorbar = True
cmap_vals = None
cmin = None
cmax = None
cpos = 1.1
use_pipe_geodata = False

return _create_branch_trace(net=net, branches=compressors, use_branch_geodata=use_pipe_geodata,
respect_separators=respect_valves, width=size, color=color,
infofunc=infofunc, trace_name=trace_name, legendgroup=legendgroup,
cmap=cmap, cbar_title=cbar_title, show_colorbar=show_colorbar,
cmap_vals=cmap_vals, cmin=cmin, cmax=cmax, cpos=cpos,
branch_element=branch_element, separator_element=separator_element,
node_element=node_element, cmap_vals_category="controlled_p_bar")

0 comments on commit f535608

Please sign in to comment.