21
21
22
22
import SimpleITK as sitk
23
23
from prefect import flow , task
24
- from pytools . HedwigZarrImages import HedwigZarrImage , HedwigZarrImages
24
+ from pytools import HedwigZarrImage , HedwigZarrImages
25
25
26
26
from em_workflows .file_path import FilePath
27
27
from em_workflows .utils import utils
@@ -78,8 +78,11 @@ def copy_zarr_to_assets_dir(file_path: FilePath) -> None:
78
78
79
79
80
80
@task
81
- def generate_imageset (file_path : FilePath ) -> List [Dict ]:
81
+ def generate_imageset (file_path : FilePath ,
82
+ use_default_dask = False ) -> List [Dict ]:
82
83
"""
84
+ :param: use_default_dask: If True, reuses the Prefect Dask Scheduler for the ZARR and Dask array operations.
85
+
83
86
| ImageSet consists of all the assets for a particular zarr sub-image and label images
84
87
| Macro image is ignored
85
88
| Label image is added as an thumbnail asset
@@ -91,16 +94,17 @@ def generate_imageset(file_path: FilePath) -> List[Dict]:
91
94
"""
92
95
zarr_fp = f"{ file_path .assets_dir } /{ file_path .base } .zarr"
93
96
image_set = list ()
94
- zarr_images = HedwigZarrImages (Path (zarr_fp ))
97
+
98
+ if use_default_dask :
99
+ compute_args = {}
100
+ else :
101
+ # This task is used in a sub-flow where it's the only task running.
102
+ # use all the cores in a thread pool.
103
+ compute_args = {"scheduler" : "threads" }
104
+ zarr_images = HedwigZarrImages (Path (zarr_fp ), compute_args = compute_args )
95
105
# for image_name, image in zarr_images.series():
96
106
for k_idx , image_name in enumerate (zarr_images .get_series_keys ()):
97
- # The relative path of the zarr group from the root zarr
98
- # this assumes a valid zarr group with OME directory inside
99
- ome_index_to_zarr_group = zarr_images .zarr_root ["OME" ].attrs ["series" ]
100
- zarr_idx = ome_index_to_zarr_group [k_idx ]
101
- image = HedwigZarrImage (
102
- zarr_images .zarr_root [zarr_idx ], zarr_images .ome_info , k_idx
103
- )
107
+ image = zarr_images [k_idx ]
104
108
# single image element
105
109
image_elt = dict ()
106
110
image_elt ["imageMetadata" ] = None
@@ -119,7 +123,7 @@ def generate_imageset(file_path: FilePath) -> List[Dict]:
119
123
120
124
else :
121
125
ng_asset = file_path .gen_asset (
122
- asset_type = "neuroglancerZarr" , asset_fp = Path ( zarr_fp ) / zarr_idx
126
+ asset_type = "neuroglancerZarr" , asset_fp = image . path
123
127
)
124
128
# note - dims should be image.dims, but GUI does not want XYC
125
129
# hardcoding in XY for now.
0 commit comments