I/O helpers
patchworks.load_ome_zarr(store_path: Union[str, Path], channel: int | None = 0, level: int = 0, chunks: tuple[int, ...] | None = None) -> da.Array
Load one spatial array from an OME-ZARR store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store_path
|
Union[str, Path]
|
Path to the OME-ZARR store (.zarr directory). |
required |
channel
|
int | None
|
Channel index to select (axis is dropped). Pass |
0
|
level
|
int
|
Resolution pyramid level (0 = full resolution). |
0
|
chunks
|
tuple[int, ...] | None
|
Target chunk shape for the returned dask array. |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Shape |
Examples:
Source code in src/patchworks/_io.py
patchworks.estimate_empty_tiles(image: Union[da.Array, str, Path], tile_shape: tuple[int, ...], threshold: float | None = None, channel: int | None = 0, level: int = 0, sample_window: tuple[int, ...] = (24, 256, 256)) -> dict[str, Any]
Fast preview of which tiles are background before processing.
For each tile, reads a small centred window (sample_window) and tests
whether its max exceeds threshold. Bounded I/O — runs in seconds to
minutes on terabyte arrays.
APPROXIMATE: only the tile centre is inspected. The actual tile_process
run always tests the whole tile inline. Use this only to pick a threshold
and gauge the empty fraction before committing to a full run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Union[Array, str, Path]
|
Dask array or OME-ZARR path. |
required |
tile_shape
|
tuple[int, ...]
|
Tile shape you plan to use, e.g. |
required |
threshold
|
float | None
|
Empty cutoff (signal <= threshold → empty). None → Otsu on samples. |
None
|
channel
|
int | None
|
Used only when image is a path. |
0
|
level
|
int | None
|
Used only when image is a path. |
0
|
sample_window
|
tuple[int, ...]
|
Size of the centred window read per tile. |
(24, 256, 256)
|
Returns:
| Type | Description |
|---|---|
dict with keys:
|
|
Examples:
>>> info = estimate_empty_tiles("image.zarr", (120, 697, 697))
>>> print(f"{info['empty_fraction']:.0%} of tiles are background")
>>> labels = tile_process("image.zarr", fn, tile_shape=(120, 697, 697),
... skip_empty=True, empty_threshold=info["threshold"])
Source code in src/patchworks/_io.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |