bio_rtd.core

Module with abstract classes.

Inlet

class bio_rtd.core.Inlet(t, species_list, inlet_id, gui_title)[source]

Bases: bio_rtd.core.DefaultLoggerLogic, abc.ABC

Generates starting flow rate and concentration profiles.

Parameters
  • t (ndarray) – Simulation time vector. Starts with 0 and has a constant time step.

  • species_list (Sequence[str]) – List with names of simulating process fluid species.

  • inlet_id (str) – Unique identifier of an instance. It is stored in uo_id.

  • gui_title (str) – Readable title of an instance.

species_list: Sequence[str]

List with names of simulating process fluid species.

uo_id: str

Unique identifier of the instance.

gui_title: str

Human readable title (for plots).

adj_par_list: Sequence[bio_rtd.adj_par.AdjustableParameter]

List of adjustable parameters exposed to the GUI.

get_t()[source]

Get simulation time vector.

Return type

ndarray

get_n_species()[source]

Get number of process fluid species.

Return type

int

abstract refresh()[source]

Updates output profiles.

Internally it updates self._f_out and self._c_out based on instance attribute values.

get_result()[source]

Get flow rate and concentration profiles.

Return type

Tuple[ndarray, ndarray]

Returns

  • f_out – Flow rate profile.

  • c_out – Concentration profile.

property log

Reference of the RtdLogger instance.

Setter also plants instance data tree into passed logger.

If logger is requested, but not yet set, then a bio_rtd.logger.DefaultLogger is instantiated.

Return type

RtdLogger

set_logger_from_parent(parent_id, logger)

Inherit logger from parent.

Parameters
  • parent_id (str) – Unique identifier of parent instance.

  • logger (RtdLogger) – Logger from parent instance.

UnitOperation

class bio_rtd.core.UnitOperation(t, uo_id, gui_title='')[source]

Bases: bio_rtd.core.DefaultLoggerLogic, abc.ABC

Processes flow rate and concentration profiles.

Parameters
  • t (ndarray) – Simulation time vector. Starts with 0 and has a constant time step.

  • uo_id (str) – Unique identifier.

  • gui_title (str) – Readable title for GUI.

uo_id: str

Unique identifier of the instance

gui_title: str

Readable title for GUI

adj_par_list

List of adjustable parameters exposed to the GUI.

Type

list of bio_rtd.adj_par.AdjustableParameter

gui_hidden: bool

Hide the of the unit operation (default False).

discard_inlet_until_t: float

Discard inlet until given time.

discard_inlet_until_min_c: numpy.ndarray

Discard inlet until given concentration is reached.

discard_inlet_until_min_c_rel: numpy.ndarray

Discard inlet until given concentration relative to is reached.

Specified concentration is relative to the max concentration.

discard_inlet_n_cycles: int

Discard first n cycles of the periodic inlet flow rate profile.

discard_outlet_until_t: float

Discard outlet until given time.

discard_outlet_until_min_c: numpy.ndarray

Discard outlet until given concentration is reached.

discard_outlet_until_min_c_rel: numpy.ndarray

Discard outlet until given concentration relative to is reached.

Specified concentration is relative to the max concentration.

discard_outlet_n_cycles: int

Discard first n cycles of the periodic outlet flow rate profile.

evaluate(f_in, c_in)[source]

Evaluate the propagation throughout the unit operation.

Parameters
  • c_in (ndarray) – Inlet concentration profile with shape (n_species, n_time_steps).

  • f_in (array) – Inlet flow rate profile with shape (n_time_steps,).

Return type

Tuple[ndarray, ndarray]

Returns

  • f_out – Outlet flow rate profile.

  • c_out – Outlet concentration profile.

get_result()[source]

Returns existing flow rate and concentration profiles.

Return type

Tuple[ndarray, ndarray]

Returns

  • f_out – Outlet flow rate profile.

  • c_out – Outlet concentration profile.

property log

Reference of the RtdLogger instance.

Setter also plants instance data tree into passed logger.

If logger is requested, but not yet set, then a bio_rtd.logger.DefaultLogger is instantiated.

Return type

RtdLogger

set_logger_from_parent(parent_id, logger)

Inherit logger from parent.

Parameters
  • parent_id (str) – Unique identifier of parent instance.

  • logger (RtdLogger) – Logger from parent instance.

