diff --git a/CHANGELOG.md b/CHANGELOG.md index 898ee44..37e9144 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Changed +* Renaming `mean_intensity` to `meanIntensity` right away after detection, before writing to disk. + ## [v0.1.0] - 2024-04-18 ### Added diff --git a/pyproject.toml b/pyproject.toml index a62a72a..c56806f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "spotfishing" -version = "0.1.0" +version = "0.2.0" description = "Detecting spots in FISH images" authors = [ "Vince Reuter ", diff --git a/spotfishing/__init__.py b/spotfishing/__init__.py index c47bde7..7c90efe 100644 --- a/spotfishing/__init__.py +++ b/spotfishing/__init__.py @@ -1,6 +1,6 @@ """Package-level members""" -from ._constants import ROI_AREA_KEY, ROI_MEAN_INTENSITY_KEY +from ._constants import ROI_AREA_KEY, ROI_MEAN_INTENSITY_KEY, ROI_MEAN_INTENSITY_KEY_CAMEL_CASE from ._exceptions import * from .detection_result import DetectionResult, RoiCenterKeys from .detectors import detect_spots_dog, detect_spots_int @@ -11,7 +11,7 @@ __all__ = [ "ROI_AREA_KEY", - "ROI_MEAN_INTENSITY_KEY", + "ROI_MEAN_INTENSITY_KEY_CAMEL_CASE", # Only export this (not the snake case one). "DifferenceOfGaussiansTransformation", "DimensionalityError", "RoiCenterKeys", diff --git a/spotfishing/_constants.py b/spotfishing/_constants.py index 46b27d1..bec950f 100644 --- a/spotfishing/_constants.py +++ b/spotfishing/_constants.py @@ -1,4 +1,4 @@ -"""Constant useful package-wide""" +"""Constants useful package-wide""" __author__ = "Vince Reuter" __credits__ = ["Vince Reuter"] @@ -6,8 +6,8 @@ __all__ = [ "ROI_AREA_KEY", "ROI_CENTROID_KEY", - "ROI_LABEL_KEY", - "ROI_MEAN_INTENSITY_KEY", + "ROI_MEAN_INTENSITY_KEY", # Export this for package-internal use. + "ROI_MEAN_INTENSITY_KEY_CAMEL_CASE", ] @@ -17,8 +17,7 @@ # 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" + +ROI_MEAN_INTENSITY_KEY_CAMEL_CASE = "intensityMean" diff --git a/spotfishing/detection_result.py b/spotfishing/detection_result.py index 8b09caf..56e06ad 100644 --- a/spotfishing/detection_result.py +++ b/spotfishing/detection_result.py @@ -30,21 +30,21 @@ def to_list(cls) -> list[str]: # 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( +SPOT_DETECTION_COLUMN_RENAMING: tuple[str, str] = tuple( (f"{ROI_CENTROID_KEY}-{i}", c) for i, c in enumerate(RoiCenterKeys.to_list()) -) +) + (ROI_MEAN_INTENSITY_KEY, ROI_MEAN_INTENSITY_KEY_CAMEL_CASE) # fields to pull from skimage.measure.regionprops_table result, besides centroid coordinates and label ROI_MEASUREMENT_KEYS = [ROI_AREA_KEY, ROI_MEAN_INTENSITY_KEY] # the sequence of columns of fields extracted from skimage.measure.regionprops_table, after accounting for expansion in multiple dimensions (e.g., centroid_weighted) SKIMAGE_REGIONPROPS_TABLE_COLUMNS_EXPANDED = [ - old for old, _ in ROI_CENTROID_COLUMN_RENAMING + old for old, _ in SPOT_DETECTION_COLUMN_RENAMING ] + ROI_MEASUREMENT_KEYS # the expected column names in a detection result table, after extraction and renaming DETECTION_RESULT_TABLE_COLUMNS = [ - dict(ROI_CENTROID_COLUMN_RENAMING).get(c, c) + dict(SPOT_DETECTION_COLUMN_RENAMING).get(c, c) for c in SKIMAGE_REGIONPROPS_TABLE_COLUMNS_EXPANDED ] diff --git a/spotfishing/detectors.py b/spotfishing/detectors.py index 1805b6c..16af564 100644 --- a/spotfishing/detectors.py +++ b/spotfishing/detectors.py @@ -17,7 +17,7 @@ from ._exceptions import DimensionalityError from ._types import * from .detection_result import ( - ROI_CENTROID_COLUMN_RENAMING, + SPOT_DETECTION_COLUMN_RENAMING, ROI_MEASUREMENT_KEYS, SKIMAGE_REGIONPROPS_TABLE_COLUMNS_EXPANDED, DetectionResult, @@ -125,13 +125,14 @@ def _build_props_table( regionprops_table( label_image=labels, intensity_image=input_image, - properties=tuple( - [ROI_LABEL_KEY, ROI_CENTROID_KEY] + ROI_MEASUREMENT_KEYS - ), + properties=(ROI_CENTROID_KEY, *ROI_MEASUREMENT_KEYS), ) ) - spot_props = spot_props.drop(["label"], axis=1, errors="ignore") - spot_props = spot_props.rename(columns=dict(ROI_CENTROID_COLUMN_RENAMING)) + spot_props = spot_props.rename( + columns=dict(SPOT_DETECTION_COLUMN_RENAMING), + inplace=False, + errors="raise", + ) spot_props = spot_props.reset_index(drop=True) return spot_props, labels