physics_utils.data module

Defines the MeasuredData class and helper functions for error propagation

class physics_utils.data.MeasuredData(measurement, reading_error, standard_error=0.0)

Bases: StepsExtension

Represents a numerical measurement with uncertainty

value

The actual value of the data

Type:

float

reading_error

The error from the instrument reading

Type:

float

standard_error

The statistical standard error

Type:

float

Notes

This class automatically propagates uncertainty through calculations

all_steps_composite(plug_in_vars=True, trunc_nums=True)

Returns the steps to calculate this MeasuredData as composed equations written in LaTeX

Parameters:
  • self (MeasuredData) – The MeasuredData object

  • plug_in_vars (bool) – Should values be plugged into the generated equations

  • trunc_nums (bool) – Should plugged in values be truncated

Returns:

Returns a tuple, with the first element being the equation to calculate the value, and the second element being an equation to calculate the uncertainty.

Return type:

tuple[str, str]

all_steps_sequential(plug_in_vars=True, trunc_nums=True)

Returns the steps to calculate this MeasuredData as lists of steps written in LaTeX

Parameters:
  • self (MeasuredData) – The MeasuredData object

  • plug_in_vars (bool) – Should values be plugged into the generated equations

  • trunc_nums (bool) – Should plugged in values be truncated

Returns:

Returns a tuple, with the first element being a list of the steps for calculating the value, the second element being a list of steps for calculating the uncertainty, and the third element a list containing the value of the MeasuredData object at each of these steps.

Return type:

tuple[list[str], list[str], list]

arcsin()

Takes the result of arcsin(x) on a MeasuredData with the MeasuredData treated as radians

arctan()

Takes the result of arctan(x) on a MeasuredData with the MeasuredData treated as radians

cosine()

Takes the result of cos(x) on a MeasuredData with the MeasuredData treated as radians

error()

Returns the uncertainty on the data, which is taken to be the greatest error it has

Return type:

float

Examples

>>> MeasuredDataBase(100.2, 2.4, 10.12).error()
10.12
static from_set(measurements, reading_error, standard_error=0.0)

Takes a bunch of measurements that all have the same error, and converts them all into MeasuredDatas

Parameters:
  • measurements (Iterable[float]) – An iterable full of values to be converted to MeasuredDatas

  • reading_error (float) – The reading error that all the measurements share

  • standard_error (float) – The standard error that all the measurements share

Returns:

A list full of MeasuredDatas, with each one corresponding to an element from the measurements parameter, and the reading_error and standard_error attributes matching that which were passed as parameters

Return type:

list[Self]

has_steps = False
label = None
latex(wrap=True)

Converts the MeasuredData into a string representation, as described in the __str__ method, but uses the LaTeX symbol for ±, and wraps the value in $$

Return type:

str

reading_error = 0
recent_step(value_step, plug_in_vars=True, trunc_nums=True)

Returns the most recent step done on this MeasuredData in LaTeX

Parameters:
  • value_step (bool) – If true, returns the step for calculating the value, else returns the step for calculating uncertainty.

  • plug_in_vars (bool) – Should values be plugged into the generated equations

  • trunc_nums (bool) – Should plugged in values be truncated

Returns:

The step in LaTeX as a string

Return type:

str

sine()

Takes the result of sin(x) on a MeasuredData with the MeasuredData treated as radians

standard_error = 0
step_variables = None
tangent()

Takes the result of tan(x) on a MeasuredData with the MeasuredData treated as radians

uncertainty_step = None
uncertainty_wrapped = False
value = 0
value_step = None
values_wrapped = False
physics_utils.data.avg_from_set(measurements, reading_error)

Averages a list of floats all having the same reading error

Parameters:
  • measurements (list[float]) – The measurements to be averaged

  • reading_error (float) – The error which all of the measurements share

Returns:

The average of all the measurements, with the uncertainty propagated

Return type:

MeasuredData

physics_utils.data.avg_measured_datas(measurements)
Return type:

MeasuredData