RtdModel

class bio_rtd.core.RtdModel(inlet, dsp_uo_chain, logger=None, title='RtdModel', desc='')[source]

Bases: bio_rtd.core.DefaultLoggerLogic, abc.ABC

Combines Inlet and a train of UnitOperation-s into a model.

The logger assigned to the instance of RtdModel is passed on to bio_rtd.core.Inlet and bio_rtd.core.UnitOperation instances.

Parameters
  • inlet (Inlet) – Inlet profile.

  • dsp_uo_chain (Sequence[UnitOperation]) – Sequence of unit operations. The sequence needs to be in order.

  • logger (Optional[RtdLogger]) – Logger for sending status messages and storing intermediate data.

  • title (str) – Title of the model.

  • desc (str) – Description of the model.

inlet

Inlet for self.dsp_uo_chain

Type

bio_rtd.core.Inlet

dsp_uo_chain

Chain of unit operations in the process.

Unit operations need to be in proper order.

The logger in unit operations is overridden by the logger from this model.

Type

sequence of bio_rtd.core.UnitOperation

title

Human readable title (mostly for plots)

desc

Human readable description (also mostly for plots)

get_dsp_uo(uo_id)[source]

Get reference to a UnitOperation with specified uo_id.

Return type

UnitOperation

recalculate(start_at=- 1, on_update_callback=None)[source]

Recalculate process fluid propagation.

Parameters
  • start_at (int) –

    Index of first unit operation for re-evaluation.

    Indexing starts at 0 (-1 for the inlet). Default = -1.

  • on_update_callback (Optional[Callable[[int], None]]) –

    Optional callback function which receives an integer.

    The integer corresponds to the index of re-evaluated unit operation, starting with 0 (-1 for inlet).

    This can serve as a trigger for updating UI or any other post-processing after re-evaluation of unit operations.

property log

Reference of the RtdLogger instance.

Setter also plants instance data tree into passed logger.

If logger is requested, but not yet set, then a bio_rtd.logger.DefaultLogger is instantiated.

Return type

RtdLogger

set_logger_from_parent(parent_id, logger)[source]

Inherit logger from parent.

Parameters
  • parent_id (str) – Unique identifier of parent instance.

  • logger (RtdLogger) – Logger from parent instance.

UserInterface

class bio_rtd.core.UserInterface(rtd_model)[source]

Bases: abc.ABC

Wrapper around RtdModel suitable for building GUI on top of it.

Parameters

rtd_model (RtdModel) – Residence time distribution model.

start_at: int

Index of first unit operation for re-evaluation.

Indexing starts at 0 (-1 for the inlet). Default = -1.

species_label: Sequence[str]

Labels of the species in concentration array.

Initially inherited from bio_rtd.core.Inlet instance.

x_label: str

Label of x axis (time). Default = ‘t’

y_label_c: str

Label of y axis (concentration). Default = ‘c’

y_label_f: str

Label of y axis (flow rate). Default = ‘f’

recalculate(forced=False)[source]

Re-evaluates the model from the start_at index onwards.

Parameters

forced – If true, the entire model (inlet + unit operations) is re-evaluated. The same can be achieved by setting start_at to -1.

abstract build_ui()[source]

Build the UI from scratch.

PDF

class bio_rtd.core.PDF(t, pdf_id='')[source]

Bases: bio_rtd.core.ParameterSetList, bio_rtd.core.DefaultLoggerLogic, abc.ABC

Abstract class for defining probability distribution functions.

Parameters
  • t (ndarray) – Simulation time vector.

  • pdf_id (str) – Unique identifier of the PDF instance.

trim_and_normalize

Trim edges of the pdf and normalize it afterwards.

Default = True.

Relative threshold value is specified by cutoff_relative_to_max.

Normalization is performed after the trimming. The area of pd == 1.

cutoff_relative_to_max

Cutoff as a share of max value of the pdf (default 0.0001).

It is defined to avoid very long tails of the distribution.

Cutoff is enabled if trim_and_normalize == True.

update_pdf(**kwargs)[source]

Re-calculate PDF based on specified parameters.

The calculated probability distribution can be obtained by get_p()

Parameters

**kwargs – Should contain keys from one of the group in POSSIBLE_KEY_GROUPS. It may contain additional keys from OPTIONAL_KEYS.

