Tile sizing
patchworks.auto_tile_shape(shape: tuple[int, ...], dtype: Any, target_bytes: int = 64 * 1024 ** 2, use_gpu: bool = False, gpu_memory: int | None = None, available_memory: int | None = None, n_workers: int | None = None, verbose: bool = False) -> tuple[int, ...]
Balanced tile shape for general-purpose 3-D processing.
Sizes the last three axes (spatial) to stay within the memory budget while keeping the shape as cubic as possible. Leading axes (t, c) are always 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, ...]
|
Full array shape, e.g. |
required |
dtype
|
Any
|
Array dtype. |
required |
target_bytes
|
int
|
Memory ceiling per tile. Default 64 MiB. |
64 * 1024 ** 2
|
use_gpu
|
bool
|
Size tiles against GPU VRAM rather than host RAM. |
False
|
gpu_memory
|
int | None
|
Available GPU VRAM in bytes; auto-queried when None. |
None
|
available_memory
|
int | None
|
Available host RAM in bytes; auto-queried when None. |
None
|
n_workers
|
int | None
|
Number of parallel workers (divides the RAM budget). |
None
|
verbose
|
bool
|
Log the chosen shape and estimated tile size. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[int, ...]
|
Tile shape with the same number of dimensions as shape. |
Examples:
Source code in src/patchworks/_chunks.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 | |
patchworks.auto_tile_shape_cellpose(shape: tuple[int, ...], dtype: Any, diameter: float | None = None, do_3D: bool = False, use_gpu: bool = False, gpu_memory: int | None = None, available_memory: int | None = None, n_workers: int | None = None, model_memory_bytes: int = 2 * 1024 ** 3, cellpose_memory_factor: int = 20, verbose: bool = False) -> tuple[int, ...]
Cellpose-optimised tile shape.
Cellpose is fundamentally 2-D: even in 3-D mode it runs 2-D segmentation on orthogonal planes and takes a consensus.
do_3D=False (default)
z is set to 1. Each tile is one 2-D (y, x) slice.
do_3D=True z is kept at its full extent per tile. y and x are tiled based on the available memory, accounting for the 3× overhead of three plane orientations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, ...]
|
Spatial shape, e.g. |
required |
dtype
|
Any
|
Array dtype. |
required |
diameter
|
float | None
|
Expected cell diameter in pixels. Tile will be at least |
None
|
do_3D
|
bool
|
Whether Cellpose will run in 3-D mode. |
False
|
use_gpu
|
bool
|
Size tiles for GPU VRAM. |
False
|
gpu_memory
|
int | None
|
Memory parameters (auto-queried when None). |
None
|
available_memory
|
int | None
|
Memory parameters (auto-queried when None). |
None
|
n_workers
|
int | None
|
Memory parameters (auto-queried when None). |
None
|
model_memory_bytes
|
int
|
Memory consumed by the Cellpose model weights (default 2 GiB). |
2 * 1024 ** 3
|
cellpose_memory_factor
|
int
|
Cellpose allocates roughly this multiple of raw input bytes (default 20×). |
20
|
verbose
|
bool
|
Log the chosen shape and memory estimates. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[int, ...]
|
Tile shape with the same number of dimensions as shape. |
Examples:
>>> tile = auto_tile_shape_cellpose((128, 2048, 2048), "uint16", diameter=30)
>>> tile
(1, 2048, 2048)
Source code in src/patchworks/_chunks.py
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 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |