spectrochempy.Quantity
- class Quantity(value, units=None)[source]
- Attributes Summary - returns: dict -- Dimensionality of the PlainQuantity, e.g. - {length: 1, time: -1}.- PlainQuantity's magnitude. - PlainQuantity's magnitude. - PlainQuantity's units. - PlainQuantity's units. - Methods Summary - check(dimension)- Return true if the quantity's dimension matches passed dimension. - compute(**kwargs)- Compute the Dask array wrapped by pint.PlainQuantity. - dot(b)- Dot product of two arrays. - from_list(quant_list[, units])- Transforms a list of Quantities into an numpy.array quantity. - from_sequence(cls, seq[, units])- Transforms a sequence of Quantities into an numpy.array quantity. - is_compatible_with(self, other, *contexts, ...)- check if the other object is compatible - ito([other])- Inplace rescale to different units. - Return PlainQuantity rescaled to plain units. - ito_preferred([preferred_units])- Return Quantity converted to a unit composed of the preferred units. - Return PlainQuantity scaled in place to reduced units, i.e. one unit per dimension. - Return PlainQuantity rescaled to root units. - m_as(units)- PlainQuantity's magnitude expressed in particular units. - persist(**kwargs)- Persist the Dask Array wrapped by pint.PlainQuantity. - prod(_prod_dispatcher)def prod(a[, axis, ...])- Return the product of quantity elements over a given axis - to([other])- Return PlainQuantity rescaled to different units. - Return PlainQuantity rescaled to plain units. - to_compact(quantity, unit)- "Return PlainQuantity rescaled to compact, human-readable units. - to_preferred([preferred_units])- Return Quantity converted to a unit composed of the preferred units. - Return PlainQuantity scaled in place to reduced units, i.e. one unit per dimension. - Return PlainQuantity rescaled to root units. - A view of the unit items. - visualize(**kwargs)- Produce a visual representation of the Dask graph. - Attributes Documentation - dimensionality
- returns: dict – Dimensionality of the PlainQuantity, e.g. - {length: 1, time: -1}
 - dimensionless
 - unitless
 - Methods Documentation - compute(**kwargs)[source]
- Compute the Dask array wrapped by pint.PlainQuantity. - Parameters:
- **kwargs (dict) – Any keyword arguments to pass to - dask.compute.
- Returns:
- pint.PlainQuantity – A pint.PlainQuantity wrapped numpy array. 
 
 - classmethod from_list(quant_list, units=None)[source]
- Transforms a list of Quantities into an numpy.array quantity. If no units are specified, the unit of the first element will be used. Same as from_sequence. - If units is not specified and list is empty, the unit cannot be determined and a ValueError is raised. - Parameters:
- quant_list (list of pint.PlainQuantity) – list of pint.PlainQuantity 
- units (UnitsContainer, str or pint.PlainQuantity) – units of the physical quantity to be created (Default value = None) 
 
- Returns:
- pint.PlainQuantity 
 
 - classmethod from_sequence(cls, seq: Sequence[PlainQuantity[MagnitudeT]], units=None ) -> PlainQuantity[MagnitudeT]: """Transforms a sequence of Quantities into an numpy.array quantity. If no units are specified, the unit of the first element will be used. If units is not specified and sequence is empty, the unit cannot be determined and a ValueError is raised. Parameters ---------- seq : sequence of pint.PlainQuantity sequence of pint.PlainQuantity units : UnitsContainer, str or pint.PlainQuantity units of the physical quantity to be created (Default value = None) Returns ------- pint.PlainQuantity """ len_seq = len(seq) if units is None: if len_seq: units = seq[0].u else: raise ValueError("Cannot determine units from empty sequence!") a = np.empty(len_seq) for i, seq_i in enumerate(seq)[source]
- Transforms a sequence of Quantities into an numpy.array quantity. If no units are specified, the unit of the first element will be used. - If units is not specified and sequence is empty, the unit cannot be determined and a ValueError is raised. - Parameters:
- seq (sequence of pint.PlainQuantity) – sequence of pint.PlainQuantity 
- units (UnitsContainer, str or pint.PlainQuantity) – units of the physical quantity to be created (Default value = None) 
 