get_p()[source]

Get probability distribution.

Returns

p – Evaluated probability distribution function.

Corresponding time axis starts with 0 and has a fixed step size (_dt).

If trim_and_normalize == 1 then sum(p * _dt) == 1.

Return type

ndarray

abstract property OPTIONAL_KEYS

Optional additional keys.

Examples

OPTIONAL_KEYS = [‘skew’, ‘t_delay’]

Return type

Sequence[str]

abstract property POSSIBLE_KEY_GROUPS

Possible key combinations.

Examples

POSSIBLE_KEY_GROUPS = [[‘v_void’], [‘f’, ‘rt_mean’]]

Return type

Sequence[Sequence[str]]

assert_and_get_provided_kv_pairs(**kwargs)
Parameters

**kwargs – Inputs to calc_pdf(**kwargs) function

Returns

Filtered **kwargs so the keys contain first possible key group in POSSIBLE_KEY_GROUPS and any number of optional keys from OPTIONAL_KEYS.

Return type

dict

Raises

ValueError – If **kwargs do not contain keys from any of the groups in POSSIBLE_KEY_GROUPS.

property log

Reference of the RtdLogger instance.

Setter also plants instance data tree into passed logger.

If logger is requested, but not yet set, then a bio_rtd.logger.DefaultLogger is instantiated.

Return type

RtdLogger

set_logger_from_parent(parent_id, logger)

Inherit logger from parent.

Parameters
  • parent_id (str) – Unique identifier of parent instance.

  • logger (RtdLogger) – Logger from parent instance.

ChromatographyLoadBreakthrough

class bio_rtd.core.ChromatographyLoadBreakthrough(dt, bt_profile_id='ChromatographyLoadBreakthrough')[source]

Bases: bio_rtd.core.ParameterSetList, bio_rtd.core.DefaultLoggerLogic, abc.ABC

What parts of the load bind to the column.

Parameters
  • dt (float) – Time step duration.

  • bt_profile_id (str) – Unique identifier of the PDF instance. Used for logs.

update_btc_parameters(**kwargs)[source]

Update binding dynamics for a given set of parameters.

Parameters

**kwargs – Should contain keys from one of the group in POSSIBLE_KEY_GROUPS. It may contain additional keys from OPTIONAL_KEYS.

calc_c_bound(f_load, c_load)[source]

Calculates what parts of load bind to the column.

The default implementation calculates cumulative mass of the load material and passes it to _update_btc_parameters() abstract method for evaluation on what shares of the load bind to the column. Those shares are then multiplied by c_load in order to obtain resulting c_bound.

This method is meant to be overridden, if needed.

Parameters
  • f_load (ndarray) – Load flow rate profile.

  • c_load (ndarray) – Load concentration profile. Concentration profile should include only species which bind to the column.

Returns

c_bound – Parts of the load that bind to the column during the load step.

c_bound has the same shape as c_load.

Return type

ndarray

abstract get_total_bc()[source]

Total binding capacity.

Meant e.g. for determining column utilization.

Return type

float

abstract property OPTIONAL_KEYS

Optional additional keys.

Examples

OPTIONAL_KEYS = [‘skew’, ‘t_delay’]

Return type

Sequence[str]

abstract property POSSIBLE_KEY_GROUPS

Possible key combinations.

Examples

POSSIBLE_KEY_GROUPS = [[‘v_void’], [‘f’, ‘rt_mean’]]

Return type

Sequence[Sequence[str]]

assert_and_get_provided_kv_pairs(**kwargs)
Parameters

**kwargs – Inputs to calc_pdf(**kwargs) function

Returns

Filtered **kwargs so the keys contain first possible key group in POSSIBLE_KEY_GROUPS and any number of optional keys from OPTIONAL_KEYS.

Return type

dict

Raises

ValueError – If **kwargs do not contain keys from any of the groups in POSSIBLE_KEY_GROUPS.

property log

Reference of the RtdLogger instance.

Setter also plants instance data tree into passed logger.

If logger is requested, but not yet set, then a bio_rtd.logger.DefaultLogger is instantiated.

Return type

RtdLogger

set_logger_from_parent(parent_id, logger)

Inherit logger from parent.

Parameters
  • parent_id (str) – Unique identifier of parent instance.

  • logger (RtdLogger) – Logger from parent instance.

