Skip to content

Commit 11b79f3

Browse files
edyoshikunsrivarra
andauthored
Ultrack_indices (#35)
* add all indices * reader v3 * test: fixed tset Signed-off-by: Sricharan Reddy Varra <[email protected]> --------- Signed-off-by: Sricharan Reddy Varra <[email protected]> Co-authored-by: Sricharan Reddy Varra <[email protected]>
1 parent d00ff1e commit 11b79f3

File tree

4 files changed

+26
-31
lines changed

4 files changed

+26
-31
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ license = { file = "LICENSE" }
1111
authors = [
1212
{ name = "CZ Biohub SF and napari-iohub contributors", email = "[email protected]" },
1313
]
14-
dependencies = ["iohub>=0.1.0", "magicgui", "qtpy"]
14+
dependencies = ["iohub>=0.1.0", "dask>=2024.12.0", "magicgui", "qtpy"]
1515
dynamic = ["version"]
1616
classifiers = [
1717
"Development Status :: 2 - Pre-Alpha",

src/napari_iohub/_cell_state_annotator.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,17 @@
4141
_logger = logging.getLogger(__name__)
4242

4343
# Index columns for ultrack-compatible CSV output
44-
INDEX_COLUMNS = ["fov_name", "track_id", "t", "z", "y", "x"]
44+
ULTRACK_INDEX_COLUMNS = [
45+
"fov_name",
46+
"track_id",
47+
"t",
48+
"id",
49+
"parent_track_id",
50+
"parent_id",
51+
"z",
52+
"y",
53+
"x",
54+
]
4555

4656
# Annotation layer definitions
4757
ANNOTATION_LAYERS = [
@@ -748,7 +758,9 @@ def _save_annotations(self) -> None:
748758
)
749759

750760
# Reorder columns
751-
index_cols = [col for col in INDEX_COLUMNS if col in merged_df.columns]
761+
index_cols = [
762+
col for col in ULTRACK_INDEX_COLUMNS if col in merged_df.columns
763+
]
752764
annotation_cols = [
753765
"cell_division_state",
754766
"infection_state",

src/napari_iohub/_reader.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ def _get_node(path: StrOrBytesPath):
7272
zgroup.store.close()
7373
node = open_ome_zarr(store_path=path, mode="r")
7474
else:
75-
raise KeyError(
76-
f"NGFF plate or well metadata not found under '{zgroup.name}'"
77-
)
75+
raise KeyError(f"NGFF plate or well metadata not found under '{zgroup.name}'")
7876
return node
7977

8078

@@ -121,9 +119,7 @@ def _get_multiscales(pos: Position):
121119
try:
122120
multiscales.append(pos[im].dask_array())
123121
except Exception as e:
124-
logging.warning(
125-
f"Skipped array '{im}' at position {pos.zgroup.name}: {e}"
126-
)
122+
logging.warning(f"Skipped array '{im}' at position {pos.zgroup.name}: {e}")
127123
return len(multiscales), multiscales
128124

129125

@@ -144,13 +140,8 @@ def _ome_to_napari_by_channel(
144140
):
145141
if metadata.omero is None:
146142
if num_channels is None:
147-
raise ValueError(
148-
"num_channels must be set when omero is not present"
149-
)
150-
return [
151-
{"name": f"{i}", "blending": "additive"}
152-
for i in range(num_channels)
153-
]
143+
raise ValueError("num_channels must be set when omero is not present")
144+
return [{"name": f"{i}", "blending": "additive"} for i in range(num_channels)]
154145
omero: OMEROMeta = metadata.omero
155146
layers_kwargs = []
156147
for channel in omero.channels:
@@ -221,13 +212,9 @@ def fov_to_layers(fov: Position, layer_type: str = "image"):
221212
)
222213

223214

224-
def well_to_layers(
225-
well: Well, mode: Literal["stitch", "stack"], layer_type: str
226-
):
215+
def well_to_layers(well: Well, mode: Literal["stitch", "stack"], layer_type: str):
227216
if mode == "stitch":
228-
layers_kwargs, ch_axis, arrays = stitch_well_by_channel(
229-
well, row_wrap=4
230-
)
217+
layers_kwargs, ch_axis, arrays = stitch_well_by_channel(well, row_wrap=4)
231218
elif mode == "stack":
232219
layers_kwargs, ch_axis, arrays = stack_well_by_position(well)
233220
return layers_from_arrays(
@@ -258,9 +245,7 @@ def make_bbox(bbox_extents):
258245
maxr = bbox_extents[2]
259246
maxc = bbox_extents[3]
260247

261-
bbox_rect = np.array(
262-
[[minr, minc], [maxr, minc], [maxr, maxc], [minr, maxc]]
263-
)
248+
bbox_rect = np.array([[minr, minc], [maxr, minc], [maxr, maxc], [minr, maxc]])
264249
bbox_rect = np.moveaxis(bbox_rect, 2, 0)
265250

266251
return bbox_rect
@@ -300,9 +285,7 @@ def plate_to_layers(
300285
]
301286
for k in range(len(boxes)):
302287
boxes[k].append(box_extents[k] - 0.5)
303-
properties["fov"].append(
304-
well_path + "/" + next(well.positions())[0]
305-
)
288+
properties["fov"].append(well_path + "/" + next(well.positions())[0])
306289
else:
307290
row_arrays.append(None)
308291
plate_arrays.append(row_arrays)

src/napari_iohub/_tests/test_cell_state_annotator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from napari_iohub._cell_state_annotator import (
77
ANNOTATION_LAYERS,
8-
INDEX_COLUMNS,
8+
ULTRACK_INDEX_COLUMNS,
99
CellStateAnnotatorWidget,
1010
)
1111

@@ -30,8 +30,8 @@ def test_annotation_layers_constant():
3030

3131
def test_index_columns_constant():
3232
"""Test that index columns match ultrack expectations."""
33-
expected = ["fov_name", "track_id", "t", "z", "y", "x"]
34-
assert INDEX_COLUMNS == expected
33+
expected = ["fov_name", "track_id", "t", "id", "parent_track_id", "parent_id", "z", "y", "x"]
34+
assert ULTRACK_INDEX_COLUMNS == expected
3535

3636

3737
def test_state_expansion_logic():

0 commit comments

Comments
 (0)