Skip to content

Commit

Permalink
better definition and sharing of keys for ROI center
Browse files Browse the repository at this point in the history
  • Loading branch information
vreuter committed Mar 20, 2024
1 parent 9cd3643 commit cdce32d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
6 changes: 4 additions & 2 deletions spotfishing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
"""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

__author__ = "Vince Reuter"
__credits__ = ["Vince Reuter", "Kai Sandoval Beckwith"]

__all__ = [
"ROI_AREA_KEY",
"ROI_MEAN_INTENSITY_KEY",
"DifferenceOfGaussiansTransformation",
"DimensionalityError",
"RoiCenterKeys",
"DetectionResult",
"detect_spots_dog",
"detect_spots_int",
Expand Down
5 changes: 3 additions & 2 deletions spotfishing/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
"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"

# 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"
14 changes: 11 additions & 3 deletions spotfishing/detection_result.py
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cdce32d

Please sign in to comment.