auto_uncertainties.uncertainty.uncertainty_containers
Attributes
Type alias for the underlying data types supporting |
|
Alias for |
|
Alias for |
Classes
Representation of a central value and its associated uncertainty. |
Functions
Return the central value of an |
|
|
Return the uncertainty of an |
Module Contents
- class auto_uncertainties.uncertainty.uncertainty_containers.UType[source]
Type alias for the underlying data types supporting
Uncertaintyobjects.- TYPE ALIAS:
- class auto_uncertainties.uncertainty.uncertainty_containers.Uncertainty(value: int, error: ErrT | None = ...)[source]
- class auto_uncertainties.uncertainty.uncertainty_containers.Uncertainty(value, error=...)
- class auto_uncertainties.uncertainty.uncertainty_containers.Uncertainty(value, error=...)
- class auto_uncertainties.uncertainty.uncertainty_containers.Uncertainty(value)
- class auto_uncertainties.uncertainty.uncertainty_containers.Uncertainty(value)
- class auto_uncertainties.uncertainty.uncertainty_containers.Uncertainty(value)
- class auto_uncertainties.uncertainty.uncertainty_containers.Uncertainty(value, error=...)
- class auto_uncertainties.uncertainty.uncertainty_containers.Uncertainty(value, error=..., skip=...)
Bases:
Generic[T],auto_uncertainties.UncertaintyDisplay
Representation of a central value and its associated uncertainty.
Parameters can be numbers, sequences,
numpyarrays,pint.Quantityobjects, otherUncertaintyobjects, or lists / tuples ofUncertaintyobjects.The
Uncertaintyclass automatically determines which methods should be implemented based on whether it represents a vector uncertainty, or a scalar uncertainty. When instantiated with sequences ornumpyarrays, vector-based operations are enabled; when instantiated with scalars, only scalar operations are permitted.Uncertaintyobjects only support float-based data types. If integers or integer arrays are passed as parameters to theUncertaintyconstructor, they will be cast tofloat(ornumpy.float64if anumpy.integersubclass is detected).- Parameters:
value – The central value(s)
error – The uncertainty value(s). Zero if not provided.
- Raises:
NegativeStdDevError – If
erris negative, or contains negative valuesTypeError – If the parameters are of incompatible types
ValueError – If the parameters have incomaptible values (e.g., misaligned array sizes)
- Returns:
An initialized
Uncertaintyobject
Example>>> u1 = Uncertainty(1.25, 0.25) >>> u2 = Uncertainty([1.4, 2.8, 0.09], [0.1, 0.14, 0.12]) >>> u3 = Uncertainty([1.4, 2.8, 0.09], 0.1) >>> u4 = Uncertainty(u1) >>> u5 = Uncertainty(np.array([1.4, 2.8]), np.array([0.1, 0.14])) >>> u6 = Uncertainty(np.array([1.4, 2.8]), 0.1) >>> u3.value array([1.4 , 2.8 , 0.09]) >>> u3.error array([0.1, 0.1, 0.1]) >>> np.cos(u1) 0.315322 +/- 0.237246 >>> u4 == u1 True
Pint Quantity Example>>> from pint import Quantity >>> val = Quantity(2.24, 'kg') >>> err = Quantity(0.208, 'kg') >>> new_quantity = Uncertainty(val, err) >>> new_quantity <Quantity(2.24 +/- 0.208, 'kilogram')>
Note
If sequences (not NumPy arrays) are supplied for
valueanderror, their numeric values will always be converted tonumpy.float64.If
pint.Quantityobjects are supplied for either parameter, the behavior is exactly as described in thefrom_quantitiesmethod.If an
Uncertaintyis supplied forvalue, itserrorattribute will always override anyerrorargument (if it is supplied).If the
errorparameter is not finite, the resultingUncertaintyobject will have itserrorattribute set to zero.
See also
- _init_seq(value, error)[source]
- Parameters:
value (SupportedSequence)
error (collections.abc.Sequence[ScalarT] | ScalarT | None)
- Return type:
None
- _init_vec(value, error)[source]
- Parameters:
value (numpy.typing.NDArray[numpy.number])
error (numpy.typing.NDArray[numpy.number] | ScalarT | None)
- Return type:
None
- property value: T[source]
The central value of the
Uncertaintyobject.- Return type:
T
- property error: T[source]
The uncertainty (error) of the
Uncertaintyobject.- Return type:
T
- property relative: T[source]
The relative uncertainty of the
Uncertaintyobject.- Return type:
T
- property rel2: T[source]
The square of the relative uncertainty of the
Uncertaintyobject.- Return type:
T
- plus_minus(error)[source]
Add an error to the
Uncertaintyobject.Returns a new instance.
- Parameters:
error (UType) – Error value to add
- Return type:
Uncertainty[T]
- classmethod from_string(string)[source]
Create an
Uncertaintyobject from a string representation of the value and error.- Parameters:
string (str) – A string representation of the value and error. The error can be represented as “+/-” or “±”. For instance, 5.0 +- 1.0 or 5.0 ± 1.0.
- Return type:
- classmethod from_quantities(value, error=None)[source]
Create a
pint.Quantityobject with uncertainty from one or moreQuantityobjects.Warning
Static type inference is hindered when using this method. Call
Uncertainty(value, error)instead for full typing support.- Parameters:
value – The central value(s) of the
Uncertaintyobjecterror – The uncertainty value(s) of the
Uncertaintyobject (Default =None)
Note
It is not necessary (and not advised) to call this method explicitly. Instantiating an
Uncertaintyobject withUncertainty(value, error)will automatically usefrom_quantitiesifQuantityobjects are supplied as parameters.Note
If neither argument is a
Quantity, returns a regularUncertaintyobject.If both arguments are
Quantityobjects, returns aQuantity(wrappedUncertainty) with the same units asvalue(attempts to converterrortovalue.units).If only the
valueargument is aQuantity, returns aQuantity(wrappedUncertainty) object with the same units asvalue.If only the
errorargument is aQuantity, returns aQuantity(wrappedUncertainty) object with the same units aserror.
- classmethod from_sequence(value, error=None)[source]
Creates either an
Uncertaintyobject or apint.Quantityobject from a supported sequence.The primary purpose of this method is to intercept sequences containing
Quantityobjects, reformat them, and then continue the instantiation process.Warning
Static type inference is hindered when using this method. Call
Uncertainty(value, error)instead for full typing support.- Parameters:
value – The central value(s)
error – The uncertainty value(s). Zero if not provided. (Default =
None)
Note
It is not necessary (and not advised) to call this method explicitly. Instantiating an
Uncertaintyobject withUncertainty(value, error)will automatically usefrom_sequenceif sequences are supplied as parameters.
- classmethod from_list(value, error=None)[source]
Alias for
from_sequence.Warning
This method is deprecated.
- Parameters:
value (ValT)
error (ErrT | None)
- Return type:
- __copy__()[source]
- Return type:
Uncertainty[T]
- __deepcopy__(memo)[source]
- Return type:
Uncertainty[T]
- clip(*args, **kwargs)[source]
NumPy
clipimplementation.- Parameters:
min
max
out
- Return type:
Uncertainty[T]
Note
Implemented only for vector uncertainty objects.
- fill(value)[source]
NumPy
fillimplementation.- Parameters:
value
- Return type:
None
Note
Implemented only for vector uncertainty objects.
- put(indices, values, mode='raise')[source]
NumPy
putimplementation.- Parameters:
indices
values
mode (Literal['raise', 'wrap', 'clip']) – (Default =
'raise')
- Return type:
None
Note
Implemented only for vector uncertainty objects.
- copy()[source]
Return a copy of the
Uncertaintyobject.Note
Implemented only for vector uncertainty objects.
- Return type:
Uncertainty[T]
- property flat[source]
NumPy
flatimplementation.Note
Implemented only for vector uncertainty objects.
- property shape[source]
NumPy
shapeimplemenetation.Note
Implemented only for vector uncertainty objects.
- property nbytes[source]
NumPy
nbytesimplementation.Note
Implemented only for vector uncertainty objects.
- searchsorted(v, side='left', sorter=None)[source]
NumPy
searchsortedimplementation.Note
Implemented only for vector uncertainty objects.
- Parameters:
side (Literal['left', 'right'])
- tolist()[source]
NumPy
tolistimplementation.Note
Implemented only for vector uncertainty objects.
- __setitem__(key, value)[source]
- Parameters:
key (int)
value (Uncertainty)
- Return type:
None
- auto_uncertainties.uncertainty.uncertainty_containers.VectorUncertainty[source]
Alias for
Uncertaintyto maintain backward compatibility.
- auto_uncertainties.uncertainty.uncertainty_containers.ScalarUncertainty[source]
Alias for
Uncertaintyto maintain backward compatibility.
- auto_uncertainties.uncertainty.uncertainty_containers.nominal_values(x: Uncertainty[UType]) UType[source]
- auto_uncertainties.uncertainty.uncertainty_containers.nominal_values(x: G) G
Return the central value of an
Uncertaintyobject if it is one, otherwise returns the object.
- auto_uncertainties.uncertainty.uncertainty_containers.std_devs(x: Uncertainty[UType]) UType[source]
- auto_uncertainties.uncertainty.uncertainty_containers.std_devs(x: G) G
Return the uncertainty of an
Uncertaintyobject if it is one, otherwise returns zero.