Skip to content

Commit

Permalink
finish the switch of the mean intensity measurement name to camel cas…
Browse files Browse the repository at this point in the history
…e to replace snake case
  • Loading branch information
vreuter committed Oct 3, 2024
1 parent 71ddcd6 commit 270a049
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 23 deletions.
17 changes: 6 additions & 11 deletions spotfishing/detection_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions spotfishing/detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from ._types import *
from .detection_result import (
SPOT_DETECTION_COLUMN_RENAMING,
ROI_MEASUREMENT_KEYS,
SKIMAGE_REGIONPROPS_TABLE_COLUMNS_EXPANDED,
DetectionResult,
)
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 270a049

Please sign in to comment.