idaes.vis package

The idaes.vis subpackage contains the framework and implementation of plots that are expected to be of general utility within the IDAES framework.

For users, an entry point is provided for IDAES classes to produce plots with the idaes.vis.plotbase.PlotRegistry singleton.

Plots will inherit from the interface in idaes.vis.plotbase.PlotBase, which provides some basic methods.

The current implementations all use the Python “bokeh” package, and can be found in idaes.vis.bokeh_plots.

For more details, please refer to the visualization section of the main IDAES documentation.

Submodules

idaes.vis.bokeh_plots module

Bokeh plots.

class idaes.vis.bokeh_plots.BokehPlot(current_plot=None)[source]
annotate(x, y, label)[source]

Annotate a plot with a given point and a label.

Parameters:
  • x – Value of independent variable.
  • y – Value of dependent variable.
  • label – Text label.
Returns:

None

Raises:

None

resize(height=-1, width=-1)[source]

Resize a plot’s height and width.

Parameters:
  • height – Height in screen units.
  • width – Width in screen units.
Returns:

None

Raises:

None

save(destination)[source]

Save the current plot object to HTML in filepath provided by destination.

Parameters:destination – Valid file path to save HTML to.
Returns:filename where HTML is saved.
Raises:None
show(in_notebook=True)[source]

Display plot in a Jupyter notebook.

Parameters:
  • self – Plot object.
  • in_notebook – Display in Jupyter notebook or generate HTML file.
Returns:

None

Raises:

None

class idaes.vis.bokeh_plots.HeatExchangerNetwork(exchangers, stream_list, mark_temperatures_with_tooltips=False, mark_modules_with_tooltips=False, stage_width=2, y_stream_step=1)[source]
class idaes.vis.bokeh_plots.ProfilePlot(data_frame, x='', y=None, title='', xlab='', ylab='', y_axis_type='auto', legend=None)[source]

idaes.vis.plotbase module

Base classes for visualization and plotting in IDAES.

Create new plots by inheriting from PlotBase. See the idaes.vis.bokeh_plots module for examples.

class idaes.vis.plotbase.PlotBase(current_plot)[source]

Abstract base class for a plot.

annotate(x, y, label: str)[source]

Annotate a plot with a given point and a label.

Parameters:
  • x – Value of independent variable.
  • y – Value of dependent variable.
  • label – Text label.
resize(height: int = -1, width: int = -1)[source]

Resize a plot’s height and width.

Parameters:
  • height – Height in screen units.
  • width – Width in screen units.
Returns:

None

Raises:

None

save(destination: str)[source]

Save the current plot object to HTML in filepath provided by destination.

Parameters:destination – Valid file path to save HTML to.
Returns:filename where HTML is saved.
Raises:None
show(in_notebook=True)[source]

Display plot in a Jupyter notebook.

Parameters:in_notebook – Display in Jupyter notebook or generate HTML file.
Returns:None
Raises:None
classmethod validate(data_frame: pandas.core.frame.DataFrame, x: str, y: List[T], legend=None)[source]

Validate that the plot parameters are valid.

Parameters:
  • data_frame – a pandas data frame of any type.
  • x – Key in data-frame to use as x-axis.
  • y – Keys in data-frame to use as y-axis.
  • legend – List of labels to use as legend for a plot.
Returns:

True, ‘’ on valid data frames (if x and y are in the data frame keys) False, “message” on invalid data

class idaes.vis.plotbase.PlotRegistry[source]

Set of associations between objects/classes + a plot name, and the parameters and values needed to perform the plot.

The basic idea is to create a set of named plots associated with a given IDAES class, and then allow the user or other APIs to invoke that plot once the data is populated in an instance of the class. This keeps the details of how to create plots of a given type in the classes that will create them.

For example:

class MyIdaesClass(ProcessBase):
  # .. code for the class
  def plot_setup(self, plot_class):
      # .. details of creating plot_instance from object contents ..
      return plot_instance
