1+ import os
2+ import subprocess
3+ from typing import Tuple
4+
5+ import pandas as pd
6+
17from ome_zarr .io import parse_url
28from ome_zarr .reader import Reader
39
410import dask .array as da
511
612
13+ def _get_dasky_data (url ):
14+ reader = Reader (parse_url (url )) # Prepare a reader.
15+ nodes = list (reader ()) # Might include multiple stuff
16+ image_node = nodes [0 ] # First node is expected to be image pixel data.
17+
18+ dask_data = image_node .data # Get the daskified data.
19+
20+ return dask_data
21+
22+
23+ def get_zebrahub_data (timepoint : int = 99 , view : bool = False ) -> Tuple [da .Array , pd .DataFrame ]:
24+ """Gets the ZebraHub data from https://doi.org/10.1016/j.cell.2024.09.047.
25+ """
26+ # NOTE: There's more single objective samples for zebrafish available with tracking annotations
27+ # https://public.czbiohub.org/royerlab/zebrahub/imaging/single-objective/
28+ url = "https://public.czbiohub.org/royerlab/zebrahub/imaging/single-objective/ZSNS001.ome.zarr"
29+
30+ # Let's get the image data.
31+ dask_data = _get_dasky_data (url )
32+
33+ # Get the lowest resolution (see below on how to access other resolutions)
34+ curr_data = dask_data [- 1 ]
35+
36+ # And strip out the channel dimension (see below for more details)
37+ curr_data = curr_data [timepoint , 0 ]
38+
39+ # We have tracking annotations here. Let's check them out.
40+ tracks_fpath = "ZSNS001_tracks.csv"
41+ if not os .path .exists (tracks_fpath ):
42+ subprocess .run (
43+ ["wget" , "https://public.czbiohub.org/royerlab/zebrahub/imaging/single-objective/ZSNS001_tracks.csv" ]
44+ )
45+
46+ # Load the tracking annotation file.
47+ tracks = pd .read_csv ("ZSNS001_tracks.csv" ) # I think this is on original resolution (?)
48+
49+ # HACK: Filtering ids based on one time-frame (the most plausible setup we might be opting for)
50+ curr_tracks = tracks .loc [tracks ["t" ] == timepoint ]
51+
52+ if view :
53+ import napari
54+ napari .view_image (curr_data )
55+ napari .run ()
56+
57+ return curr_data , curr_tracks
58+
59+
760def get_czi_zebrafish_data (
861 neuromast : bool = True , view : bool = False
962) -> da .Array :
@@ -26,12 +79,8 @@ def get_czi_zebrafish_data(
2679 # NOTE: This data does not have tracking annotations!
2780 url = "https://public.czbiohub.org/royerlab/ultrack/zebrafish_embryo.ome.zarr"
2881
29- # First, let's get the image data
30- reader = Reader (parse_url (url )) # Prepare a reader.
31- nodes = list (reader ()) # Might include multiple stuff
32- image_node = nodes [0 ] # First node is expecte to be image pixel data.
33-
34- dask_data = image_node .data # Get the daskified data.
82+ # Let's get the image data
83+ dask_data = _get_dasky_data (url )
3584
3685 # HACK: Try it for one dask array with lowest resolution (there exists four resolutions in this data).
3786 # TODO: Control res below, the highest res starts at the first index, lowest at the last index.
@@ -53,7 +102,8 @@ def get_czi_zebrafish_data(
53102
54103
55104def main ():
56- image = get_czi_zebrafish_data (neuromast = True , view = False )
105+ # image = get_czi_zebrafish_data(neuromast=True, view=False)
106+ image , tracks = get_zebrahub_data (view = False )
57107 print (image .shape )
58108
59109
0 commit comments