Table Methods

Table Methods#

The IDAES toolset contains a number of methods for generating and displaying summary tables of data in the form of pandas DataFrames.

Available Methods#

idaes.core.util.tables.arcs_to_stream_dict(blk, additional=None, descend_into=True, sort=False, prepend=None, s=None)[source]#

Creates a stream dictionary from the Arcs in a model, using the Arc names as keys. This can be used to automate the creation of the streams dictionary needed for the create_stream_table_dataframe() and stream_states_dict() functions.

Parameters:
  • blk (pyomo.environ._BlockData) – Pyomo model to search for Arcs

  • additional (dict) – Additional states to add to the stream dictionary, which aren’t represented by arcs in blk, for example feed or product streams without Arcs attached or states internal to a unit model.

  • descend_into (bool) – If True, search subblocks for Arcs as well. The default is True.

  • sort (bool) – If True sort keys and return an OrderedDict

  • prepend (str) – Prepend a string to the arc name joined with a ‘.’. This can be useful to prevent conflicting names when sub blocks contain Arcs that have the same names when used in combination with descend_into=False.

  • s (dict) – Add streams to an existing stream dict.

Returns:

Dictionary with Arc names as keys and the Arcs as values.

idaes.core.util.tables.create_stream_table_dataframe(streams, true_state=False, time_point=0, orient='columns')[source]#

Method to create a stream table in the form of a pandas dataframe. Method takes a dict with name keys and stream values. Use an OrderedDict to list the streams in a specific order, otherwise the dataframe can be sorted later.

Parameters:
  • streams – dict with name keys and stream values. Names will be used as display names for stream table, and streams may be Arcs, Ports or StateBlocks.

  • true_state – indicated whether the stream table should contain the display variables define in the StateBlock (False, default) or the state variables (True).

  • time_point – point in the time domain at which to generate stream table (default = 0)

  • orient – orientation of stream table. Accepted values are ‘columns’ (default) where streams are displayed as columns, or ‘index’ where stream are displayed as rows.

Returns:

A pandas DataFrame containing the stream table data.

idaes.core.util.tables.create_stream_table_ui(streams, true_state=False, time_point=0, orient='columns', precision=5)[source]#

Method to create a stream table in the form of a pandas dataframe. Method takes a dict with name keys and stream values. Use an OrderedDict to list the streams in a specific order, otherwise the dataframe can be sorted later. Note: This function process each stream the same way create_stream_table_dataframe does.

Parameters:
  • streams – dict with name keys and stream values. Names will be used as display names for stream table, and streams may be Arcs, Ports or StateBlocks.

  • true_state – indicated whether the stream table should contain the display variables define in the StateBlock (False, default) or the state variables (True).

  • time_point – point in the time domain at which to generate stream table (default = 0)

  • orient – orientation of stream table. Accepted values are ‘columns’ (default) where streams are displayed as columns, or ‘index’ where stream are displayed as rows.

  • precision – rounding the floating numbers to the give precision. Default is 5 digits after the floating point.

Returns:

A pandas DataFrame containing the stream table data.

idaes.core.util.tables.generate_table(blocks, attributes, heading=None, exception=True)[source]#

Create a Pandas DataFrame that contains a list of user-defined attributes from a set of Blocks.

Parameters:
  • blocks (dict) – A dictionary with name keys and BlockData objects for values. Any name can be associated with a block. Use an OrderedDict to show the blocks in a specific order, otherwise the dataframe can be sorted later.

  • attributes (list or tuple of strings) – Attributes to report from a Block, can be a Var, Param, or Expression. If an attribute doesn’t exist or doesn’t have a valid value, it will be treated as missing data.

  • heading (list or tuple of strings) – A list of strings that will be used as column headings. If None the attribute names will be used.

  • exception (bool) – If True, raise exceptions related to invalid or missing indexes. If false missing or bad indexes are ignored and None is used for the table value. Setting this to False allows tables where some state blocks have the same attributes with different indexing. (default is True)

Returns:

A Pandas dataframe containing a data table

Return type:

(DataFrame)

idaes.core.util.tables.stream_states_dict(streams, time_point=0)[source]#

Method to create a dictionary of state block representing stream states. This takes a dict with stream name keys and stream values.

Parameters:
  • streams – dict with name keys and stream values. Names will be used as display names for stream table, and streams may be Arcs, Ports or StateBlocks.

  • time_point – point in the time domain at which to generate stream table (default = 0)

Returns:

A pandas DataFrame containing the stream table data.

idaes.core.util.tables.stream_table_dataframe_to_string(stream_table, **kwargs)[source]#

Method to print a stream table from a dataframe. Method takes any argument understood by DataFrame.to_string