bio_rtd.core

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.

Variables
  • species_list (list of str) – List with names of simulating process fluid species.

  • uo_id (str) – Unique identifier of the Inlet instance.

  • gui_title (str) – Readable title of the Inlet instance.

  • adj_par_list (list of bio_rtd.adj_par.AdjustableParameter) – List of adjustable parameters exposed to the GUI.

get_n_species()[source]

Get number of process fluid species.

Return type

int

get_result()[source]

Get flow rate and concentration profiles.

Return type

Tuple[ndarray, ndarray]

Returns

  • f_out – Flow rate profile.

  • c_out – Concentration profile.

get_t()[source]

Get simulation time vector.

Return type

ndarray

property log

Logger.

If logger is not set, then a DefaultLogger is instantiated. Setter also plants a data tree into passed logger.

Return type

RtdLogger

set_logger_from_parent(parent_id, logger)

Inherit logger from parent.

Parameters

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) – Global simulation time vector. It must starts with 0 and have a constant time step.

  • uo_id (str) – Unique identifier.

  • gui_title (str) – Readable title for GUI.

Variables
  • adj_par_list – List of adjustable parameters exposed to the GUI.

  • gui_hidden – Hide the of the unit operation (default False).

  • discard_inlet_until_t – Discard inlet until given time.

  • discard_inlet_until_min_c – Discard inlet until given concentration is reached.

  • discard_inlet_until_min_c_rel – Discard inlet until given concentration relative to is reached. Specified concentration is relative to the max concentration.

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

  • discard_outlet_until_t – Discard outlet until given time.

  • discard_outlet_until_min_c – Discard outlet until given concentration is reached.

  • discard_outlet_until_min_c_rel – Discard outlet until given concentration relative to is reached. Specified concentration is relative to the max concentration.

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

adj_par_list: _typing.Sequence[_adj_par.AdjustableParameter]

Settings

evaluate(f_in, c_in)[source]

Evaluate the propagation through 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

Logger.

If logger is not set, then a DefaultLogger is instantiated. Setter also plants a data tree into passed logger.

Return type

RtdLogger

set_logger_from_parent(parent_id, logger)

Inherit logger from parent.

Parameters

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 unit operations into a model.

The logger assigned to the instance of RtdModel is propagated throughout inlet and unit operations in dsp_uo_chain.

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 that the model uses for sending status messages and storing intermediate data.

  • title (str) – Title of the model.

  • desc (str) – Description of the model.

recalculate(start_at, on_update_callback)[source]

Recalculates the process fluid propagation, starting at start_at unit operation (-1 for inlet and entire process). Callback function can be specified. It receives the index of the just updated unit operation.

get_dsp_uo(uo_id)[source]

Get reference to a UnitOperation with specified uo_id.

Return type

UnitOperation

property log

Logger.

If logger is not set, then a DefaultLogger is instantiated. Setter also plants a data tree into passed logger.

Return type

RtdLogger

recalculate(start_at=0, on_update_callback=None)[source]

Recalculate process fluid propagation.

Parameters
  • start_at (int) – The index of first unit operation that needs to be re-evaluated. Default = 0. If -1, then the inlet profile is also re-evaluated.

  • 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 (-1 for inlet). This can serve as a trigger for updating UI after re-evaluation of individual unit operations.

set_logger_from_parent(parent_id, logger)

Inherit logger from parent.

Parameters

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) – RTD model.

Variables
  • species_label (list of str) – Labels of the species in concentration array.

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

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

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

  • start_at (int) – The index of unit operation (starting with 0) at which the re-evaluation starts. The value of -1 means that the inlet profile is also reevaluated.

abstract build_ui()[source]

Build the UI from scratch.

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 self.start_at to -1.

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.

Variables
  • trim_and_normalize – Trim edges of the peak by the threshold at the relative signal specified by cutoff_relative_to_max. Default = True.

  • 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.

get_p()[source]

Get calculated PDF.

update_pdf(**kwargs)[source]

Re-calculate PDF based on specified parameters.

Abstract Methods
----------------
_calc_pdf(kw_pars: dict)[source]

Calculate new pdf for a given set of parameters. The keys of the kw_pars include keys from one of the group in _possible_key_groups and any optional subset of keys from _optional_keys.

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.

get_p()[source]

Get probability distribution.

Returns

p – Evaluated probability distribution function. sum(p * self._dt) == 1 Corresponding time axis starts with 0 and has a fixed step of self._dt.

Return type

np.ndarray

property log

Logger.

If logger is not set, then a DefaultLogger is instantiated. Setter also plants a data tree into passed logger.

Return type

RtdLogger

set_logger_from_parent(parent_id, logger)

Inherit logger from parent.

Parameters
update_pdf(**kwargs)[source]

Re-calculate PDF based on specified parameters.

Parameters

kwargs – Should contain keys from one of the group in self._possible_key_groups. It may contain additional keys from self._optional_keys.

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

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

Notes

See docstring of ParameterSetList for information about key groups.

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.

calc_c_bound(f_load, c_load)[source]

Calculates what parts of load bin to the column.

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

Parts of the load that binds to the column during the load step. c_bound has the same shape as c_load.

Return type

c_bound

Notes

This is default implementation. The user is welcome to override this function in a custom child class.

abstract get_total_bc()[source]

Total binding capacity

Useful for determining column utilization.

Return type

float

property log

Logger.

If logger is not set, then a DefaultLogger is instantiated. Setter also plants a data tree into passed logger.

Return type

RtdLogger

set_logger_from_parent(parent_id, logger)

Inherit logger from parent.

Parameters
update_btc_parameters(**kwargs)[source]

Update binding dynamics for a given set of parameters.

Return type

None

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: ...
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 RtdLogger logger instance and plants a data tree in the logger.

Parameters

logger_parent_id (str) – Custom unique id that belongs to the instance of the class. It is used to plant a data tree in the RtdLogger.

Examples

>>> logger_parent_id = "parent_unit_operation"
>>> l = DefaultLoggerLogic(logger_parent_id)
>>> isinstance(l.log, _logger.DefaultLogger)
True
>>> l.log.e("Error Description")  # log error
Traceback (most recent call last):
RuntimeError: Error Description
>>> l.log.w("Warning Description")  # log waring
Warning Description
>>> l.log.i("Info")  # log 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()
>>> l.log.w("Warning Info")
Traceback (most recent call last):
RuntimeError: Warning Info

Notes

See the documentation of the RtdLogger.

property log

Logger.

If logger is not set, then a DefaultLogger is instantiated. Setter also plants a data tree into passed logger.

Return type

RtdLogger

set_logger_from_parent(parent_id, logger)[source]

Inherit logger from parent.

Parameters