Skip to content

Commit 53893b6

Browse files
committed
Fix/update illumination_correction (ref #62 #61)
1 parent 386569c commit 53893b6

File tree

2 files changed

+20
-31
lines changed

2 files changed

+20
-31
lines changed

fractal/fractal_cmd.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ def workflow_apply(
443443
rows, cols = params["dims"]
444444
workflow_name = params["workflow_name"]
445445
path_dict_channels = params["channel_file"]
446+
path_dict_corr = params["path_dict_corr"]
446447
delete_input = params.get("delete_input", False)
447448

448449
# FIXME validate tasks somewhere?
@@ -562,6 +563,7 @@ def app_create_zarr_structure(**kwargs_):
562563
elif task == "illumination_correction":
563564
kwargs = dict(
564565
chl_list=chl_list,
566+
path_dict_corr=path_dict_corr,
565567
coarsening_xy=coarsening_xy,
566568
overwrite=True,
567569
# background=background,

fractal/tasks/illumination_correction.py

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def illumination_correction(
7575
zarrurl,
7676
overwrite=False,
7777
newzarrurl=None,
78-
channels=None,
78+
chl_list=None,
79+
path_dict_corr=None,
7980
coarsening_xy=2,
8081
background=110,
8182
):
@@ -90,19 +91,17 @@ def illumination_correction(
9091
:type overwrite: bool
9192
:param newzarrurl: output zarr, at the site level (e.g. x.zarr/B/03/0/)
9293
:type newzarrurl: str
93-
:param chl_list: list of channels #FIXME
94+
:param chl_list: list of channel names (e.g. A01_C01)
9495
:type chl_list: list
96+
:param path_dict_corr: FIXME
97+
:type path_dict_corr: str
9598
:param coarsening_xy: coarsening factor in XY (optional, default 2)
9699
:type coarsening_z: xy
97100
:param background: value for background subtraction (optional, default 110)
98101
:type background: int
99102
100103
"""
101104

102-
raise NotImplementedError(
103-
"illumination_correction not implemented " "with new channel scheme"
104-
)
105-
106105
# Check that only one output option is chosen
107106
if overwrite and (newzarrurl is not None):
108107
raise Exception(
@@ -128,26 +127,16 @@ def illumination_correction(
128127
img_size_y = 2160
129128
img_size_x = 2560
130129

131-
# FIXME: this block is too specific!
132-
# Hard-coded choice of illumination correction matrix
133-
path_correction_matrices = (
134-
"/data/active/fractal/Liberali/"
135-
"FractalTesting20220124/"
136-
"IlluminationCorrectionMatrices-Yokogawa/"
137-
)
138-
filenames = {
139-
1: "220120_60xW_BP445_CH01.tif",
140-
2: "220120_60xW_BP525_CH02.tif",
141-
3: "220120_60xW_BP600_CH03.tif",
142-
4: "220120_60xW_BP676_CH04.tif",
143-
}
130+
# Load paths of correction matrices
131+
with open(path_dict_corr, "r") as jsonfile:
132+
dict_corr = json.load(jsonfile)
133+
root_path_corr = dict_corr.pop("root_path_corr")
134+
135+
# Assemble dictionary of matrices and check their shapes
144136
corrections = {}
145-
for channel in channels:
146-
ind_ch, ID_ch, label_ch = channel[:]
147-
corrections[ind_ch] = imread(
148-
path_correction_matrices + filenames[ind_ch + 1]
149-
)
150-
if corrections[ind_ch].shape != (img_size_y, img_size_x):
137+
for ind_ch, ch in enumerate(chl_list):
138+
corrections[ch] = imread(root_path_corr + dict_corr[ch])
139+
if corrections[ch].shape != (img_size_y, img_size_x):
151140
raise Exception(
152141
"Error in illumination_correction, "
153142
"correction matrix has wrong shape."
@@ -188,11 +177,10 @@ def illumination_correction(
188177

189178
# Loop over channels
190179
data_czyx_new = []
191-
for channel in channels:
192-
ind_ch, ID_ch, label_ch = channel[:]
180+
for ind_ch, ch in enumerate(chl_list):
193181

194182
data_zyx = data_czyx[ind_ch]
195-
illum_img = corrections[ind_ch]
183+
illum_img = corrections[ch]
196184

197185
# Map "correct" function onto each block
198186
data_zyx_new = data_zyx.map_blocks(
@@ -214,7 +202,7 @@ def illumination_correction(
214202
num_levels=num_levels,
215203
chunk_size_x=img_size_x,
216204
chunk_size_y=img_size_y,
217-
num_channels=len(channels),
205+
num_channels=len(chl_list),
218206
)
219207

220208
# Write data into output zarr
@@ -246,12 +234,11 @@ def illumination_correction(
246234
help="path of the new zarr file",
247235
)
248236

249-
# FIXME
250237
parser.add_argument(
251238
"-C",
252239
"--chl_list",
253240
nargs="+",
254-
help="list of channels ",
241+
help="list of channel names (e.g. A01_C01)",
255242
)
256243
parser.add_argument(
257244
"-cxy",

0 commit comments

Comments
 (0)