patchworks 0.11.15__tar.gz → 0.11.17__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {patchworks-0.11.15 → patchworks-0.11.17}/PKG-INFO +1 -1
- {patchworks-0.11.15 → patchworks-0.11.17}/src/patchworks/plugins/napari.py +53 -4
- {patchworks-0.11.15 → patchworks-0.11.17}/workflow/config/config.yaml +4 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/workflow/profile/slurm/config.yaml +15 -3
- {patchworks-0.11.15 → patchworks-0.11.17}/workflow/scripts/merge.py +12 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/.github/workflows/docs.yml +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/.github/workflows/lint.yml +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/.github/workflows/release.yml +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/.gitignore +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/.markdownlint-cli2.yaml +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/LICENSE +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/README.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/cliff.toml +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/api/chunks.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/api/cluster.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/api/io.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/api/merge_tile_labels.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/api/plugins/cellpose.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/api/plugins/napari.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/api/plugins/ome_zarr.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/api/relabel.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/api/tile_process.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/assets/logo.png +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/examples/cellpose_2d.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/examples/cellpose_2d.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/examples/cellpose_3d.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/examples/cellpose_3d.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/examples/custom.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/examples/custom_method.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/examples/standalone_merge.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/examples/stardist.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/examples/stardist_2d.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/getting_started.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/guide/gpu_distributed.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/guide/merging.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/guide/ome_zarr_napari.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/guide/performance.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/guide/pitfalls.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/guide/skip_empty.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/guide/snakemake.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/guide/tiling.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/docs/index.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/mkdocs.yml +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/pyproject.toml +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/src/patchworks/__init__.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/src/patchworks/_chunks.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/src/patchworks/_cluster.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/src/patchworks/_core.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/src/patchworks/_distributed.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/src/patchworks/_io.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/src/patchworks/_merge.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/src/patchworks/_relabel.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/src/patchworks/plugins/__init__.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/src/patchworks/plugins/cellpose.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/src/patchworks/plugins/ome_zarr.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/tests/test_core.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/tests/test_distributed.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/tests/test_napari.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/tests/test_ome_zarr.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/workflow/README.md +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/workflow/Snakefile +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/workflow/pixi.toml +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/workflow/rules/common.smk +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/workflow/rules/convert.smk +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/workflow/rules/merge.smk +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/workflow/rules/segment.smk +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/workflow/scripts/_pw.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/workflow/scripts/convert.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/workflow/scripts/fetch_model.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/workflow/scripts/prepare_tiles.py +0 -0
- {patchworks-0.11.15 → patchworks-0.11.17}/workflow/scripts/segment_tile.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: patchworks
|
|
3
|
-
Version: 0.11.
|
|
3
|
+
Version: 0.11.17
|
|
4
4
|
Summary: Tiled processing of arbitrarily large images with globally consistent labels
|
|
5
5
|
Project-URL: Homepage, https://github.com/imcf/patchworks
|
|
6
6
|
Project-URL: Issues, https://github.com/imcf/patchworks/issues
|
|
@@ -142,6 +142,36 @@ def _resolve_image(
|
|
|
142
142
|
return source
|
|
143
143
|
|
|
144
144
|
|
|
145
|
+
def _pyramid_scale(path: Union[str, Path], ndim: int) -> list[float] | None:
|
|
146
|
+
"""Read the level-0 physical scale (µm/px) from an OME-ZARR's own metadata.
|
|
147
|
+
|
|
148
|
+
Without this, napari shows every axis with an implicit scale of 1, so a
|
|
149
|
+
volume with anisotropic voxels (e.g. z coarser than x/y) renders with the
|
|
150
|
+
wrong aspect ratio and no real-world units.
|
|
151
|
+
|
|
152
|
+
Parameters
|
|
153
|
+
----------
|
|
154
|
+
path : str or Path
|
|
155
|
+
OME-ZARR store path (image or label group) — each carries its own
|
|
156
|
+
``multiscales`` metadata, so image and label stores are read
|
|
157
|
+
independently.
|
|
158
|
+
ndim : int
|
|
159
|
+
Number of spatial dimensions of the loaded array (2 -> "yx", 3 ->
|
|
160
|
+
"zyx"), used to align the calibration to the right axes.
|
|
161
|
+
|
|
162
|
+
Returns
|
|
163
|
+
-------
|
|
164
|
+
list of float or None
|
|
165
|
+
Physical size per axis, or ``None`` if the store carries no
|
|
166
|
+
calibration (napari then falls back to its uncalibrated default).
|
|
167
|
+
"""
|
|
168
|
+
from .ome_zarr import _base_scale, _default_axes, _read_zarr_calibration
|
|
169
|
+
|
|
170
|
+
axes = _default_axes(ndim)
|
|
171
|
+
pixel_size = _read_zarr_calibration(str(path), axes)
|
|
172
|
+
return _base_scale(axes, pixel_size) if pixel_size else None
|
|
173
|
+
|
|
174
|
+
|
|
145
175
|
def _inner_label_names(store: Union[str, Path]) -> list[str]:
|
|
146
176
|
"""List label images registered under an OME-ZARR's ``labels/`` group.
|
|
147
177
|
|
|
@@ -248,11 +278,14 @@ def view_in_napari(
|
|
|
248
278
|
napari = _require_napari()
|
|
249
279
|
|
|
250
280
|
img = _resolve_image(image, channel)
|
|
281
|
+
img_ndim = img[0].ndim if isinstance(img, list) else img.ndim
|
|
282
|
+
img_scale = _pyramid_scale(image, img_ndim) if _is_zarr(image) else None
|
|
251
283
|
viewer = napari.Viewer()
|
|
252
284
|
viewer.add_image(
|
|
253
285
|
img,
|
|
254
286
|
name=image_name,
|
|
255
287
|
multiscale=isinstance(img, list),
|
|
288
|
+
scale=img_scale,
|
|
256
289
|
**add_image_kwargs,
|
|
257
290
|
)
|
|
258
291
|
|
|
@@ -288,16 +321,32 @@ def view_in_napari(
|
|
|
288
321
|
|
|
289
322
|
if labels is not None:
|
|
290
323
|
lab = _resolve_labels(labels, labels_component)
|
|
291
|
-
|
|
324
|
+
lab_ndim = lab[0].ndim if isinstance(lab, list) else lab.ndim
|
|
325
|
+
lab_scale = _pyramid_scale(labels, lab_ndim) if _is_zarr(labels) else None
|
|
326
|
+
viewer.add_labels(
|
|
327
|
+
lab,
|
|
328
|
+
name=labels_name,
|
|
329
|
+
multiscale=isinstance(lab, list),
|
|
330
|
+
scale=lab_scale,
|
|
331
|
+
**label_kwargs,
|
|
332
|
+
)
|
|
292
333
|
elif _is_zarr(image):
|
|
293
334
|
# No labels given → auto-overlay every label image stored inside the
|
|
294
335
|
# OME-ZARR under labels/<name>/ (the default place tile_process writes
|
|
295
|
-
# them), each as its own multi-scale Labels layer.
|
|
336
|
+
# them), each as its own multi-scale Labels layer. Kept as a list (not
|
|
337
|
+
# unwrapped to a single array) even for one level, so napari always
|
|
338
|
+
# treats it as multiscale — required for 3D resolution switching, see
|
|
339
|
+
# https://napari.org/stable/gallery/add_multiscale_volume.html
|
|
296
340
|
for name in _inner_label_names(image):
|
|
297
|
-
|
|
341
|
+
store = f"{image}/labels/{name}"
|
|
342
|
+
levels = _multiscale_levels(store, None)
|
|
298
343
|
lab = [lvl.astype("int32") for lvl in levels]
|
|
299
344
|
viewer.add_labels(
|
|
300
|
-
lab
|
|
345
|
+
lab,
|
|
346
|
+
name=name,
|
|
347
|
+
multiscale=True,
|
|
348
|
+
scale=_pyramid_scale(store, lab[0].ndim),
|
|
349
|
+
**label_kwargs,
|
|
301
350
|
)
|
|
302
351
|
logger.info("auto-loaded labels/%s from %s", name, image)
|
|
303
352
|
|
|
@@ -51,3 +51,7 @@ cellpose:
|
|
|
51
51
|
pyramid_levels: 5
|
|
52
52
|
pyramid_downscale: 2
|
|
53
53
|
sequential_labels: true # renumber merged labels to a contiguous 1..N range
|
|
54
|
+
|
|
55
|
+
# ---- merge performance --------------------------------------------------
|
|
56
|
+
# null -> use the "merge" rule's actual cpus_per_task (profile/slurm/config.yaml).
|
|
57
|
+
merge_workers: null
|
|
@@ -5,7 +5,13 @@
|
|
|
5
5
|
# Edit the partitions / account / GPU request for your cluster.
|
|
6
6
|
|
|
7
7
|
executor: slurm
|
|
8
|
-
|
|
8
|
+
# Max concurrent SLURM jobs Snakemake will have in flight at once. This is a
|
|
9
|
+
# submission-side cap, not a cluster limit — raising it just lets more
|
|
10
|
+
# "segment" tiles queue/run together; scicore's scheduler still enforces your
|
|
11
|
+
# real GPU quota (MaxTRESPU) and backfills the rest, so it's safe to raise.
|
|
12
|
+
# Check your actual per-user GPU cap with:
|
|
13
|
+
# sacctmgr show assoc user=$USER format=account,partition,maxjobs,GrpTRES
|
|
14
|
+
jobs: 128
|
|
9
15
|
latency-wait: 60
|
|
10
16
|
rerun-incomplete: true
|
|
11
17
|
# Only re-run when an output is missing/stale — NOT when the patchworks code,
|
|
@@ -26,8 +32,12 @@ default-resources:
|
|
|
26
32
|
# Per-rule overrides.
|
|
27
33
|
set-resources:
|
|
28
34
|
convert:
|
|
35
|
+
# bioio/dask's default threaded scheduler uses every visible core, so
|
|
36
|
+
# this scales conversion for free. Verify actual scaling with `seff
|
|
37
|
+
# <jobid>` after a run and dial back if efficiency is low (scicore
|
|
38
|
+
# fair-share asks you not to sit on idle cores).
|
|
29
39
|
mem_mb: 64000
|
|
30
|
-
cpus_per_task:
|
|
40
|
+
cpus_per_task: 32
|
|
31
41
|
runtime: 360
|
|
32
42
|
prepare:
|
|
33
43
|
mem_mb: 32000
|
|
@@ -44,6 +54,8 @@ set-resources:
|
|
|
44
54
|
cpus_per_task: 4
|
|
45
55
|
runtime: 360 # 6 hours — must match the QOS, NOT 120 (=2h → killed early)
|
|
46
56
|
merge:
|
|
57
|
+
# merge_tile_labels now uses n_workers = this allocation (see merge.py /
|
|
58
|
+
# config.yaml's merge_workers) instead of silently capping at 4 threads.
|
|
47
59
|
mem_mb: 128000
|
|
48
|
-
cpus_per_task:
|
|
60
|
+
cpus_per_task: 32
|
|
49
61
|
runtime: 240
|
|
@@ -5,6 +5,7 @@ boundaries, optionally renumbers them) and writes the result back into the
|
|
|
5
5
|
image store under ``labels/<name>/`` as a calibrated, multi-scale pyramid.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
+
import os
|
|
8
9
|
import shutil
|
|
9
10
|
from pathlib import Path
|
|
10
11
|
|
|
@@ -19,11 +20,17 @@ work_dir = cfg["work_dir"]
|
|
|
19
20
|
image_store = str(Path(work_dir) / "image.zarr")
|
|
20
21
|
merged_store = str(Path(work_dir) / "_merged.zarr")
|
|
21
22
|
|
|
23
|
+
# merge_tile_labels defaults to min(4, cpu_count) workers, so it ignores
|
|
24
|
+
# whatever cpus_per_task the "merge" rule was actually allocated in the SLURM
|
|
25
|
+
# profile. Read the real allocation (SLURM_CPUS_PER_TASK) so the job uses all
|
|
26
|
+
# the cores it's paying for; merge_workers: in config.yaml can still override.
|
|
27
|
+
default_workers = int(os.environ.get("SLURM_CPUS_PER_TASK", os.cpu_count() or 4))
|
|
22
28
|
merged = merge_tile_labels(
|
|
23
29
|
stage_path(work_dir),
|
|
24
30
|
write_to=merged_store,
|
|
25
31
|
input_component="staged",
|
|
26
32
|
sequential_labels=cfg.get("sequential_labels", True),
|
|
33
|
+
n_workers=cfg.get("merge_workers", default_workers),
|
|
27
34
|
progress=False,
|
|
28
35
|
)
|
|
29
36
|
group = write_labels(
|
|
@@ -37,5 +44,10 @@ group = write_labels(
|
|
|
37
44
|
|
|
38
45
|
shutil.rmtree(merged_store, ignore_errors=True)
|
|
39
46
|
shutil.rmtree(stage_path(work_dir), ignore_errors=True)
|
|
47
|
+
# Also drop the checkpoint's completion sentinel (stage.zarr.done): the
|
|
48
|
+
# "prepare" rule's stage=touch(STAGE_OK) output must not outlive the store it
|
|
49
|
+
# claims exists, or a future rerun (e.g. re-segmenting for new labels) skips
|
|
50
|
+
# "prepare" and "segment" tries to open a stage.zarr that's already gone.
|
|
51
|
+
Path(f"{stage_path(work_dir)}.done").unlink(missing_ok=True)
|
|
40
52
|
print(f"[patchworks] labels written to {group}")
|
|
41
53
|
open(snakemake.output[0], "w").close() # noqa: F821
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|