spacr.intensity_rescale

Auditable intensity scaling for merged measurement fields.

The measurement worker stores merged arrays as uint16 while label planes must remain integer identities. This module makes the conversion decision a plate-level, serialisable plan so every worker uses the same scale and the decision can be written into measurements.db.

Functions

build_plate_plan(→ Dict[str, Any])

Inspect all fields and return a JSON/pickle-safe plate scaling plan.

fallback_record(→ Dict[str, Any])

Return the explicitly non-comparable per-field fallback decision.

mask_planes(→ set[int])

Return last-axis planes that contain labels rather than intensities.

needs_warning(→ bool)

Whether a conversion factor is neither identity nor fixed [0, 1].

resolve_record(→ Dict[str, Any])

Resolve and verify one worker's record against the precomputed plan.

signal_max(→ Tuple[float, bool])

Return the largest finite intensity and whether one exists.

Module Contents

spacr.intensity_rescale.build_plate_plan(src: os.PathLike | str, filenames: Iterable[str], settings: Mapping[str, Any]) → Dict[str, Any][source]

Inspect all fields and return a JSON/pickle-safe plate scaling plan.

Parameters:
  • src – directory containing the merged array files.

  • filenames – merged-array filenames to inspect as one plate set.

  • settings – resolved parsing and mask-plane settings.

Raw-valued fields on a plate share 65535 / plate_max when any one of them exceeds the uint16 ceiling. Normalised floating-point fields retain their well-defined fixed conversion of x65535. A file that cannot be inspected is left in failures and its worker will make (and record) a per-field fallback decision.

spacr.intensity_rescale.fallback_record(data: numpy.ndarray, filename: str, settings: Mapping[str, Any]) → Dict[str, Any][source]

Return the explicitly non-comparable per-field fallback decision.

Parameters:
  • data – loaded merged field array to characterize.

  • filename – field filename used to recover the plate identifier.

  • settings – resolved parsing and mask-plane settings.

spacr.intensity_rescale.mask_planes(data: numpy.ndarray, settings: Mapping[str, Any]) → set[int][source]

Return last-axis planes that contain labels rather than intensities.

Parameters:
  • data – merged field array whose last axis contains image planes.

  • settings – resolved mask-dimension settings for segmented roles.

spacr.intensity_rescale.needs_warning(factor: float) → bool[source]

Whether a conversion factor is neither identity nor fixed [0, 1].

Parameters:

factor – multiplicative intensity conversion factor to classify.

spacr.intensity_rescale.resolve_record(data: numpy.ndarray, filename: str, settings: Mapping[str, Any]) → Dict[str, Any][source]

Resolve and verify one worker’s record against the precomputed plan.

Parameters:
  • data – loaded merged field array handled by the worker.

  • filename – field filename used to locate its planned record.

  • settings – resolved settings containing the optional plate plan.

spacr.intensity_rescale.signal_max(data: numpy.ndarray, settings: Mapping[str, Any]) → Tuple[float, bool][source]

Return the largest finite intensity and whether one exists.

Parameters:
  • data – merged field array whose last axis contains image planes.

  • settings – resolved mask-dimension settings used to exclude label planes from the intensity scan.

Nested helpers

build_plate_plan._inspect(filename)

Read one field’s dtype, intensity maximum and file stats.

Parameters:

filename – merged-array filename inside src.

Returns:

(filename, record, None) or (filename, None, error).

spacr/intensity_rescale.py:113