The ExperimentalValue Object¶
-
class
qexpy.data.data.ExperimentalValue(unit='', name='', save=True)[source]¶ Base class for quantities with a value and an uncertainty
The ExperimentalValue is a container for an individual quantity involved in an experiment and subsequent data analysis. Each quantity has a value and an uncertainty (error), and optionally, a name and a unit. ExperimentalValue instances can be used in calculations just like any other numerical variable in Python. The result of such calculations will be wrapped in ExperimentalValue instances, with the properly propagated uncertainties.
Examples
>>> import qexpy as q
>>> a = q.Measurement(302, 5) # The standard way to initialize an ExperimentalValue
>>> # Access the basic properties >>> a.value 302 >>> a.error 5 >>> a.relative_error # This is defined as error/value 0.016556291390728478
>>> # These properties can be changed >>> a.value = 303 >>> a.value 303 >>> a.relative_error = 0.05 >>> a.error # The error and relative_error are connected 15.15
>>> # You can specify the name or the units of a value >>> a.name = "force" >>> a.unit = "kg*m^2/s^2"
>>> # The string representation of the value will include the name and units >>> print(a) force = 300 +/- 20 [kg⋅m^2⋅s^-2]
>>> # You can also specify how you want the values or the units to be printed >>> q.set_print_style(q.PrintStyle.SCIENTIFIC) >>> q.set_unit_style(q.UnitStyle.FRACTION) >>> q.set_sig_figs_for_error(2) >>> print(a) force = (3.03 +/- 0.15) * 10^2 [kg⋅m^2/s^2]
Properties¶
-
ExperimentalValue.value¶ The center value of this quantity
- Type
float
-
ExperimentalValue.error¶ The uncertainty of this quantity
- Type
float
-
ExperimentalValue.relative_error¶ The ratio of the uncertainty to its center value
- Type
float
-
ExperimentalValue.name¶ The name of this quantity
- Type
str
-
ExperimentalValue.unit¶ The unit of this quantity
- Type
str
Methods¶
-
abstract
ExperimentalValue.derivative(other)[source]¶ Calculates the derivative of this quantity with respect to another
The derivative of any value with respect to itself is 1, and for unrelated values, the derivative is always 0. This method is typically called from a DerivedValue, to find out its derivative with respect to one of the measurements it’s derived from.
- Parameters
other (ExperimentalValue) – the target for finding the derivative
- Return type
float
-
ExperimentalValue.get_covariance(other)[source]¶ Gets the covariance between this value and another value
- Return type
float
-
ExperimentalValue.set_covariance(other, cov=None)[source]¶ Sets the covariance between this value and another value
The covariance between two variables is by default 0. Users can set the covariance between two measurements to any value, and it will be taken into account during error propagation. When two measurements are recorded as arrays of repeated measurements of the same length, users can leave the covariance term empty, and let QExPy calculate the covariance between them. You should only do this when these two quantities are measured at the same time, and can be related physically.
Examples
>>> import qexpy as q >>> a = q.Measurement(5, 0.5) >>> b = q.Measurement(6, 0.3)
>>> # The user can manually set the covariance between two values >>> a.set_covariance(b, 0.135) >>> a.get_covariance(b) 0.135
>>> # The correlation factor is calculated behind the scene as well >>> a.get_correlation(b) 0.9
>>> # The user can ask QExPy to calculate the covariance if applicable >>> a = q.Measurement([1, 1.2, 1.3, 1.4]) >>> b = q.Measurement([2, 2.1, 3, 2.3]) >>> a.set_covariance(b) # this will declare that a and b are indeed correlated >>> a.get_covariance(b) 0.0416667
-
ExperimentalValue.get_correlation(other)[source]¶ Gets the correlation between this value and another value
- Return type
float