piel.analysis.metrics.units#

Functions#

convert_scalar_metric_unit(→ piel.types.ScalarMetric)

Converts the units of a single ScalarMetrics instance to the target unit.

convert_metric_collection_units_per_metric(...)

Converts the units of metrics in a ScalarMetricCollection to the target units.

convert_metric_collection_per_unit(...)

Converts the units of metrics in a ScalarMetricCollection based on unit names.

Module Contents#

convert_scalar_metric_unit(metric: piel.types.ScalarMetric, target_unit: piel.types.Unit) piel.types.ScalarMetric[source]#

Converts the units of a single ScalarMetrics instance to the target unit.

Parameters:
  • metric (ScalarMetric) – The original scalar metric.

  • target_unit (Unit) – The target unit to convert to.

Returns:

A new ScalarMetrics instance with converted values and updated unit.

Return type:

ScalarMetric

Raises:

ValueError – If the original unit and target unit have different ‘datum’.

convert_metric_collection_units_per_metric(collection: piel.types.ScalarMetricCollection, target_units: dict[str, piel.types.Unit]) piel.types.ScalarMetricCollection[source]#

Converts the units of metrics in a ScalarMetricCollection to the target units.

Parameters:
  • collection (ScalarMetricCollection) – The original metric collection.

  • target_units (dict[str, Unit]) –

    • If a dictionary is provided, keys should be metrics names and values are the target Units.

Returns:

A new ScalarMetricCollection with converted metrics.

Return type:

ScalarMetricCollection

Raises:

ValueError – If target_units is a dict and a metric name is missing, or if any unit conversion is invalid.

convert_metric_collection_per_unit(collection: piel.types.ScalarMetricCollection, target_units: dict[str, piel.types.Unit]) piel.types.ScalarMetricCollection[source]#

Converts the units of metrics in a ScalarMetricCollection based on unit names.

Parameters:
Returns:

A new ScalarMetricCollection with converted metrics.

Return type:

ScalarMetricCollection

Raises:

ValueError – If target_units is a dict and a metric’s unit name is missing, or if any unit conversion is invalid.