diff --git a/spotfishing/__init__.py b/spotfishing/__init__.py index f02b8ae..c47bde7 100644 --- a/spotfishing/__init__.py +++ b/spotfishing/__init__.py @@ -1,8 +1,8 @@ """Package-level members""" -from ._constants import ROI_MEAN_INTENSITY_KEY +from ._constants import ROI_AREA_KEY, ROI_MEAN_INTENSITY_KEY from ._exceptions import * -from .detection_result import DetectionResult +from .detection_result import DetectionResult, RoiCenterKeys from .detectors import detect_spots_dog, detect_spots_int from .dog_transform import DifferenceOfGaussiansTransformation @@ -10,9 +10,11 @@ __credits__ = ["Vince Reuter", "Kai Sandoval Beckwith"] __all__ = [ + "ROI_AREA_KEY", "ROI_MEAN_INTENSITY_KEY", "DifferenceOfGaussiansTransformation", "DimensionalityError", + "RoiCenterKeys", "DetectionResult", "detect_spots_dog", "detect_spots_int", diff --git a/spotfishing/_constants.py b/spotfishing/_constants.py index 8b778be..46b27d1 100644 --- a/spotfishing/_constants.py +++ b/spotfishing/_constants.py @@ -10,8 +10,6 @@ "ROI_MEAN_INTENSITY_KEY", ] -# the key for an ROI's label, coming back from skimage.measure.regionprops_table -ROI_LABEL_KEY = "label" # the key for an ROI's area, coming back from skimage.measure.regionprops_table ROI_AREA_KEY = "area" @@ -19,5 +17,8 @@ # the key for an ROI's centroid, coming back from skimage.measure.regionprops_table ROI_CENTROID_KEY = "centroid_weighted" +# the key for an ROI's label, coming back from skimage.measure.regionprops_table +ROI_LABEL_KEY = "label" + # the key for an ROI's average intensity, coming back from skimage.measure.regionprops_table ROI_MEAN_INTENSITY_KEY = "intensity_mean" diff --git a/spotfishing/detection_result.py b/spotfishing/detection_result.py index 22a9785..8b09caf 100644 --- a/spotfishing/detection_result.py +++ b/spotfishing/detection_result.py @@ -1,6 +1,7 @@ """Abstraction over the result of application of a spot detection procedure to an input image""" from dataclasses import dataclass +from enum import Enum from typing import TYPE_CHECKING, Iterable from numpydoc_decorator import doc # type: ignore[import-untyped] @@ -17,13 +18,20 @@ __all__ = ["DetectionResult"] -# column names corresponding to the coordinates of the ROI centroid -ROI_CENTER_KEYS = ["zc", "yc", "xc"] +class RoiCenterKeys(Enum): + Z = "zc" + Y = "yc" + X = "xc" + + @classmethod + def to_list(cls) -> list[str]: + return [m.value for m in cls] + # how to rename columns arising from extraction from skimage.measure.regionprops_table, to better suit downstream analysis # TODO: consider making this configurable, see: https://github.com/gerlichlab/spotfishing/issues/1 ROI_CENTROID_COLUMN_RENAMING = tuple( - (f"{ROI_CENTROID_KEY}-{i}", c) for i, c in enumerate(ROI_CENTER_KEYS) + (f"{ROI_CENTROID_KEY}-{i}", c) for i, c in enumerate(RoiCenterKeys.to_list()) ) # fields to pull from skimage.measure.regionprops_table result, besides centroid coordinates and label diff --git a/tests/spotfishing_looptrace/test_accord_with_original_settings.py b/tests/spotfishing_looptrace/test_accord_with_original_settings.py index 16780a2..861b259 100644 --- a/tests/spotfishing_looptrace/test_accord_with_original_settings.py +++ b/tests/spotfishing_looptrace/test_accord_with_original_settings.py @@ -9,8 +9,7 @@ from pandas.testing import assert_frame_equal from helpers import ORIGINAL_SPECIFICATION, load_image_file -from spotfishing import ROI_MEAN_INTENSITY_KEY, detect_spots_dog, detect_spots_int -from spotfishing.detection_result import ROI_CENTER_KEYS +from spotfishing import ROI_MEAN_INTENSITY_KEY, RoiCenterKeys, detect_spots_dog, detect_spots_int import spotfishing_looptrace from spotfishing_looptrace.transformation_specification import ( DifferenceOfGaussiansSpecificationForLooptrace, @@ -76,7 +75,7 @@ def test_output_is_correct_with_original_settings( arr_name = f"img__{data_name}__smaller.npy" input_image = load_image_file(arr_name) obs = detect(input_image, spot_threshold=threshold, expand_px=expand_px) # type: ignore[call-arg] - obs_table = obs.table[ROI_CENTER_KEYS + [ROI_MEAN_INTENSITY_KEY]] + obs_table = obs.table[RoiCenterKeys.to_list() + [ROI_MEAN_INTENSITY_KEY]] print("EXPECTED (below):") print(exp_table)