From 270a049f1c357f494de32a194ac08313ddf7f99f Mon Sep 17 00:00:00 2001 From: Vince Reuter Date: Thu, 3 Oct 2024 14:55:36 +0200 Subject: [PATCH] finish the switch of the mean intensity measurement name to camel case to replace snake case --- spotfishing/detection_result.py | 17 ++++++----------- spotfishing/detectors.py | 3 +-- ...ble__diff_gauss__threshold_10__p0_t57_c0.csv | 2 +- ...le__diff_gauss__threshold_10__p13_t57_c0.csv | 2 +- ...ble__diff_gauss__threshold_15__p0_t57_c0.csv | 2 +- ...le__diff_gauss__threshold_15__p13_t57_c0.csv | 2 +- ...ble__intensity__threshold_200__p0_t57_c0.csv | 2 +- ...le__intensity__threshold_200__p13_t57_c0.csv | 2 +- ...ble__intensity__threshold_300__p0_t57_c0.csv | 2 +- ...le__intensity__threshold_300__p13_t57_c0.csv | 2 +- .../test_accord_with_original_settings.py | 4 ++-- 11 files changed, 17 insertions(+), 23 deletions(-) diff --git a/spotfishing/detection_result.py b/spotfishing/detection_result.py index 56e06ad..5742f6d 100644 --- a/spotfishing/detection_result.py +++ b/spotfishing/detection_result.py @@ -32,21 +32,16 @@ def to_list(cls) -> list[str]: # TODO: consider making this configurable, see: https://github.com/gerlichlab/spotfishing/issues/1 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] +) + ( + (ROI_AREA_KEY, ROI_AREA_KEY), + (ROI_MEAN_INTENSITY_KEY, ROI_MEAN_INTENSITY_KEY_CAMEL_CASE), +) # 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 SPOT_DETECTION_COLUMN_RENAMING -] + ROI_MEASUREMENT_KEYS +SKIMAGE_REGIONPROPS_TABLE_COLUMNS_EXPANDED = [old for old, _ in SPOT_DETECTION_COLUMN_RENAMING] # the expected column names in a detection result table, after extraction and renaming -DETECTION_RESULT_TABLE_COLUMNS = [ - dict(SPOT_DETECTION_COLUMN_RENAMING).get(c, c) - for c in SKIMAGE_REGIONPROPS_TABLE_COLUMNS_EXPANDED -] +DETECTION_RESULT_TABLE_COLUMNS = [new for _, new in SPOT_DETECTION_COLUMN_RENAMING] @doc( diff --git a/spotfishing/detectors.py b/spotfishing/detectors.py index 16af564..1adc2de 100644 --- a/spotfishing/detectors.py +++ b/spotfishing/detectors.py @@ -18,7 +18,6 @@ from ._types import * from .detection_result import ( SPOT_DETECTION_COLUMN_RENAMING, - ROI_MEASUREMENT_KEYS, SKIMAGE_REGIONPROPS_TABLE_COLUMNS_EXPANDED, DetectionResult, ) @@ -125,7 +124,7 @@ def _build_props_table( regionprops_table( label_image=labels, intensity_image=input_image, - properties=(ROI_CENTROID_KEY, *ROI_MEASUREMENT_KEYS), + properties=(ROI_CENTROID_KEY, ROI_AREA_KEY, ROI_MEAN_INTENSITY_KEY), ) ) spot_props = spot_props.rename( diff --git a/tests/data/outputs__original_settings/expect__spots_table__diff_gauss__threshold_10__p0_t57_c0.csv b/tests/data/outputs__original_settings/expect__spots_table__diff_gauss__threshold_10__p0_t57_c0.csv index 7626374..234617c 100644 --- a/tests/data/outputs__original_settings/expect__spots_table__diff_gauss__threshold_10__p0_t57_c0.csv +++ b/tests/data/outputs__original_settings/expect__spots_table__diff_gauss__threshold_10__p0_t57_c0.csv @@ -1,4 +1,4 @@ -,zc,yc,xc,intensity_mean +,zc,yc,xc,intensityMean 0,2.4580271876546713,125.05243771893812,189.95460283233513,140.35164243403338 1,3.215275611393135,165.8262102606279,338.60801357496007,142.0859637340497 2,2.9371662355253076,174.2444293945887,343.5015376758335,135.34335086401202 diff --git a/tests/data/outputs__original_settings/expect__spots_table__diff_gauss__threshold_10__p13_t57_c0.csv b/tests/data/outputs__original_settings/expect__spots_table__diff_gauss__threshold_10__p13_t57_c0.csv index 381d14b..c4b30a5 100644 --- a/tests/data/outputs__original_settings/expect__spots_table__diff_gauss__threshold_10__p13_t57_c0.csv +++ b/tests/data/outputs__original_settings/expect__spots_table__diff_gauss__threshold_10__p13_t57_c0.csv @@ -1,4 +1,4 @@ -,zc,yc,xc,intensity_mean +,zc,yc,xc,intensityMean 0,1.464823275885825,381.0047398327831,256.9925375190833,150.19950331125827 1,5.64082522600635,21.70851874992031,177.53797926734416,158.95216862586136 2,5.645954517203461,334.42413956132106,246.54587324100783,158.50154364299746 diff --git a/tests/data/outputs__original_settings/expect__spots_table__diff_gauss__threshold_15__p0_t57_c0.csv b/tests/data/outputs__original_settings/expect__spots_table__diff_gauss__threshold_15__p0_t57_c0.csv index f34d892..339ed9e 100644 --- a/tests/data/outputs__original_settings/expect__spots_table__diff_gauss__threshold_15__p0_t57_c0.csv +++ b/tests/data/outputs__original_settings/expect__spots_table__diff_gauss__threshold_15__p0_t57_c0.csv @@ -1,4 +1,4 @@ -,zc,yc,xc,intensity_mean +,zc,yc,xc,intensityMean 0,2.900904569286373,478.08907046083226,672.0878758101751,143.69342359767893 1,3.4613367258090584,206.96659488938826,769.1328018686423,119.6487835308796 2,3.3685636416728855,557.7280560872998,563.5415814974639,150.34634146341463 diff --git a/tests/data/outputs__original_settings/expect__spots_table__diff_gauss__threshold_15__p13_t57_c0.csv b/tests/data/outputs__original_settings/expect__spots_table__diff_gauss__threshold_15__p13_t57_c0.csv index 4486187..a03e184 100644 --- a/tests/data/outputs__original_settings/expect__spots_table__diff_gauss__threshold_15__p13_t57_c0.csv +++ b/tests/data/outputs__original_settings/expect__spots_table__diff_gauss__threshold_15__p13_t57_c0.csv @@ -1,4 +1,4 @@ -,zc,yc,xc,intensity_mean +,zc,yc,xc,intensityMean 0,5.338708099413269,21.623742874490315,177.42528322192456,160.0732381391064 1,5.4162750969712805,334.3139437667062,246.38533874630704,159.93892639022823 2,6.183825840659056,343.4778794839467,238.8895252240894,161.87028235951914 diff --git a/tests/data/outputs__original_settings/expect__spots_table__intensity__threshold_200__p0_t57_c0.csv b/tests/data/outputs__original_settings/expect__spots_table__intensity__threshold_200__p0_t57_c0.csv index e236a75..77a80fd 100644 --- a/tests/data/outputs__original_settings/expect__spots_table__intensity__threshold_200__p0_t57_c0.csv +++ b/tests/data/outputs__original_settings/expect__spots_table__intensity__threshold_200__p0_t57_c0.csv @@ -1,4 +1,4 @@ -,zc,yc,xc,intensity_mean +,zc,yc,xc,intensityMean 0,3.3902772597289568,125.08864851423598,190.01392515230637,187.04651162790697 1,4.863298083935557,126.35459623417093,210.9740933501293,266.3664459161148 2,2.74294559405134,134.9870391491757,311.8039430611308,201.5253731343284 diff --git a/tests/data/outputs__original_settings/expect__spots_table__intensity__threshold_200__p13_t57_c0.csv b/tests/data/outputs__original_settings/expect__spots_table__intensity__threshold_200__p13_t57_c0.csv index 6ed43c6..87e0dad 100644 --- a/tests/data/outputs__original_settings/expect__spots_table__intensity__threshold_200__p13_t57_c0.csv +++ b/tests/data/outputs__original_settings/expect__spots_table__intensity__threshold_200__p13_t57_c0.csv @@ -1,4 +1,4 @@ -,zc,yc,xc,intensity_mean +,zc,yc,xc,intensityMean 0,3.658232714432168,22.889665679462357,178.80805758059003,221.90205371248024 1,0.5710688944838636,250.68390936140997,486.9258411535821,189.95652173913044 2,4.348300667423207,340.4061183666404,242.91498528591487,226.78735005452563 diff --git a/tests/data/outputs__original_settings/expect__spots_table__intensity__threshold_300__p0_t57_c0.csv b/tests/data/outputs__original_settings/expect__spots_table__intensity__threshold_300__p0_t57_c0.csv index 58ab9d4..fbd1209 100644 --- a/tests/data/outputs__original_settings/expect__spots_table__intensity__threshold_300__p0_t57_c0.csv +++ b/tests/data/outputs__original_settings/expect__spots_table__intensity__threshold_300__p0_t57_c0.csv @@ -1,4 +1,4 @@ -,zc,yc,xc,intensity_mean +,zc,yc,xc,intensityMean 0,0.2320966350301984,477.7818809318378,672.2436583261432,275.95238095238096 1,2.3448733193085154,557.9810207628282,563.80988749657,283.97402597402595 2,5.223356373573381,126.48178213577668,210.59382200075012,358.90384615384613 diff --git a/tests/data/outputs__original_settings/expect__spots_table__intensity__threshold_300__p13_t57_c0.csv b/tests/data/outputs__original_settings/expect__spots_table__intensity__threshold_300__p13_t57_c0.csv index 92121c6..ecc0ac0 100644 --- a/tests/data/outputs__original_settings/expect__spots_table__intensity__threshold_300__p13_t57_c0.csv +++ b/tests/data/outputs__original_settings/expect__spots_table__intensity__threshold_300__p13_t57_c0.csv @@ -1,4 +1,4 @@ -,zc,yc,xc,intensity_mean +,zc,yc,xc,intensityMean 0,3.315825788780396,22.067221443954253,177.91419072908607,298.91875 1,3.748072232760957,336.2526422113276,245.102830676751,302.9179104477612 2,4.329418330331549,341.85340300854875,240.40516475989955,323.12295081967216 diff --git a/tests/spotfishing_looptrace/test_accord_with_original_settings.py b/tests/spotfishing_looptrace/test_accord_with_original_settings.py index 7fb8708..a4a9253 100644 --- a/tests/spotfishing_looptrace/test_accord_with_original_settings.py +++ b/tests/spotfishing_looptrace/test_accord_with_original_settings.py @@ -11,7 +11,7 @@ import spotfishing_looptrace from spotfishing import ( - ROI_MEAN_INTENSITY_KEY, + ROI_MEAN_INTENSITY_KEY_CAMEL_CASE, RoiCenterKeys, detect_spots_dog, detect_spots_int, @@ -82,7 +82,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) - obs_table = obs.table[RoiCenterKeys.to_list() + [ROI_MEAN_INTENSITY_KEY]] + obs_table = obs.table[RoiCenterKeys.to_list() + [ROI_MEAN_INTENSITY_KEY_CAMEL_CASE]] print("EXPECTED (below):") print(exp_table)