inspect

inspect

Classes

Name Description
PrintableDict Simple subclass of dict that has nicer printing.
PrintableList Simple subclass of list that has nice printing. Only works flat lists.

PrintableDict

inspect.PrintableDict(*args, key='Key', value='Value', **kwargs)

Simple subclass of dict that has nicer printing.

PrintableList

inspect.PrintableList()

Simple subclass of list that has nice printing. Only works flat lists.

Functions

Name Description
get_attrs Returns a list of which attributes are defined on the target
get_labels Returns a list of labels present on the object
get_params Returns a list of which parameters are defined on the target
get_printable_labels This function is used by the str methods on all classes to get a
get_props Retrieves a list of keys that contain numerical data (i.e. “properties”)
props_to_df Creates a pandas DataFrame from the specified data on the target

get_attrs

inspect.get_attrs(target, return_values=False)

Returns a list of which attributes are defined on the target

Parameters

Name Type Description Default
target dict The dictionary for which the list of attributes is desired. If a nested dictionary is supplied only the top level is scanned. required
return_values bool If True then a dictionary of attributes-values is returned. Otherwise, just a list of attribute names is returned. False

Returns

Name Type Description
params list or dict If return_values is False (default) a list of attribute names is returned. If return_values is True then a dictionary of attribute names and values is returned.

get_labels

inspect.get_labels(
    target,
    pores=[],
    throats=[],
    element=['pore', 'throat'],
    mode='union',
)

Returns a list of labels present on the object

Additionally, this function can return labels applied to a specified set of pores or throats

Parameters

Name Type Description Default
element str Controls whether pore or throat labels are returned. If empty then both are returned (default). ['pore', 'throat']
pores The pores (or throats) whose labels are sought. If left empty a list containing all pore and throat labels is returned. []
mode str Controls how the query should be performed. Only applicable when pores or throats are specified: ============== =================================================== mode meaning ============== =================================================== ‘or’ Returns the labels that are assigned to any of the given locations. Also accepts ‘union’ and ‘any’ ‘and’ Labels that are present on all the given locations. also accepts ‘intersection’ and ‘all’ ‘xor’ Labels that are present on only one of the given locations.Also accepts ‘exclusive_or’ ‘nor’ Labels that are not present on any of the given locations. Also accepts ‘not’ and ‘none’ ‘nand’ Labels that are present on all but one of the given locations ‘xnor’ Labels that are present on more than one of the given locations. ============== =================================================== 'union'

Returns

Name Type Description
A list containing the labels on the object. If pores or
throats are given, the results are filtered according to the
specified mode.

See Also

props keys

Notes

Technically, ‘nand’ and ‘xnor’ should also return pores with none of the labels but these are not included. This makes the returned list more useful.

get_params

inspect.get_params(target, return_values=False)

Returns a list of which parameters are defined on the target

Parameters

Name Type Description Default
target dict The dictionary for which the list of parameters is desired. If a nested dictionary is supplied only the top level is scanned. required
return_values bool If True then a dictionary of parameters-values is returned. Otherwise, just a list of parameter names is returned. False

Returns

Name Type Description
params list or dict If return_values is False (default) a list of parameter names is returned. If return_values is True then a dictionary of parameter names and values is returned.

get_printable_labels

inspect.get_printable_labels(target, suffix='', hr=78 * '―')

This function is used by the str methods on all classes to get a nicely formatted list of labels on the object.

Parameters

Name Type Description Default
target dict The dictionary object with each dictionary key containing a numpy array required
suffix str If provided, this will be attached to the end of every dictionary key so that ‘pore.viscosity’ becomes ‘pore.viscosity.phase_01’. This is a workaround to enhance the printing of component information on mixtures. ''
hr str The horizontal rule to use between the table heading and body 78 * '―'

Returns

Name Type Description
table str A formatted string that will output a 78 character wide table when printed

Notes

The table returned by this function only contains items that boolean arrays. Any numerical arrays are ignored.

See Also

get_printable_props

get_props

inspect.get_props(target, element=['pore', 'throat', 'conduit'])

Retrieves a list of keys that contain numerical data (i.e. “properties”)

Parameters

Name Type Description Default
element str, list of strings Indicates whether 'pore' or 'throat' properties should be returned. The default is ['pore', 'throat'], so both are returned. ['pore', 'throat', 'conduit']

Returns

Name Type Description
props list of strings The names of all dictionary keys on the object that contain numerical data.

props_to_df

inspect.props_to_df(target, element)

Creates a pandas DataFrame from the specified data on the target

Parameters

Name Type Description Default
target dict The dictionary with the data to be converted required
element str The prefix specifying which data to extract (i.e. ‘pore’, ‘throat’, etc) required

Returns

Name Type Description
df DataFrame A pandas DataFrame with each property as a column and each row containing the value of the that property in the corresponding element (i.e. pore index)