PlotRegistry().register(MyIdaesClass, 'basic', MyIdaesClass.plot_setup)

# .. and, later ..
obj = MyIdaesClass(...)
# .. do things that fill "obj" with data ..
# now create the plot
plot = PlotRegistry().get(obj, 'basic')
plot.show()

XXX: This class is not actually used (yet) by any of the IDAES models.

get(obj, name: str)[source]

Get a plot object for the given object + name.

Parameters:
  • obj – Object for which to get the plot
  • name – Registered name of plot to get
Returns:

Return value of setup function given to register(), or, if that is empty, the retrieved plot object.

register(obj, name: str, plot: Type[CT_co], setup_fn=None, overwrite: bool = False)[source]

Register an object/plot combination.

Parameters:
  • obj – Class or instance
  • name – Name for this association
  • plot – Plot class
  • setup_fn – Optional setup function to call. Function should take two arguments: plot class instance, obj assoc. with plot.
  • overwrite – If true, allow overwrite of existing entry in the registry
remove_all()[source]

Remove all entries from the registry.

Since the registry is a singleton, this removes all entries from ALL instances. Use with care.

idaes.vis.plotutils module

class idaes.vis.plotutils.HENStreamType[source]

Enum type defining hot and cold streams

idaes.vis.plotutils.add_exchanger_labels(plot, x, y_start, y_end, label_font_size, exchanger, module_marker_line_color, module_marker_fill_color, mark_modules_with_tooltips)[source]

Plot exchanger labels for an exchanger (for Q and A) on a heat exchanger network diagram and add module markers (if needed).

Parameters:
  • plot – bokeh.plotting.plotting.figure instance.
  • label_font_size – font-size for labels.
  • x – x-axis coordinate of exchanger (exchangers are vertical lines so we just need 1 x-value)
  • y_start – y-axis coordinate of exchanger start.
  • y_end – y-axis coordinate of exchanger end.
  • exchanger

    exchanger dictionary of the form:

    {'hot': 'H2', 'cold': 'C1', 'Q': 1400, 'A': 159, 'annual_cost': 28358,
     'stg': 2}
    
  • module_marker_line_color – color of border of the module marker.
  • module_marker_fill_color – color inside the module marker.
  • mark_modules_with_tooltips – whether to add tooltips to plot or not (currently not utilized).
Returns:

modified bokeh.plotting.plotting.figure instance with labels added.

Raises:

None

idaes.vis.plotutils.add_module_markers_to_heat_exchanger_plot(plot, x, y, modules, line_color, fill_color, mark_modules_with_tooltips)[source]

Plot module markers as tooltips to a heat exchanger network diagram.

Parameters:
  • plot – bokeh.plotting.plotting.figure instance.
  • x – x-axis coordinate of module marker tooltip.
  • y – y-axis coordinate of module marker tooltip.
  • modules – dict containing modules.
  • line_color – color of border of the module marker.
  • fill_color – color inside the module marker.
  • mark_modules_with_tooltips – whether to add tooltips to plot or not (currently not utilized).
Returns:

bokeh.plotting.plotting.figure instance with module markers added.

Raises:

None

idaes.vis.plotutils.get_color_dictionary(set_to_color)[source]

Given a set, return a dictionary of the form:

{'set_member': valid_bokeh_color}
Args:
set_to_color: set of unique elements, e.g: [1,2,3] or [“1”, “2”, “3”]
Returns:

Dictionary of the form:

{'set_member': valid_bokeh_color}
Raises:
None
idaes.vis.plotutils.get_stream_y_values(exchangers, hot_streams, cold_streams, y_stream_step=1)[source]

Return a dict containing the layout of the heat exchanger diagram including any stage splits.

