Miscellaneous Functions

clear_lca_registries

qsdsan.utils.clear_lca_registries(print_msg=False)

Clear registries related to LCA, including instances of ImpactIndicator, ImpactItem, Construction, and Transportation

Parameters:

print_msg (bool) – Whether to print registry clear notice.

Examples

>>> from qsdsan.utils import clear_lca_registries
>>> clear_lca_registries(True)
All impact indicators have been removed from the registry.
All impact items have been removed from the registry.
All construction activities have been removed from the registry.
All transportation activities have been removed from the registry.

copy_attr

qsdsan.utils.copy_attr(new, original, skip=(), same=(), slots=None)

Set the attributes of a new object based on an original one:

  • If one attribute is in skip, it will not be copied to the new object.

  • If one attribute is in same, the attribute of the new object will be the same as the original object.

  • For remaining attributes, if it has copy(), then the attribute of the new object will be set as the copy of the original one; otherwise, it will be the same as the original one.

Parameters:
  • new (obj) – The new object.

  • origin (obj) – The original object.

  • skip (Iterable) – Attributes that will not be copied.

  • same (Iterable) – Attributes that will be the same for the original one and the copy.

  • slots (Iterable[str]) – All fields of the original object, will be set to original.__slots__ if not provided.

price_ratio

qsdsan.utils.price_ratio(default_price_ratio=1)

Add a price_ratio attribute to a unit that can be used to adjust capital and operating cost.

Parameters:

default_price_ratio (float) – Default value of the price ratio.

Examples

>>> from qsdsan import SanUnit, Components, set_thermo
>>> from qsdsan.utils import price_ratio
>>> @price_ratio(default_price_ratio=0.5)
... class Foo(SanUnit):
...     pass
>>> set_thermo(Components.load_default())
>>> F1 = Foo()
>>> print(F1.price_ratio)
0.5

register_with_prefix

qsdsan.utils.register_with_prefix(obj, prefix, ID)

Register the object with a prefix (and a “_” between the prefix and the ID).

Parameters:
  • obj (obj) – The object to be registered, must has the registry attribute.

  • prefix (str) – Prefix of the ID.

  • ID (str) – The original ID.

time_printer

qsdsan.utils.time_printer(func)

Allow functions to print execution time with a print_time kwarg.

Examples

>>> from qsdsan.utils import time_printer
>>> @time_printer
... def foo(a=1, **kwargs):
...     return a
>>> # This will print run time
>>> print(foo(a=5))
function `foo`
Total time: 0:00:00.
5
>>> # This will NOT print run time
>>> print(foo(a=5, print_time=False))
5