bio_rtd.pdf¶
Wrappers for probability distribution functions.
This module contains subclasses of bio_rtd.core.PDF
.
The integral of a probability distribution function (PDF) over time has a value of 1.
Examples
>>> t = _np.linspace(0, 100, 1001)
>>> dt = t[1]
>>> pdf = GaussianFixedDispersion(t, 0.2)
>>> pdf.trim_and_normalize = False
>>> pdf.update_pdf(rt_mean=40)
>>> p = pdf.get_p()
>>> print(round(p.sum() * dt, 8))
1.0
>>> t[p.argmax()]
40.0
GaussianFixedDispersion¶
-
class
bio_rtd.pdf.
GaussianFixedDispersion
(t, dispersion_index, cutoff=0.0001, pdf_id='GaussianFixedDispersion')[source]¶ Bases:
bio_rtd.core.PDF
Gaussian PDF with fixed dispersion.
- Parameters
dispersion_index (
float
) –Dispersion index.
Dispersion index is defined as sigma * sigma / rt_mean. Where rt_mean is a mean residence time and sigma is a standard deviation on time scale (not volume).
cutoff –
Cutoff limit for trimming front and end tailing.
Cutoff limit is relative to the peak max value.
pdf_id (
str
) – Unique identifier. Default = “GaussianFixedDispersion”.
See also
rtd_lib.core.PDF
Examples
>>> t = _np.linspace(0, 100, 1001) >>> dt = t[1] >>> pdf = GaussianFixedDispersion(t, dispersion_index=0.2) >>> pdf.trim_and_normalize = False >>> pdf.update_pdf(rt_mean=40) >>> p = pdf.get_p() >>> print(round(p.sum() * dt, 4)) 1.0 >>> t[p.argmax()] 40.0
-
POSSIBLE_KEY_GROUPS
= [['f', 'v_void'], ['rt_mean']]¶
-
OPTIONAL_KEYS
= []¶
-
dispersion_index
¶ Dispersion index.
Dispersion index is defined as sigma * sigma / rt_mean. Where rt_mean is a mean residence time and sigma is a standard deviation.
-
cutoff_relative_to_max
¶ Cutoff limit for trimming front and end tailing.
Cutoff limit is relative to the peak max value.
-
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 fromOPTIONAL_KEYS
.- Return type
dict
- Raises
ValueError – If **kwargs do not contain keys from any of the groups in
POSSIBLE_KEY_GROUPS
.
-
get_p
()¶ 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
-
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
-
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.
-
update_pdf
(**kwargs)¶ 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 fromOPTIONAL_KEYS
.
-
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.
GaussianFixedRelativeWidth¶
-
class
bio_rtd.pdf.
GaussianFixedRelativeWidth
(t, relative_sigma, cutoff=0.0001, pdf_id='GaussianFixedRelativeWidth')[source]¶ Bases:
bio_rtd.core.PDF
Gaussian PDF with fixed relative peak width.
- Parameters
relative_sigma (
float
) –Relative sigma.
Relative sigma is defined as sigma / rt_mean. Where rt_mean is a mean residence time and sigma is a standard deviation.
cutoff –
Cutoff limit for trimming front and end tailing.
Cutoff limit is relative to the peak max value.
pdf_id (
str
) – Unique identifier. Default = “GaussianFixedRelativeWidth”.
See also
rtd_lib.core.PDF
Examples
>>> t = _np.linspace(0, 100, 1001) >>> dt = t[1] >>> pdf = GaussianFixedRelativeWidth(t, relative_sigma=0.15) >>> pdf.trim_and_normalize = False >>> pdf.update_pdf(rt_mean=40) >>> p = pdf.get_p() >>> print(round(p.sum() * dt, 4)) 1.0 >>> t[p.argmax()] 40.0
-
POSSIBLE_KEY_GROUPS
= [['f', 'v_void'], ['rt_mean']]¶
-
OPTIONAL_KEYS
= []¶
-
relative_sigma
¶ Relative sigma.
Relative sigma is defined as sigma / rt_mean. Where rt_mean is a mean residence time and sigma is a standard deviation.
-
cutoff_relative_to_max
¶ Cutoff limit for trimming front and end tailing.
Cutoff limit is relative to the peak max value.
-
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 fromOPTIONAL_KEYS
.- Return type
dict
- Raises
ValueError – If **kwargs do not contain keys from any of the groups in
POSSIBLE_KEY_GROUPS
.
-
get_p
()¶ 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
-
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
-
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.
-
update_pdf
(**kwargs)¶ 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 fromOPTIONAL_KEYS
.
-
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.
ExpModGaussianFixedDispersion¶
-
class
bio_rtd.pdf.
ExpModGaussianFixedDispersion
(t, dispersion_index, skew, pdf_id='ExpModGaussianFixedDispersion')[source]¶ Bases:
bio_rtd.core.PDF
Exponentially Modified Gaussian PDF with fixed dispersion.
- Parameters
dispersion_index (
float
) –Dispersion index of Gaussian part.
Dispersion index is defined as sigma * sigma / rt_mean. Where rt_mean is a mean residence time and sigma is a standard deviation on time scale (not volume).
skew (
float
) – Rate of exponential part.pdf_id (
str
) – Unique identifier. Default = “ExpModGaussianFixedDispersion”.
See also
rtd_lib.core.PDF
Examples
>>> t = _np.linspace(0, 100, 1001) >>> dt = t[1] >>> dispersion_index = 0.2 >>> skew = 0.5 >>> pdf = ExpModGaussianFixedDispersion(t, dispersion_index, skew) >>> pdf.trim_and_normalize = False >>> pdf.update_pdf(rt_mean=40) >>> p = pdf.get_p() >>> print(round(p.sum() * dt, 8)) 1.0 >>> t[p.argmax()] # position of peak max 39.6 >>> print(round((p * t[:p.size]).sum() * dt, 3)) # 1st momentum 40.0
-
POSSIBLE_KEY_GROUPS
= [['f', 'v_void'], ['rt_mean']]¶
-
OPTIONAL_KEYS
= ['skew']¶
-
dispersion_index
¶ Dispersion index for Gaussian part.
Dispersion index is defined as sigma * sigma / rt_mean. Where rt_mean is a mean residence time and sigma is a standard deviation.
-
skew
¶ Rate of exponential part.
-
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 fromOPTIONAL_KEYS
.- Return type
dict
- Raises
ValueError – If **kwargs do not contain keys from any of the groups in
POSSIBLE_KEY_GROUPS
.
-
get_p
()¶ 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
-
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
-
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.
-
update_pdf
(**kwargs)¶ 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 fromOPTIONAL_KEYS
.
-
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.
ExpModGaussianFixedRelativeWidth¶
-
class
bio_rtd.pdf.
ExpModGaussianFixedRelativeWidth
(t, sigma_relative, tau_relative, pdf_id='ExpModGaussianFixedRelativeWidth')[source]¶ Bases:
bio_rtd.core.PDF
Exponentially Modified Gaussian PDF with fixed relative sigma.
- Parameters
sigma_relative (
float
) –Relative sigma for Gaussian part.
Relative sigma is defined as sigma / rt_mean. Where rt_mean is a mean residence time and sigma is a standard deviation.
tau_relative (
float
) –Relative characteristic time of exponential part.
It is defined as 1 / (skew * rt_mean).
pdf_id (
str
) – Unique identifier. Default = “ExpModGaussianFixedRelativeWidth”.
See also
rtd_lib.core.PDF
Examples
>>> t = _np.linspace(0, 100, 1001) >>> dt = t[1] >>> sigma_relative = 0.15 >>> skew = 0.5 >>> pdf = ExpModGaussianFixedDispersion(t, sigma_relative, skew) >>> pdf.trim_and_normalize = False >>> pdf.update_pdf(rt_mean=40) >>> p = pdf.get_p() >>> print(round(p.sum() * dt, 8)) 1.0 >>> t[p.argmax()] # position of peak max 39.5 >>> print(round((p * t[:p.size]).sum() * dt, 2)) # 1st momentum 40.0
-
POSSIBLE_KEY_GROUPS
= [['rt_mean'], ['f', 'v_void']]¶
-
OPTIONAL_KEYS
= ['skew']¶
-
sigma_relative
¶ Relative sigma for Gaussian part.
Relative sigma is defined as sigma / rt_mean. Where rt_mean is a mean residence time and sigma is a standard deviation.
-
tau_relative
¶ Relative characteristic time of exponential part.
Relative characteristic time is defined as 1 / (skew * rt_mean). Where rt_mean is a mean residence time and skew is the rate of the exponential part.
-
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 fromOPTIONAL_KEYS
.- Return type
dict
- Raises
ValueError – If **kwargs do not contain keys from any of the groups in
POSSIBLE_KEY_GROUPS
.
-
get_p
()¶ 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
-
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
-
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.
-
update_pdf
(**kwargs)¶ 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 fromOPTIONAL_KEYS
.
-
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.
TanksInSeries¶
-
class
bio_rtd.pdf.
TanksInSeries
(t, n_tanks, pdf_id='TanksInSeries')[source]¶ Bases:
bio_rtd.core.PDF
Tanks in series PDF.
rt_mean means flow-through time through entire unit operation (all tanks).
For n_tanks == 1, the distribution becomes exponential drop.
- Parameters
n_tanks (
float
) – Number of tanks.pdf_id (
str
) – Unique identifier. Default = “TanksInSeries”.
See also
rtd_lib.core.PDF
Examples
>>> t = _np.linspace(0, 100, 1001) >>> dt = t[1] >>> sigma_relative = 0.15 >>> skew = 0.5 >>> pdf = TanksInSeries(t, n_tanks=5) >>> pdf.update_pdf(rt_mean=10) >>> pdf.trim_and_normalize = False >>> p = pdf.get_p() >>> print(round(p.sum() * dt, 8)) 1.0 >>> t[p.argmax()] # position of peak max 8.0 >>> print(round((p * t[:p.size]).sum() * dt, 2)) # 1st momentum 10.0 >>> pdf = TanksInSeries(t, n_tanks=1) >>> pdf.trim_and_normalize = False >>> pdf.update_pdf(rt_mean=10) >>> p = pdf.get_p() >>> print(round(p.sum() * dt, 2)) 1.0 >>> t[p.argmax()] # position of peak max 0.0 >>> print(round((p * t[:p.size]).sum() * dt, 1)) # 1st momentum 10.0
-
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 fromOPTIONAL_KEYS
.- Return type
dict
- Raises
ValueError – If **kwargs do not contain keys from any of the groups in
POSSIBLE_KEY_GROUPS
.
-
get_p
()¶ 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
-
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
-
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.
-
update_pdf
(**kwargs)¶ 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 fromOPTIONAL_KEYS
.
-
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.
-
POSSIBLE_KEY_GROUPS
= [['rt_mean'], ['f', 'v_void']]¶
-
OPTIONAL_KEYS
= ['n_tanks']¶
-
n_tanks
¶ Number of tanks.
-
allow_open_end
: bool¶ Prevent warnings and errors if the pdf does not fit on t.
Default: False
If True, no warnings or errors are reported in case the distribution does not fit on provided time vector.