ParameterSetList

class bio_rtd.core.ParameterSetList[source]

Bases: abc.ABC

Abstract class for asserting keys in key-value pairs.

Key-value pairs passed to assert_and_get_provided_kv_pairs should contain all keys from (at least) one of the key groups in POSSIBLE_KEY_GROUPS. The method returns key-value pars with keys from that group and all passed keys that can be also found in OPTIONAL_KEYS.

Examples

>>> class DummyClass(ParameterSetList):
...    POSSIBLE_KEY_GROUPS = [['par_1'], ['par_2a', 'par_2b']]
...    OPTIONAL_KEYS = ['key_plus_1', 'key_plus_2']
>>>
>>> dc = DummyClass()
>>> dc.assert_and_get_provided_kv_pairs(par_1=1, par_2a=2)
{'par_1': 1}
>>> dc.assert_and_get_provided_kv_pairs(par_2a=1, par_2b=2,
...                                     key_plus_1=3, key_plus_9=2)
{'par_2a': 1, 'par_2b': 2, 'key_plus_1': 3}
>>> dc.assert_and_get_provided_kv_pairs(
...     key_plus_1=1) 
Traceback (most recent call last):
KeyError: "Keys ... do not contain any of the required groups: ...
abstract property POSSIBLE_KEY_GROUPS

Possible key combinations.

Examples

POSSIBLE_KEY_GROUPS = [[‘v_void’], [‘f’, ‘rt_mean’]]

Return type

Sequence[Sequence[str]]

abstract property OPTIONAL_KEYS

Optional additional keys.

Examples

OPTIONAL_KEYS = [‘skew’, ‘t_delay’]

Return type

Sequence[str]

assert_and_get_provided_kv_pairs(**kwargs)[source]
Parameters

**kwargs – Inputs to calc_pdf(**kwargs) function

Returns

Filtered **kwargs so the keys contain first possible key group in POSSIBLE_KEY_GROUPS and any number of optional keys from OPTIONAL_KEYS.

Return type

dict

Raises

ValueError – If **kwargs do not contain keys from any of the groups in POSSIBLE_KEY_GROUPS.

DefaultLoggerLogic

class bio_rtd.core.DefaultLoggerLogic(logger_parent_id)[source]

Bases: abc.ABC

Default binding of the RtdLogger to a class.

The class holds a reference to a bio_rtd.logger.RtdLogger instance. When the class receives the instance, it plants a data tree into it. If the class is asked to provide the instance before it received one, then an instance of bio_rtd.logger.DefaultLogger is created and passed on.

Parameters

logger_parent_id (str) –

Custom unique id that belongs to the instance of the class.

The data tree of this instance is stored in bio_rtd.logger.RtdLogger under the logger_parent_id.

Examples

>>> logger_parent_id = "parent_unit_operation"
>>> l = DefaultLoggerLogic(logger_parent_id)
>>> isinstance(l.log, _logger.DefaultLogger)
True
>>> # Log error: DefaultLogger raises RuntimeError.
>>> l.log.e("Error Description")
Traceback (most recent call last):
RuntimeError: Error Description
>>> # Log waring: DefaultLogger prints it.
>>> l.log.w("Warning Description")
Warning Description
>>> # Log info: DefaultLogger ignores it.
>>> l.log.i("Info")
>>> l.log.log_data = True
>>> l.log.log_level = _logger.RtdLogger.DEBUG
>>> l.log.i_data(l._log_tree, "a", 3)  # store value in logger
>>> l.log.d_data(l._log_tree, "b", 7)  # store at DEBUG level
>>> l.log.get_data_tree(logger_parent_id)["b"]
7
>>> l.log = _logger.StrictLogger()
>>> # Log waring: StrictLogger raises RuntimeError.
>>> l.log.w("Warning Info")
Traceback (most recent call last):
RuntimeError: Warning Info
property log

Reference of the RtdLogger instance.

Setter also plants instance data tree into passed logger.

If logger is requested, but not yet set, then a bio_rtd.logger.DefaultLogger is instantiated.

Return type

RtdLogger

set_logger_from_parent(parent_id, logger)[source]

Inherit logger from parent.

Parameters
  • parent_id (str) – Unique identifier of parent instance.

  • logger (RtdLogger) – Logger from parent instance.