Parameters:
  • exchangers

    List of exchangers where each exchanger is a dict of the form:

    {'hot': 'H2', 'cold': 'C1', 'Q': 1400, 'A': 159, 'annual_cost': 28358,
    'stg': 2}
    

    where hot is the hot stream name, cold is the cold stream name, A is the area (in m^2), annual_cost is the annual cost in $, Q is the amount of heat transferred from one stream to another in a given exchanger and stg is the stage the exchanger belongs to. Additionally a ‘utility_type’ can specify if we draw the cold stream as water (idaes.vis.plot_utils.HENStreamType.cold_utility) or the hot stream as steam (idaes.vis.plot_utils.HENStreamType.hot_utility).

    Additionally, the exchanger could have the key ‘modules’, like this:

    {'hot': 'H1', 'cold': 'C1', 'Q': 667, 'A': 50, 'annual_cost': 10979, 'stg': 3,
    'modules': {10: 1, 20: 2}}
    
  • hot_streams

    List of dicts representing hot streams where each item is a dict of the form:

    {'name':'H1', 'temps': [443, 435, 355, 333], 'type': HENStreamType.hot}
    
  • cold_streams

    List of dicts representing cold streams where each item is a dict of the form:

    {'name':'H1', 'temps': [443, 435, 355, 333], 'type': HENStreamType.hot}
    
  • y_stream_step – how many units on the HEN diagram to leave between each stream (or sub-stream) and the one above it. Defaults to 1.
Returns:

* stream_y_values_dict : a dict of each stream name as key and value being a dict of the form

{'default_y_value': 2, 'split_y_values': [1,3]}.

This indicates what the default y value of this stream will be on the diagram and what values we’ll use when it splits.

* hot_split_streams : list of tuples of the form (a,b) where a is a hot stream name and b is the max. times it will split over all the stages.

* cold_split_streams : list of tuples of the form (a,b) where a is a cold stream name and b is the max. times it will split over all the stages.

Return type:

Tuple containing 3 dictionaries to be used when plotting the HEN

Raises:

None

idaes.vis.plotutils.is_hot_or_cold_utility(exchanger)[source]

Return if an exchanger is a hot or a cold utility by checking if it has the key utility_type.

Parameters:exchanger – dict representing the exchanger.
Returns:True if utility_type in the exchanger dict passed.
Raises:None
idaes.vis.plotutils.plot_line_segment(plot, x_start, x_end, y_start, y_end, color='white', legend=None)[source]

Plot a line segment on a bokeh figure.

Parameters:
  • plot – bokeh.plotting.plotting.figure instance.
  • x_start – x-axis coordinate of 1st point in line.
  • x_end – x-axis coordinate of 2nd point in line.
  • y_start – y-axis coordinate of 1st point in line.
  • y_end – y-axis coordinate of 2nd point in line.
  • color – color of line (defaults to white).
  • legend – what legend to associate with (defaults to None).
Returns:

modified bokeh.plotting.plotting.figure instance with line added.

Raises:

None

idaes.vis.plotutils.plot_stream_arrow(plot, line_color, stream_arrow_temp, temp_label_font_size, x_start, x_end, y_start, y_end, stream_name=None)[source]

Plot a stream arrow for the heat exchanger network diagram.

Parameters:
  • plot – bokeh.plotting.plotting.figure instance.
  • line_color – color of arrow (defaults to white).
  • stream_arrow_temp – Tempreature of the stream to be plotted.
  • temp_label_font_size – font-size of the temperature label to be added.
  • x_start – x-axis coordinate of arrow base.
  • x_end – x-axis coordinate of arrow head.
  • y_start – y-axis coordinate of arrow base.
  • y_end – y-axis coordinate of arrow head.
  • stream_name – Name of the stream to add as a label to arrow (defaults to None).
Returns:

modified bokeh.plotting.plotting.figure instance with stream arrow added.

Raises:

None

idaes.vis.plotutils.turn_off_grid_and_axes_ticks(plot)[source]

Turn off axis ticks and grid lines on a bokeh figure object.

Parameters:plot – bokeh.plotting.plotting.figure instance.
Returns:modified bokeh.plotting.plotting.figure instance.
Raises:None