Skip to content

Commit

Permalink
add simple functions for valve and compressor traces in plotly
Browse files Browse the repository at this point in the history
  • Loading branch information
jkisse committed Nov 27, 2023
1 parent f770cb8 commit d027ffd
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pandapipes/plotting/plotly/simple_plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import pandas as pd

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

try:
Expand Down Expand Up @@ -89,8 +90,10 @@ def get_hoverinfo(net, element, precision=3, sub_index=None):

def simple_plotly(net, use_pipe_geodata=None, on_map=False,
projection=None, map_style='basic', figsize=1, aspectratio='auto', pipe_width=1,
junction_size=10, ext_grid_size=20.0, junction_color="blue", pipe_color='grey',
pressure_reg_color='green', ext_grid_color="yellow", filename='temp-plot.html',
junction_size=10, ext_grid_size=20.0, valve_size=3.0, compressor_size=3,
junction_color="blue", pipe_color='grey', pressure_reg_color='green',
ext_grid_color="yellow", valve_color="black", compressor_color="cyan",
filename='temp-plot.html',
auto_open=True, showlegend=True, additional_traces=None):
respect_valves = False # TODO, not implemented yet
node_element = "junction"
Expand Down Expand Up @@ -125,7 +128,16 @@ def simple_plotly(net, use_pipe_geodata=None, on_map=False,
filename=filename,
auto_open=auto_open,
showlegend=showlegend)
if "valve" in net.keys() and len(net.valve) > 0:
traces.extend(create_valve_trace(net, valves=net.valve.loc[net.valve.opened].index,
size=valve_size, color=valve_color,
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",
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 additional_traces:
if isinstance(additional_traces, dict):
traces.append(additional_traces)
Expand Down
49 changes: 49 additions & 0 deletions pandapipes/plotting/plotly/traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,52 @@ def create_pipe_trace(net, pipes=None, use_pipe_geodata=True, respect_valves=Fal
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="vmean_m_s")


def create_valve_trace(net, valves=None, use_valve_geodata=False, size=1.0,
color='black', infofunc=None, trace_name='valves', legendgroup='valves',
dash="solid"):
branch_element = "valve"
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

return _create_branch_trace(net=net, branches=valves, use_branch_geodata=use_valve_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="vmean_m_s",
dash=dash)


def create_compressor_trace(net, compressors=None, use_pipe_geodata=False, size=3.0,
color='cyan', infofunc=None, trace_name='compressors',
legendgroup='compressors'):
branch_element = "compressor"
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

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="compr_power_mw")

0 comments on commit d027ffd

Please sign in to comment.