The MeasurementArray Object
Using QExPy, the user is able to record a series of measurements, and store them in an array. This feature is implemented in QExPy as a wrapper around numpy.ndarray
. The ExperimentalValueArray
class, also given the alias MeasurementArray
stores an array of values with uncertainties, and it also comes with methods for some basic data processing.
- class qexpy.data.datasets.ExperimentalValueArray(*args, **kwargs)[source]
An array of experimental values, alias: MeasurementArray
An ExperimentalValueArray (MeasurementArray) represents a series of ExperimentalValue objects. It is implemented as a sub-class of numpy.ndarray. This class is given an alias “MeasurementArray” for more intuitive user interface.
- Parameters:
*args – The first argument is an array of real numbers representing the center values of the measurements. The second argument (if present) is either a positive real number or an array of positive real numbers of the same length as the data array, representing the uncertainties on the measurements.
- Keyword Arguments:
data (List) – an array of real numbers representing the center values
error (Real|List) – the uncertainties on the measurements
relative_error (Real|List) – the relative uncertainties on the measurements
unit (str) – the unit of the measurement
name (str) – the name of the measurement
Examples
>>> import qexpy as q
>>> # We can instantiate an array of measurements with two lists >>> a = q.MeasurementArray([1, 2, 3, 4, 5], [0.1, 0.2, 0.3, 0.4, 0.5]) >>> a ExperimentalValueArray([MeasuredValue(1.0 +/- 0.1), MeasuredValue(2.0 +/- 0.2), MeasuredValue(3.0 +/- 0.3), MeasuredValue(4.0 +/- 0.4), MeasuredValue(5.0 +/- 0.5)], dtype=object)
>>> # We can also create an array of measurements with a single uncertainty. >>> # As usual, if the error is not specified, they will be set to 0 by default >>> a = q.MeasurementArray([1, 2, 3, 4, 5], 0.5, unit="m", name="length") >>> a ExperimentalValueArray([MeasuredValue(1.0 +/- 0.5), MeasuredValue(2.0 +/- 0.5), MeasuredValue(3.0 +/- 0.5), MeasuredValue(4.0 +/- 0.5), MeasuredValue(5.0 +/- 0.5)], dtype=object)
>>> # We can access the different statistical properties of this array >>> print(np.sum(a)) 15 +/- 1 [m] >>> print(a.mean()) 3.0 +/- 0.7 [m] >>> a.std() 1.5811388300841898
>>> # Manipulation of a MeasurementArray is also very easy. We can append or insert >>> # into the array values in multiple formats >>> a = a.append((7, 0.2)) # a measurement can be inserted as a tuple >>> print(a[5]) length = 7.0 +/- 0.2 [m] >>> a = a.insert(0, 8) # if error is not specified, it is set to 0 by default >>> print(a[0]) length = 8 +/- 0 [m]
>>> # The same operations also works with array-like objects, in which case they are >>> # concatenated into a single array >>> a = a.append([(10, 0.1), (11, 0.3)]) >>> a ExperimentalValueArray([MeasuredValue(8.0 +/- 0), MeasuredValue(1.0 +/- 0.5), MeasuredValue(2.0 +/- 0.5), MeasuredValue(3.0 +/- 0.5), MeasuredValue(4.0 +/- 0.5), MeasuredValue(5.0 +/- 0.5), MeasuredValue(7.0 +/- 0.2), MeasuredValue(10.0 +/- 0.1), MeasuredValue(11.0 +/- 0.3)], dtype=object)
>>> # The ExperimentalValueArray object is vectorized just like numpy.ndarray. You >>> # can perform basic arithmetic operations as well as functions with them and get >>> # back ExperimentalValueArray objects >>> a = q.MeasurementArray([0, 1, 2], 0.5) >>> a + 2 ExperimentalValueArray([DerivedValue(2.0 +/- 0.5), DerivedValue(3.0 +/- 0.5), DerivedValue(4.0 +/- 0.5)], dtype=object) >>> q.sin(a) ExperimentalValueArray([DerivedValue(0.0 +/- 0.5), DerivedValue(0.8 +/- 0.3), DerivedValue(0.9 +/- 0.2)], dtype=object)
See also
numpy.ndarray
Properties
- ExperimentalValueArray.values
An array consisting of the center values of each item
- Type:
np.ndarray
- ExperimentalValueArray.errors
An array consisting of the uncertainties of each item
- Type:
np.ndarray
- ExperimentalValueArray.name
Name of this array of values
A name can be given to this data set, and each measurement within this list will be named in the form of “name_index”. For example, if the name is specified as “length”, the items in this array will be named “length_0”, “length_1”, “length_2”, …
- Type:
str
- ExperimentalValueArray.unit
The unit of this array of values
It is assumed that the set of data that constitutes one ExperimentalValueArray have the same unit, which, when assigned, is given too all the items of the array.
- Type:
str
Methods
- ExperimentalValueArray.std(ddof=1, **_)[source]
The standard deviation of this array
- Return type:
float
- ExperimentalValueArray.error_on_mean()[source]
The error on the mean of this array
- Return type:
float
- ExperimentalValueArray.error_weighted_mean()[source]
The error weighted mean of this array
- Return type:
float
- ExperimentalValueArray.propagated_error()[source]
The propagated error from the error weighted mean calculation
- Return type:
float
- ExperimentalValueArray.append(value)[source]
Adds a value to the end of this array and returns the new array
- Parameters:
value – The value to be appended to this array. This can be a real number, a pair of value and error in a tuple, an ExperimentalValue instance, or an array consisting of any of the above.
- Return type:
- Returns:
The new ExperimentalValueArray instance
- ExperimentalValueArray.delete(index)[source]
deletes the value on the requested position and returns the new array
- Parameters:
index (int) – the index of the value to be deleted
- Return type:
- Returns:
The new ExperimentalValueArray instance
- ExperimentalValueArray.insert(index, value)[source]
adds a value to a position in this array and returns the new array
- Parameters:
index (int) – the position to insert the value
value – The value to be inserted into this array. This can be a real number, a pair of value and error in a tuple, an ExperimentalValue instance, or an array consisting of any of the above.
- Return type:
- Returns:
The new ExperimentalValueArray instance