Measurement
#
- class pymeasurement.Measurement(sample, precision=None, uncertainty=None, uncertaintyPercent=False, digital=False, analog=False, units=None, P=None, U=None, UP=False, D=False, A=False, UN=None)[source]#
A class to represent a SigFig sample with a SigFig uncertainty and corresponding units. This class can be used to perform calculations with uncertainty propagation. Units are also automatically derived through operations with other measurements.
- Parameters:
sample (SigFig or str) – The sample value as a SigFig object or a string.
precision (int) – The number of significant figures to use when printing the number. If None, the number of significant figures will be automatically determined.
uncertainty (SigFig or str) – The uncertainty of the sample as a SigFig object or a string.
uncertaintyPercent (bool) – If True, the uncertainty will be interpreted as a percentage of the sample value.
digital (bool) – If True, the uncertainty will be automatically determined based on the precision of the device.
analog (bool) – If True, the uncertainty will be automatically determined based on the precision of the device.
units (str) – The units of the measurement as a string.
P (int) – The number of significant figures to use when printing the number. If None, the number of significant figures will be automatically determined.
U (SigFig or str) – The uncertainty of the sample as a SigFig object or a string.
UP (bool) – If True, the uncertainty will be interpreted as a percentage of the sample value.
D (bool) – If True, the uncertainty will be automatically determined based on the precision of the device.
A (bool) – If True, the uncertainty will be automatically determined based on the precision of the device.
UN (str) – The units of the measurement as a string.
- __add__(other)[source]#
Returns the sum of the two Measurement objects.
- Parameters:
other (Measurement) – The Measurement object to add.
- Returns:
The sum of the two Measurement objects.
- Return type:
- __eq__(other)[source]#
Returns True if the two Measurement objects are equal.
- Parameters:
other (Measurement) – The Measurement object to compare.
- Returns:
True if the two Measurement objects are equal.
- Return type:
bool
- __ge__(other)[source]#
Returns True if the first Measurement object is greater than or equal to the second.
- Parameters:
other (Measurement) – The Measurement object to compare.
- Returns:
True if the first Measurement object is greater than or equal to the second.
- Return type:
bool
- __gt__(other)[source]#
Returns True if the first Measurement object is greater than the second.
- Parameters:
other (Measurement) – The Measurement object to compare.
- Returns:
True if the first Measurement object is greater than the second.
- Return type:
bool
- __hash__ = None#
- __init__(sample, precision=None, uncertainty=None, uncertaintyPercent=False, digital=False, analog=False, units=None, P=None, U=None, UP=False, D=False, A=False, UN=None)[source]#
Measurement Constructor
- __le__(other)[source]#
Returns True if the first Measurement object is less than or equal to the second.
- Parameters:
other (Measurement) – The Measurement object to compare.
- Returns:
True if the first Measurement object is less than or equal to the second.
- Return type:
bool
- __lt__(other)[source]#
Returns True if the first Measurement object is less than the second.
- Parameters:
other (Measurement) – The Measurement object to compare.
- Returns:
True if the first Measurement object is less than the second.
- Return type:
bool
- __mul__(other)[source]#
Returns the product of the two Measurement objects.
- Parameters:
other (Measurement) – The Measurement object to multiply by.
- Returns:
The product of the two Measurement objects.
- Return type:
- __neg__()[source]#
Returns the negation of the Measurement object.
- Returns:
The negation of the Measurement object.
- Return type:
- __pow__(integer)[source]#
Returns the Measurement object raised to the given integer power.
- Parameters:
integer (int) – The integer power to raise the Measurement object to.
- Returns:
The Measurement object raised to the given integer power.
- Return type:
- __radd__(other)[source]#
Returns the sum of the two Measurement objects.
- Parameters:
other (Measurement) – The Measurement object to add to.
- Returns:
The sum of the two Measurement objects.
- Return type:
- __repr__()[source]#
Returns a string representation of the Measurement object.
- Returns:
A string representation of the Measurement object.
- Return type:
str
- __rmul__(other)[source]#
Returns the product of the two Measurement objects.
- Parameters:
other (Measurement) – The Measurement object to multiply by.
- Returns:
The product of the two Measurement objects.
- Return type:
- __rsub__(other)[source]#
Returns the difference of the two Measurement objects.
- Parameters:
other (Measurement) – The Measurement object to subtract from.
- Returns:
The difference of the two Measurement objects.
- Return type:
- __rtruediv__(other)[source]#
Returns the quotient of the two Measurement objects.
- Parameters:
other (Measurement) – The Measurement object to divide by.
- Returns:
The quotient of the two Measurement objects.
- Return type:
- __str__()[source]#
Returns a string representation of the Measurement object.
- Returns:
A string representation of the Measurement object.
- Return type:
str
- __sub__(other)[source]#
Returns the difference of the two Measurement objects.
- Parameters:
other (Measurement) – The Measurement object to subtract.
- Returns:
The difference of the two Measurement objects.
- Return type:
- __truediv__(other)[source]#
Returns the quotient of the two Measurement objects.
- Parameters:
other (Measurement) – The Measurement object to divide by.
- Returns:
The quotient of the two Measurement objects.
- Return type:
- __weakref__#
list of weak references to the object (if defined)
- absolute()[source]#
Returns a copy of the Measurement with the uncertainty converted to an absolute value.
- Returns:
A copy of the Measurement with the uncertainty converted to an absolute value.
- Return type:
- apply_func(**kwargs)[source]#
Applies a function to the sample and uncertainty of the Measurement object. Based on the Generalized Uncertainty Propagation Formula. Suggest the units of the result by passing a “units” kwarg.
- Parameters:
func (string) – The function expression to apply.
- Returns:
The Measurement object with the function applied.
- Return type:
- average()[source]#
Returns the average of the given list of Measurement objects. Uses (max - min) / (2 * sqrt(n)) as the uncertainty.
- Parameters:
measurements (list) – The list of Measurement objects.
- Returns:
The average of the given list of Measurement objects.
- Return type:
- convert(uncertainty=None, uncertaintyPercent=False, units='', analog=False, digital=False, constant=False, u=None, up=False, a=False, d=False, un='', decimals=None)[source]#
Returns a Measurement object with the given sample, uncertainty, and units.
- Parameters:
sample (float or str) – The sample of the Measurement object.
uncertainty (float or str) – The uncertainty of the Measurement object.
uncertaintyPercent (bool) – Whether the uncertainty is a percent.
units (str) – The units of the Measurement object.
analog (bool) – Whether the Measurement object is analog.
digital (bool) – Whether the Measurement object is digital.
constant (bool) – Whether the Measurement object is constant.
u (float or str) – The uncertainty of the Measurement object.
up (bool) – Whether the uncertainty is a percent.
a (bool) – Whether the Measurement object is analog.
d (bool) – Whether the Measurement object is digital.
un (str) – The units of the Measurement object.
decimals (int) – The number of decimals to round to.
- deepCopy()[source]#
Returns a deep copy of the Measurement object.
- Returns:
A deep copy of the Measurement object.
- Return type:
- exportColumn(column, addUncertainty=True, asPercent=True)[source]#
Convert a Measurement Pandas DataFrame column to numeric values.
- Parameters:
savedf (pandas.core.frame.DataFrame) – The Pandas DataFrame to save to.
column (pandas.core.series.Series) – The Measurement Pandas DataFrame column.
addUncertainty (bool) – Whether to add the uncertainty to the DataFrame.
asPercent (bool) – Whether to add the uncertainty as a percent.
- formatUnits(dUnits)[source]#
Formats a set of units into a string.
- Parameters:
nUnits (list) – The numerator units.
dUnits (list) – The denominator units.
- Returns:
The formatted units.
- Return type:
str
- fromFloat(units='')[source]#
Creates a Measurement constant from a float.
- Parameters:
f (float) – The float to create the Measurement constant from.
units (str) – The units of the Measurement constant.
- Returns:
The Measurement constant created from the float.
- Return type:
- fromStr()[source]#
Creates a Measurement object from a string. The string must be in the form of a number, uncertainty, and units. The uncertainty can be in the form of a percentage or a number. A ‘a’ or ‘d’ can be used to indicate an analog or digital device for automatic uncertainty determination.
- Parameters:
string (str) – The string to create the Measurement object from.
- Returns:
The Measurement object created from the string.
- Return type:
- importColumn(uncertaintyColumn=None, df=None, **kwargs)[source]#
Convert a numeric Pandas DataFrame column to Measurement objects.
- Parameters:
column (pandas.core.series.Series) – The numeric Pandas DataFrame column.
kwargs (dict) – Keyword arguments to pass to Measurement.convert.
- max()[source]#
Returns the maximum of the given list of Measurement objects.
- Parameters:
measurements (list) – The list of Measurement objects.
- Returns:
The maximum of the given list of Measurement objects.
- Return type:
- min()[source]#
Returns the minimum of the given list of Measurement objects.
- Parameters:
measurements (list) – The list of Measurement objects.
- Returns:
The minimum of the given list of Measurement objects.
- Return type:
- multUnits(dUnits1, nUnits2, dUnits2)[source]#
Multiplies two sets of units.
- Parameters:
nUnits1 (list) – The numerator units of the first set.
dUnits1 (list) – The denominator units of the first set.
nUnits2 (list) – The numerator units of the second set.
dUnits2 (list) – The denominator units of the second set.
- Returns:
The multiplied units.
- Return type:
tuple
- percent()[source]#
Returns a copy of the Measurement with the uncertainty converted to a percentage.
- Returns:
A copy of the Measurement with the uncertainty converted to a percentage.
- Return type:
- sum()[source]#
Returns the sum of the given list of Measurement objects.
- Parameters:
measurements (list) – The list of Measurement objects.
- Returns:
The sum of the given list of Measurement objects.
- Return type:
- toAbsolute()[source]#
Converts the uncertainty to an absolute value. Note that this mutates the object.
- Returns:
The Measurement object with the uncertainty converted to an absolute value.
- Return type: