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

RepeatedlyMeasuredValue.use_propagated_error_for_uncertainty()[source]

Sets the uncertainty of this object to the weight propagated error

RepeatedlyMeasuredValue.show_histogram(**kwargs)[source]

Plots the raw measurement data in a histogram :rtype: tuple

See also

This works the same as the hist() function in the plotting module of QExPy

Correlated Measurements

Sometimes in experiments, two measured quantities can be correlated, and this correlation needs to be accounted for during error propagation. QExPy provides methods that allows users to specify the correlation between two measurements, and it will be taken into account automatically during computations.

qexpy.data.data.set_correlation(var1, var2, corr=None)[source]

Sets the correlation factor between two MeasuredValue objects

Parameters:
qexpy.data.data.get_correlation(var1, var2)[source]

Finds the correlation between two ExperimentalValue instances

Parameters:
Return type:

float

Returns:

The correlation factor between var1 and var2

qexpy.data.data.set_covariance(var1, var2, cov=None)[source]

Sets the covariance between two measurements

Parameters:

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
>>> q.set_covariance(a, b, 0.135)
>>> q.get_covariance(a, b)
0.135
qexpy.data.data.get_covariance(var1, var2)[source]

Finds the covariances between two ExperimentalValue instances

Parameters:
Return type:

float

Returns:

The covariance between var1 and var2

There are also shortcuts to the above methods implemented in ExperimentalValue.

MeasuredValue.set_correlation(other, corr=None)[source]

Sets the correlation factor of this value with another value

MeasuredValue.get_correlation(other)[source]

Gets the correlation factor of this value with another value

Return type:

float

MeasuredValue.set_covariance(other, cov=None)[source]

Sets the covariance of this value with another value

MeasuredValue.get_covariance(other)[source]

Gets the covariance of this value with another value

Return type:

float