- Returns:
- pint.PlainQuantity 
 
 - is_compatible_with(self, other: Any, *contexts: str | Context, **ctx_kwargs: Any ) -> bool: """check if the other object is compatible Parameters ---------- other The object to check. Treated as dimensionless if not a PlainQuantity, Unit or str. *contexts : str or pint.Context Contexts to use in the transformation. **ctx_kwargs : Values for the Context/s Returns ------- bool """ from .unit import PlainUnit if contexts or self._REGISTRY._active_ctx: try: self.to(other, *contexts, **ctx_kwargs) return True except DimensionalityError: return False if isinstance(other, (PlainQuantity, PlainUnit))[source]
- check if the other object is compatible - Parameters:
- other – The object to check. Treated as dimensionless if not a PlainQuantity, Unit or str. 
- *contexts (str or pint.Context) – Contexts to use in the transformation. 
- **ctx_kwargs – Values for the Context/s 
 
- Returns:
- bool 
 
 - ito(other=None, *contexts, **ctx_kwargs)[source]
- Inplace rescale to different units. - Parameters:
- other (pint.PlainQuantity, str or dict) – Destination units. (Default value = None) 
- *contexts (str or pint.Context) – Contexts to use in the transformation. 
- **ctx_kwargs – Values for the Context/s 
 
 
 - ito_preferred(preferred_units=None)[source]
- Return Quantity converted to a unit composed of the preferred units. - Examples - >>> import pint >>> ureg = pint.UnitRegistry() >>> (1*ureg.acre).to_preferred([ureg.meters]) <Quantity(4046.87261, 'meter ** 2')> >>> (1*(ureg.force_pound*ureg.m)).to_preferred([ureg.W]) <Quantity(4.44822162, 'watt * second')> 
 - ito_reduced_units()[source]
- Return PlainQuantity scaled in place to reduced units, i.e. one unit per dimension. This will not reduce compound units (e.g., ‘J/kg’ will not be reduced to m**2/s**2), nor can it make use of contexts at this time. 
 - m_as(units)[source]
- PlainQuantity’s magnitude expressed in particular units. - Parameters:
- units (pint.PlainQuantity, str or dict) – destination units 
 
 - persist(**kwargs)[source]
- Persist the Dask Array wrapped by pint.PlainQuantity. - Parameters:
- **kwargs (dict) – Any keyword arguments to pass to - dask.persist.
- Returns:
- pint.PlainQuantity – A pint.PlainQuantity wrapped Dask array. 
 
 - prod(_prod_dispatcher)def prod(a, axis=None, dtype=None, out=None, keepdims=np._NoValue, initial=np._NoValue, where=np._NoValue)[source]
- Return the product of quantity elements over a given axis - Wraps np.prod(). 
 - to(other=None, *contexts, **ctx_kwargs)[source]
- Return PlainQuantity rescaled to different units. - Parameters:
- other (pint.PlainQuantity, str or dict) – destination units. (Default value = None) 
- *contexts (str or pint.Context) – Contexts to use in the transformation. 
- **ctx_kwargs – Values for the Context/s 
 
- Returns:
- pint.PlainQuantity 
 
 - to_compact(quantity: PlainQuantity, unit: UnitsContainer | None = None) -> PlainQuantity: """ "Return PlainQuantity rescaled to compact, human-readable units. To get output in terms of a different unit, use the unit parameter. Examples -------- >>> import pint >>> ureg = pint.UnitRegistry() >>> (200e-9*ureg.s).to_compact() <Quantity(200.0, 'nanosecond')> >>> (1e-2*ureg('kg m/s^2')).to_compact('N') <Quantity(10.0, 'millinewton')> """ if not isinstance(quantity.magnitude, numbers.Number) and not hasattr( quantity.magnitude, "nominal_value")[source]
- “Return PlainQuantity rescaled to compact, human-readable units. - To get output in terms of a different unit, use the unit parameter. - Examples - >>> import pint >>> ureg = pint.UnitRegistry() >>> (200e-9*ureg.s).to_compact() <Quantity(200.0, 'nanosecond')> >>> (1e-2*ureg('kg m/s^2')).to_compact('N') <Quantity(10.0, 'millinewton')> 
 - to_preferred(preferred_units=None)[source]
- Return Quantity converted to a unit composed of the preferred units. - Examples - >>> import pint >>> ureg = pint.UnitRegistry() >>> (1*ureg.acre).to_preferred([ureg.meters]) <Quantity(4046.87261, 'meter ** 2')> >>> (1*(ureg.force_pound*ureg.m)).to_preferred([ureg.W]) <Quantity(4.44822162, 'watt * second')> 
 
Examples using spectrochempy.Quantity
