Skip to content

Commit e0e3ed9

Browse files
committed
Add physical units in zarr metadata (ref #112)
1 parent b79fdbd commit e0e3ed9

File tree

1 file changed

+63
-4
lines changed

1 file changed

+63
-4
lines changed

fractal/tasks/create_zarr_structure.py

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import zarr
1919

2020
from fractal.tasks.lib_parse_filename_metadata import parse_metadata
21+
from fractal.tasks.metadata_parsing import parse_yokogawa_metadata
2122

2223

2324
def create_zarr_structure(
@@ -26,6 +27,7 @@ def create_zarr_structure(
2627
ext=None,
2728
path_dict_channels=None,
2829
num_levels=None,
30+
coarsening_xy=None,
2931
):
3032

3133
"""
@@ -41,6 +43,7 @@ def create_zarr_structure(
4143
:type path_dict_channels: str
4244
:param num_levels: number of coarsening levels in the pyramid
4345
:type num_levels: int
46+
FIXME
4447
"""
4548

4649
try:
@@ -142,6 +145,24 @@ def create_zarr_structure(
142145
zarrurls = {"plate": [], "well": []}
143146
# zarrurls_in_paths = {}
144147

148+
# PARSE METADATA
149+
# FIXME: hard-coded paths
150+
root = (
151+
"/data/active/fractal/3D/PelkmansLab/"
152+
"CardiacMultiplexing/Cycle1_testSubset/"
153+
)
154+
mrf_path = root + "MeasurementDetail.mrf"
155+
mlf_path = root + "MeasurementData.mlf"
156+
157+
site_metadata, total_files = parse_yokogawa_metadata(
158+
mrf_path=mrf_path, mlf_path=mlf_path
159+
)
160+
161+
# PIXEL SIZES
162+
pixel_size_z = site_metadata["pixel_size_z"][0]
163+
pixel_size_y = site_metadata["pixel_size_y"][0]
164+
pixel_size_x = site_metadata["pixel_size_x"][0]
165+
145166
if not out_path.endswith("/"):
146167
out_path += "/"
147168
for plate in plates:
@@ -243,11 +264,43 @@ def create_zarr_structure(
243264
"type": "space",
244265
"unit": "micrometer",
245266
},
246-
{"name": "y", "type": "space"},
247-
{"name": "x", "type": "space"},
267+
{
268+
"name": "y",
269+
"type": "space",
270+
"unit": "micrometer",
271+
},
272+
{
273+
"name": "x",
274+
"type": "space",
275+
"unit": "micrometer",
276+
},
248277
],
249278
"datasets": [
250-
{"path": f"{level}"} for level in range(num_levels)
279+
{
280+
"path": f"{ind_level}",
281+
"coordinateTransformations": [
282+
{
283+
"type": "scale",
284+
"scale": [
285+
1.0,
286+
1.0 * coarsening_xy**ind_level,
287+
1.0 * coarsening_xy**ind_level,
288+
],
289+
}
290+
],
291+
}
292+
for ind_level in range(num_levels)
293+
],
294+
# Global rescaling to physiacl units
295+
"coordinateTransformations": [
296+
{
297+
"type": "scale",
298+
"scale": [
299+
pixel_size_z,
300+
pixel_size_y,
301+
pixel_size_x,
302+
],
303+
}
251304
],
252305
}
253306
]
@@ -302,7 +355,12 @@ def create_zarr_structure(
302355
type=int,
303356
help="number of levels in the Zarr pyramid",
304357
)
305-
358+
parser.add_argument(
359+
"-cxy",
360+
"--coarsening_xy",
361+
type=int,
362+
help="FIXME",
363+
)
306364
parser.add_argument(
307365
"-c",
308366
"--path_dict_channels",
@@ -315,5 +373,6 @@ def create_zarr_structure(
315373
out_path=args.out_path,
316374
ext=args.ext,
317375
num_levels=args.num_levels,
376+
coarsening_xy=args.coarsening_xy,
318377
path_dict_channels=args.path_dict_channels,
319378
)

0 commit comments

Comments
 (0)