photons.samples module

A formatting-friendly convenience class for 1-D sample data.

photons.samples.order_of_magnitude(value)[source]

Returns the order of magnitude of value.

Return type:

int

photons.samples.parse(format_spec)[source]

Parse a format specification into its grammar fields.

Return type:

dict[str, str]

photons.samples.si_prefix_factor(exponent)[source]

Returns the SI prefix and scaling factor.

Parameters:

exponent (int) – The exponent, e.g., 10 ** exponent

Return type:

tuple[str, float]

class photons.samples.Rounded(value, precision, type, exponent, suffix)[source]

Bases: object

Represents a rounded value.

value: float
precision: int
type: str
exponent: int
suffix: str
class photons.samples.Format(**kwargs)[source]

Bases: object

Format specification.

result(text)[source]

Format text using the fill, align, zero and width fields.

Return type:

str

uncertainty(uncertainty, *, hash=None, type='f', precision=None)[source]

Format uncertainty using the hash, grouping, precision and type fields.

Parameters:
  • uncertainty (float) – The uncertainty to format.

  • hash (str) – Can be either # or ‘’ (an empty string)

  • type (str | None) – Can be one of: e, E, f, F, g, G, n

  • precision (int) – Indicates how many digits should be displayed after the decimal point for presentation types f and F, or before and after the decimal point for presentation types g or G.

Return type:

str

Returns:

The uncertainty formatted.

update(std)[source]

Update the precision and u_exponent attributes.

Parameters:

std (float) – The standard uncertainty of the samples.

Return type:

None

value(value, *, hash=None, type=None, sign=None, precision=None)[source]

Format value using the sign, hash, grouping, precision and type fields.

Parameters:
  • value (float) – The value to format.

  • hash (str) – Can be either # or ‘’ (an empty string)

  • type (str) – Can be one of: e, E, f, F, g, G, n

  • sign (str) – Can be one of: +, -, ‘ ‘ (a space)

  • precision (int) – Indicates how many digits should be displayed after the decimal point for presentation types f and F, or before and after the decimal point for presentation types g or G.

Return type:

str

Returns:

The value formatted.

class photons.samples.Samples(samples=None, *, mean=None, stdev=None, size=None, overload=1e+30)[source]

Bases: object

Convenience class for a 1-D array of data samples.

Calculates the mean, standard deviation, variance, relative standard deviation and standard deviation of the mean of the samples.

Parameters:
  • samples (Union[str, Sequence[str | int | float], ndarray]) – The samples. If a string then in CSV format.

  • mean (float) – If specified, then it is not calculated from the samples.

  • stdev (float) – If specified, then it is not calculated from the samples.

  • size (int) – If specified, then it is not determined from the samples.

  • overload (float | None) – For some devices, like a DMM, if the input signal is greater than the present range can measure, the device returns a large value (e.g., 9.9E+37) to indicate a measurement overload. If the absolute value of the mean is greater than overload then the mean and standard deviation become NaN. Setting overload to None disables this check.

__getattr__(item)[source]

Pass all other attributes to the ndarray.

property mean: float

Returns the mean.

property overload: float | None

Returns the overload value.

property relative_stdev: float

Returns the relative standard deviation.

property relative_stdom: float

Returns the relative standard deviation of the mean.

property samples: ndarray

Returns the samples.

property size: int

Returns the number of samples.

property stdev: float

Returns the sample standard deviation.

property stdom: float

Returns the standard deviation of the mean.

to_json()[source]

Allows for this class to be JSON serializable with msl-network.

Return type:

dict[str, float]

to_ureal(*, label=None, delta=None, truncated=False)[source]

Convert to an uncertain-real number.

Parameters:
  • label (str) – The label to associate with the uncertain number.

  • delta (float) – The digitization step size (only valid if the samples are digitized).

  • truncated (bool) – Whether the digitized samples were truncated or rounded. Only used if delta is not None.

Return type:

UncertainReal

Returns:

The samples as an uncertain-real number.

property variance: float

Returns the sample variance.