The Measurement Object
To record values with an uncertainty, we use the MeasuredValue
object. It is a child class of ExperimentalValue
, so it inherits all attributes and methods from the ExperimentalValue
class.
- class qexpy.data.data.MeasuredValue(data, error=None, **kwargs)[source]
Container for user-recorded values with uncertainties
The MeasuredValue represents a single measurement recorded in an experiment. This class is given an alias “Measurement” for backward compatibility and for a more intuitive user interface. On the top level of this package, this class is imported as “Measurement”.
- Parameters:
data (Real|List) – The center value of the measurement
error (Real|List) – The uncertainty on the value
- Keyword Arguments:
unit (str) – The unit of this value
name (str) – The name of this value
Repeated Measurements
To record a value as the mean of a series of repeated measurements, use RepeatedlyMeasuredValue
- class qexpy.data.data.RepeatedlyMeasuredValue(data, error=None, **kwargs)[source]
Container for a MeasuredValue recorded as an array of repeated measurements
This class is instantiated if an array of values is used to record a Measurement of a single quantity with repeated takes. By default, the mean of the array is used as the value of this quantity, and the standard error (error on the mean) is the uncertainty. The reason for this choice is because the reason for taking multiple measurements is usually to minimize the uncertainty on the quantity, not to find out the uncertainty on a single measurement (which is what standard deviation is).
Examples
>>> import qexpy as q
>>> # The most common way of recording a value with repeated measurements is to only >>> # give the center values for the measurements >>> a = q.Measurement([9, 10, 11]) >>> print(a) 10.0 +/- 0.6
>>> # There are other statistical properties of the array of measurements >>> a.std 1 >>> a.error_on_mean 0.5773502691896258
>>> # You can choose to use the standard deviation as the uncertainty >>> a.use_std_for_uncertainty() >>> a.error 1
>>> # You can also specify individual uncertainties for the measurements >>> a = q.Measurement([10, 11], [0.1, 1]) >>> print(a) 10.5 +/- 0.5 >>> a.error_weighted_mean 10.00990099009901 >>> a.propagated_error 0.09950371902099892
>>> # You can choose which statistical properties to be used as the value/error >>> a.use_error_weighted_mean_as_value() >>> a.use_propagated_error_for_uncertainty() >>> q.set_sig_figs_for_error(4) >>> print(a) 10.00990 +/- 0.09950
Properties
- RepeatedlyMeasuredValue.raw_data
The raw data that was used to generate this measurement
- Type:
np.ndarray
- RepeatedlyMeasuredValue.mean
The mean of raw measurements
- Type:
float
- RepeatedlyMeasuredValue.error_weighted_mean
Error weighted mean if individual errors are specified
- Type:
float
- RepeatedlyMeasuredValue.std
The standard deviation of the raw data
- Type:
float
- RepeatedlyMeasuredValue.error_on_mean
The error on the mean or the standard error
- Type:
float
- RepeatedlyMeasuredValue.propagated_error
Error propagated with errors passed in if present
- Type:
float
Methods
- RepeatedlyMeasuredValue.use_std_for_uncertainty()[source]
Sets the uncertainty of this value to the standard deviation
- RepeatedlyMeasuredValue.use_error_on_mean_for_uncertainty()[source]
Sets the uncertainty of this value to the error on the mean
- RepeatedlyMeasuredValue.use_error_weighted_mean_as_value()[source]
Sets the value of this object to the error weighted mean