perun.io.util¶
IO Util.
Classes¶
Json Numpy object encoder. |
Functions¶
|
Render a DataFrame as a GitHub-flavoured markdown pipe table. |
|
Get transformation factor and magnitude to improve string formating. |
|
Return a printable representation as [Value:.3f][mag][unit] (e.g. 3.05mV) of the value based on its metric metadata. |
|
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. |
|
Compute (min, mean, max, metadata) for a metric from raw sensor data. |
Module Contents¶
- perun.io.util.dataframe_to_markdown(df: pandas.DataFrame, stralign: str = 'right') str[source]¶
Render a DataFrame as a GitHub-flavoured markdown pipe table.
This is a dependency-free replacement for
DataFrame.to_markdown(which requires the optionaltabulatepackage). It reproduces the previous output style used in perun reports: a header row, a separator row, and one row per record, with cells aligned according tostralign.- Parameters:
df (pandas.DataFrame) – Table to render. The index is not included.
stralign (str, optional) – Column alignment, one of
"right","left"or"center". Defaults to"right"to match the historical report format.
- Returns:
The markdown table as a string (no trailing newline).
- Return type:
str
- 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
- perun.io.util.raw_metric_stats(node: Any, metric_type: Any) Tuple[perun.data_model.measurement_type.Number, perun.data_model.measurement_type.Number, perun.data_model.measurement_type.Number, perun.data_model.measurement_type.MetricMetaData] | None[source]¶
Compute (min, mean, max, metadata) for a metric from raw sensor data.
The statistics are taken directly from the underlying sensor time-series found beneath
node(a host, device-group or run node), which is exactly the raw data recorded during monitoring. ReturnsNonewhen the metric has no per-sample series (e.g. RUNTIME, ENERGY) or no matching sensor data is available.- Parameters:
node (DataNode) – Any node in the tree; its sensor descendants are searched.
metric_type (MetricType) – The metric whose raw statistics are requested.
- Returns:
(min, mean, max, metric_md)in base magnitude, orNone.- Return type:
tuple | None
- 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.JSONEncoderJson Numpy object encoder.
- default(o: Any) Any[source]¶
Encode an object to a JSON-serializable format, handling NumPy types.
- Parameters:
o (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.