pyplate.pyplate.Unit
- class Unit[source]
Bases:
objectProvides unit conversion utility functions.
- __init__()
Methods
__init__()calculate_concentration_ratio(solute, ...)Helper function for dealing with concentrations.
convert(substance, quantity, unit)Convert quantity of substance to unit.
convert_from(substance, quantity, from_unit, ...)Convert quantity of substance between units.
convert_from_storage(value, unit)Converts value from storage format.
Converts a quantity of a substance or container to a standard format.
convert_prefix_to_multiplier(prefix)Converts an SI prefix into a multiplier.
convert_to_storage(value, unit)Converts value to storage format.
get_human_readable_unit(value, unit)Returns a more human-readable value and unit.
parse_concentration(concentration)Parses concentration string to (value, numerator, denominator).
parse_quantity(quantity)Splits a quantity into a value and unit, converting any SI prefix.
- static calculate_concentration_ratio(solute: Substance, concentration: str, solvent: Substance) Tuple[float, str, str][source]
Helper function for dealing with concentrations.
Returns: ratio of moles or Activity Units per mole storage unit (‘umol’, etc.).
- static convert(substance: Substance, quantity: str, unit: str) float[source]
Convert quantity of substance to unit.
- Parameters:
substance – Substance in question.
quantity – Quantity of substance (‘10 mL’).
unit – Unit to convert quantity to (‘mol’).
Returns: Converted value.
- static convert_from(substance: Substance, quantity: float, from_unit: str, to_unit: str) float[source]
Convert quantity of substance between units.
- Parameters:
substance – Substance in question.
quantity – Quantity of substance.
from_unit – Unit to convert quantity from (‘mL’).
to_unit – Unit to convert quantity to (‘mol’).
Returns: Converted value.
- static convert_from_storage(value: float, unit: str) float[source]
Converts value from storage format. Example: (1e3 uL, ‘mL’) -> 1
- Parameters:
value – Value to be converted.
unit – Unit value should be in. (‘uL’, ‘mL’, ‘mol’, etc.)
Returns: Converted value.
- static convert_from_storage_to_standard_format(what: Substance | Container, quantity: float) Tuple[float, str][source]
Converts a quantity of a substance or container to a standard format. Example: (water, 1e6) -> (18.015, ‘mL’), (NaCl, 1e6) -> (58.443, ‘g’), (Amylase, 1) -> (1, ‘U’)
- Parameters:
what – Substance or Container
quantity – Quantity in storage format.
Returns: Tuple of quantity and unit.
- static convert_prefix_to_multiplier(prefix: str) float[source]
Converts an SI prefix into a multiplier. Example: “m” -> 1e-3, “u” -> 1e-6
- Parameters:
prefix –
- Returns:
Multiplier (float)
- static convert_to_storage(value: float, unit: str) float[source]
Converts value to storage format. Example: (1, ‘L’) -> 1e6 uL
- Parameters:
value – Value to be converted.
unit – Unit value is in. (‘uL’, ‘mL’, ‘mol’, etc.)
Returns: Converted value.
- static get_human_readable_unit(value: float, unit: str) Tuple[float, str][source]
Returns a more human-readable value and unit.
- Parameters:
value – Value to work with.
unit – Unit to determine type and default unit if value is zero.
Returns: Tuple of new value and unit
- static parse_concentration(concentration) Tuple[float, str, str][source]
Parses concentration string to (value, numerator, denominator). :param concentration: concentration, ‘1 M’, ‘1 umol/uL’, ‘0.1 umol/10 uL’
Returns: Tuple of value, numerator, denominator. (0.01, ‘mol’, ‘L’)
- static parse_quantity(quantity: str) Tuple[float, str][source]
Splits a quantity into a value and unit, converting any SI prefix. Example: ‘10 mL’ -> (0.01, ‘L’)
- Parameters:
quantity – Quantity to convert.
- Returns: A tuple of float and str. The float will be the parsed value
and the str will be the unit (‘L’, ‘mol’, ‘g’, etc.).