perun.io.util

IO Util.

Classes

NumpyEncoder

Json Numpy object encoder.

Functions

getTFactorMag(→ Tuple[float, ...)

Get transformation factor and magnitude to improve string formating.

value2ValueUnitStr(→ str)

Return a printable representation as [Value:.3f][mag][unit] (e.g. 3.05mV) of the value based on its metric metadata.

value2MeanStdStr(→ str)

Return a printable representation as [Value:.3f]±[std:.3f][mag][unit] (e.g. 3.05±0.1mV) of the value based on its metric metadata.

Module Contents

perun.io.util.getTFactorMag(value: perun.data_model.measurement_type.Number, metric_md: perun.data_model.measurement_type.MetricMetaData) Tuple[float, perun.data_model.measurement_type.Magnitude][source]

Get transformation factor and magnitude to improve string formating.

Parameters:
  • value (Number) – Reference value

  • metric_md (MetricMetaData) – Value description

Returns:

Scaling factor and Magnitude Enum

Return type:

Tuple[float, Magnitude]

perun.io.util.value2ValueUnitStr(value: perun.data_model.measurement_type.Number, metric_md: perun.data_model.measurement_type.MetricMetaData) str[source]

Return a printable representation as [Value:.3f][mag][unit] (e.g. 3.05mV) of the value based on its metric metadata.

Parameters:
  • value (Number) – Value to apply formating to.

  • metric_md (MetricMetaData) – Value metadata.

Returns:

String represenation

Return type:

str

perun.io.util.value2MeanStdStr(stats: perun.data_model.data.Stats) str[source]

Return a printable representation as [Value:.3f]±[std:.3f][mag][unit] (e.g. 3.05±0.1mV) of the value based on its metric metadata.

Parameters:
  • stats (Stats obj) – Stats to apply formating to.

  • metric_md (MetricMetaData) – Value metadata.

Returns:

String represenation

Return type:

str

class perun.io.util.NumpyEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: json.JSONEncoder

Json Numpy object encoder.

default(obj: Any) Any[source]

Encode an object to a JSON-serializable format, handling NumPy types.

Parameters:

obj (Any) – The object to encode.

Returns:

The JSON-serializable representation of the input object.

Return type:

Any

Raises:

TypeError – If the object cannot be encoded to a supported format.

Notes

This method specifically handles NumPy integer, floating, ndarray, and dtype objects, converting them to standard Python types or string representations. For other types, the superclass’s default method is called.