pyiron_base.utils.units.PyironUnitRegistry#
- class pyiron_base.utils.units.PyironUnitRegistry[source]#
Bases:
objectModule to record units for physical quantities within pyiron. This module is used for defining the units for different pyiron submodules.
Usage:
>>> import pint >>> from pyiron_base.utils.units import PyironUnitRegistry >>> pint_registry = pint.UnitRegistry()
After instantiating, the pint units for different physical quantities can be registered as follows
>>> base_registry = PyironUnitRegistry() >>> base_registry.add_quantity(quantity="energy", unit=pint_registry.eV, data_type=float)
Labels corresponding to a particular physical quantity can also be registered
>>> base_registry.add_labels(labels=["energy_tot", "energy_pot"], quantity="energy")
For more information on working with pint, see: https://pint.readthedocs.io/en/0.10.1/tutorial.html
Methods
__init__()- self.quantity_dict#
add_labels(labels, quantity)Maps quantities with different labels to quantities already defined in the registry
add_quantity(quantity, unit[, data_type])Add a quantity to a registry
get_dtype(quantity)Returns the data type in which the quantity will be stored
Attributes
A dictionary of the names of the different physical quantities to the corresponding datatype in which they are to be stored
A dictionary of the different labels stored and the physical quantity they correspond to
A dictionary of the different physical quantities and the corresponding pint unit
- add_labels(labels: list | ndarray, quantity: str) None[source]#
Maps quantities with different labels to quantities already defined in the registry
- Parameters:
labels (list/ndarray) – List of labels
quantity (str) – Physical quantity associated with the labels
- Raises:
KeyError – If quantity is not yet added with :method:`.add_quantity()`
Note: quantity should already be a key of unit_dict
- add_quantity(quantity: str, unit: ~pint.registry.Unit | ~pint.registry.Quantity, data_type: type = <class 'float'>) None[source]#
Add a quantity to a registry
- Parameters:
quantity (str) – The physical quantity
unit (pint.unit.Unit/pint.quantity.Quantity) – pint unit or quantity
data_type (type) – Data type in which the quantity has to be stored
- property dtype_dict: dict#
A dictionary of the names of the different physical quantities to the corresponding datatype in which they are to be stored
- Returns:
dict
- get_dtype(quantity: str) type[source]#
Returns the data type in which the quantity will be stored
- Parameters:
quantity (str) – The quantity
- Returns:
Corresponding data type
- Return type:
type
- Raises:
KeyError – If quantity is not yet added with :method:`.add_quantity()` or :method:`.add_labels()`
- property quantity_dict: dict#
A dictionary of the different labels stored and the physical quantity they correspond to
- Returns:
dict
- property unit_dict: dict#
A dictionary of the different physical quantities and the corresponding pint unit
- Returns:
dict