ngio 0.5.0__py3-none-any.whl → 0.5.0a1__py3-none-any.whl

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.
Files changed (54) hide show
  1. ngio/__init__.py +2 -5
  2. ngio/common/__init__.py +6 -11
  3. ngio/common/_masking_roi.py +54 -34
  4. ngio/common/_pyramid.py +87 -321
  5. ngio/common/_roi.py +330 -258
  6. ngio/experimental/iterators/_feature.py +3 -3
  7. ngio/experimental/iterators/_rois_utils.py +11 -10
  8. ngio/hcs/_plate.py +136 -192
  9. ngio/images/_abstract_image.py +35 -539
  10. ngio/images/_create.py +283 -0
  11. ngio/images/_create_synt_container.py +43 -40
  12. ngio/images/_image.py +251 -517
  13. ngio/images/_label.py +172 -249
  14. ngio/images/_masked_image.py +2 -2
  15. ngio/images/_ome_zarr_container.py +241 -644
  16. ngio/io_pipes/_io_pipes.py +9 -9
  17. ngio/io_pipes/_io_pipes_masked.py +7 -7
  18. ngio/io_pipes/_io_pipes_roi.py +6 -6
  19. ngio/io_pipes/_io_pipes_types.py +3 -3
  20. ngio/io_pipes/_match_shape.py +8 -6
  21. ngio/io_pipes/_ops_slices_utils.py +5 -8
  22. ngio/ome_zarr_meta/__init__.py +18 -29
  23. ngio/ome_zarr_meta/_meta_handlers.py +708 -392
  24. ngio/ome_zarr_meta/ngio_specs/__init__.py +0 -4
  25. ngio/ome_zarr_meta/ngio_specs/_axes.py +51 -152
  26. ngio/ome_zarr_meta/ngio_specs/_dataset.py +22 -13
  27. ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py +91 -129
  28. ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +68 -57
  29. ngio/ome_zarr_meta/v04/__init__.py +1 -5
  30. ngio/ome_zarr_meta/v04/{_v04_spec.py → _v04_spec_utils.py} +85 -54
  31. ngio/ome_zarr_meta/v05/__init__.py +1 -5
  32. ngio/ome_zarr_meta/v05/{_v05_spec.py → _v05_spec_utils.py} +87 -64
  33. ngio/resources/__init__.py +1 -1
  34. ngio/resources/resource_model.py +1 -1
  35. ngio/tables/_tables_container.py +27 -85
  36. ngio/tables/backends/_anndata.py +8 -58
  37. ngio/tables/backends/_anndata_utils.py +6 -1
  38. ngio/tables/backends/_csv.py +19 -3
  39. ngio/tables/backends/_json.py +13 -10
  40. ngio/tables/backends/_non_zarr_backends.py +196 -0
  41. ngio/tables/backends/_parquet.py +31 -3
  42. ngio/tables/v1/_roi_table.py +27 -44
  43. ngio/utils/__init__.py +12 -8
  44. ngio/utils/_datasets.py +0 -6
  45. ngio/utils/_logger.py +50 -0
  46. ngio/utils/_zarr_utils.py +250 -292
  47. {ngio-0.5.0.dist-info → ngio-0.5.0a1.dist-info}/METADATA +6 -13
  48. ngio-0.5.0a1.dist-info/RECORD +88 -0
  49. {ngio-0.5.0.dist-info → ngio-0.5.0a1.dist-info}/WHEEL +1 -1
  50. ngio/images/_create_utils.py +0 -406
  51. ngio/tables/backends/_py_arrow_backends.py +0 -222
  52. ngio/utils/_cache.py +0 -48
  53. ngio-0.5.0.dist-info/RECORD +0 -88
  54. {ngio-0.5.0.dist-info → ngio-0.5.0a1.dist-info}/licenses/LICENSE +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ngio
3
- Version: 0.5.0
3
+ Version: 0.5.0a1
4
4
  Summary: Next Generation file format IO
5
5
  Project-URL: homepage, https://github.com/BioVisionCenter/ngio
6
6
  Project-URL: repository, https://github.com/BioVisionCenter/ngio
@@ -13,17 +13,16 @@ Classifier: Programming Language :: Python :: 3
13
13
  Classifier: Programming Language :: Python :: 3.11
14
14
  Classifier: Programming Language :: Python :: 3.12
15
15
  Classifier: Programming Language :: Python :: 3.13
16
- Classifier: Programming Language :: Python :: 3.14
17
16
  Classifier: Typing :: Typed
18
- Requires-Python: <3.15,>=3.11
17
+ Requires-Python: <3.14,>=3.11
19
18
  Requires-Dist: aiohttp
20
19
  Requires-Dist: anndata
21
- Requires-Dist: dask[array]<2025.11.0
22
- Requires-Dist: dask[distributed]<2025.11.0
20
+ Requires-Dist: dask[array]
21
+ Requires-Dist: dask[distributed]
23
22
  Requires-Dist: filelock
24
23
  Requires-Dist: numpy
25
24
  Requires-Dist: ome-zarr-models
26
- Requires-Dist: pandas<3.0.0,>=1.2.0
25
+ Requires-Dist: pandas>=1.2.0
27
26
  Requires-Dist: pillow
28
27
  Requires-Dist: polars
29
28
  Requires-Dist: pooch
@@ -32,6 +31,7 @@ Requires-Dist: pydantic
32
31
  Requires-Dist: requests
33
32
  Requires-Dist: zarr>3
34
33
  Provides-Extra: dev
34
+ Requires-Dist: devtools; extra == 'dev'
35
35
  Requires-Dist: matplotlib; extra == 'dev'
36
36
  Requires-Dist: mypy; extra == 'dev'
37
37
  Requires-Dist: napari; extra == 'dev'
@@ -43,7 +43,6 @@ Requires-Dist: pyqt5; extra == 'dev'
43
43
  Requires-Dist: rich; extra == 'dev'
44
44
  Requires-Dist: ruff; extra == 'dev'
45
45
  Requires-Dist: scikit-image; extra == 'dev'
46
- Requires-Dist: zarrs; extra == 'dev'
47
46
  Provides-Extra: docs
48
47
  Requires-Dist: griffe-typingdoc; extra == 'docs'
49
48
  Requires-Dist: markdown-exec[ansi]; extra == 'docs'
@@ -58,17 +57,11 @@ Requires-Dist: mkdocs-jupyter; extra == 'docs'
58
57
  Requires-Dist: mkdocs-material; extra == 'docs'
59
58
  Requires-Dist: mkdocstrings[python]; extra == 'docs'
60
59
  Requires-Dist: rich; extra == 'docs'
61
- Requires-Dist: ruff; extra == 'docs'
62
60
  Requires-Dist: scikit-image; extra == 'docs'
63
61
  Requires-Dist: tabulate; extra == 'docs'
64
62
  Provides-Extra: test
65
- Requires-Dist: boto; extra == 'test'
66
- Requires-Dist: devtools; extra == 'test'
67
- Requires-Dist: moto[server]; extra == 'test'
68
63
  Requires-Dist: pytest; extra == 'test'
69
64
  Requires-Dist: pytest-cov; extra == 'test'
70
- Requires-Dist: pytest-httpserver; extra == 'test'
71
- Requires-Dist: s3fs; extra == 'test'
72
65
  Requires-Dist: scikit-image; extra == 'test'
73
66
  Description-Content-Type: text/markdown
74
67
 
@@ -0,0 +1,88 @@
1
+ ngio/__init__.py,sha256=rEgnXuU6TCejUUGsxt4eKmjMhxjYh0fYBxWF4o5YjbE,1435
2
+ ngio/common/__init__.py,sha256=aPSuUbdGryrxbnlWrsVNe3LZoBAWC4GijR1BNH1UwuU,612
3
+ ngio/common/_dimensions.py,sha256=w8PYgyWxA8hgJETjFbw5CXf7WrasCL5FbzgfL1in86M,11361
4
+ ngio/common/_masking_roi.py,sha256=ZZTXordEZoq_ADk0OzADvq-5dPOwUBSuNobzFR8fpTw,5697
5
+ ngio/common/_pyramid.py,sha256=186eQSCxP_x2heYKmMP_Edl4Aml9Eo1bBmIHlwslqy8,8699
6
+ ngio/common/_roi.py,sha256=9fKFTHoUiP0xmxvQiFkNmIuwWg3bFuRaAx-froCSqvA,11487
7
+ ngio/common/_synt_images_utils.py,sha256=B6uYOW1NyrM06YMR-csca3_YnAAkPRTbvnbLdy9tk9E,3188
8
+ ngio/common/_zoom.py,sha256=U01c-vqXjzZkrpd9Yvs24frVfTls_xPJeeaFCGmUwYI,6727
9
+ ngio/experimental/__init__.py,sha256=3pmBtHi-i8bKjTsvrOJM56ZyRX3Pv_dceCdt88-8COQ,147
10
+ ngio/experimental/iterators/__init__.py,sha256=TECOMGb5PEEZ0yXxt8pqIGvLKG41g_L1fTJU-zGPeV8,488
11
+ ngio/experimental/iterators/_abstract_iterator.py,sha256=7aAoMI-6vYGCMKxO3M10WpuBMTdqX4zr0K-TutAOp88,13195
12
+ ngio/experimental/iterators/_feature.py,sha256=g03yHIzYpTVeD3KUq2a4TwX29Dt48XaaGdZNSykYy7M,6749
13
+ ngio/experimental/iterators/_image_processing.py,sha256=cM7sL7xgdcjSOKAu-6367Aov89o6wgiJ_wqCGkU2Bsw,5091
14
+ ngio/experimental/iterators/_mappers.py,sha256=VVVsjems57wJUnWeufUFcgqa23k7VPeFL4Nc04HVw4o,1399
15
+ ngio/experimental/iterators/_rois_utils.py,sha256=Q-8lQ26neYn63h_RvfypYqvrq2UUN2O3xqVe57k_ufU,4363
16
+ ngio/experimental/iterators/_segmentation.py,sha256=xzotGvTn04HPeMeXZ_URnQqWco6d2lH6Ng6vkCUh9NM,9153
17
+ ngio/hcs/__init__.py,sha256=G8j9vD-liLeB_UeGtKYIgshWvJnUA6ks9GwjvWBLdHs,357
18
+ ngio/hcs/_plate.py,sha256=qfRwbCKaoz_AWTi8RDFFwOxy5geSknfJrPcqFVno9zI,44288
19
+ ngio/images/__init__.py,sha256=9Whvt7GTiCgT_vXaEEqGnDaY1-UsRk3dhLTv091F_g4,1211
20
+ ngio/images/_abstract_image.py,sha256=hrB9xn4MFRxnxE1d7HKnM8SXVPUGhMD9u32yBHTsFiU,18517
21
+ ngio/images/_create.py,sha256=OirIKg843CCSiwy_oUolX2UHlROR_iO4rN_IK47jDWc,10448
22
+ ngio/images/_create_synt_container.py,sha256=D3SkjYN_AZ5fSefjEX0iQ3ZGEuBTWZvuPQIwHc6l-CU,5519
23
+ ngio/images/_image.py,sha256=JWN7qmNVZxAzm9zmaImYseDt8xzYtOw-N0olR6VQo_8,33483
24
+ ngio/images/_label.py,sha256=sJUB8of7t1YErZRu3t7jzGjlRn3KAAs0EL5nFrbvvlc,11921
25
+ ngio/images/_masked_image.py,sha256=YhbBzgPZMav6rX0WYue1BaxAzEIsfaQrxUIOK6ZWZcw,18848
26
+ ngio/images/_ome_zarr_container.py,sha256=tfG40PLNfyfaR2pVAmGINlkKJRoQ4W0L0melFotMcP8,38737
27
+ ngio/images/_table_ops.py,sha256=jFv_AMqoB4JBpoWsMtZppZVW7dAOC_u-JpfNm8b33kY,15292
28
+ ngio/io_pipes/__init__.py,sha256=arW_7GWzZs82kPNKdm_6B1sIDFV0lWwp-ZaORr9Q1FQ,2412
29
+ ngio/io_pipes/_io_pipes.py,sha256=KuwMYofE11EKx0iplWXBQZ-eE1A9YpGDprWh98cUlAI,10710
30
+ ngio/io_pipes/_io_pipes_masked.py,sha256=077j1XNgyCNOHlOsbjPOWcLtb2ccFvbLp-cPzWL1j3c,16999
31
+ ngio/io_pipes/_io_pipes_roi.py,sha256=cu_vd4MTDuyiabCWQ5ieMLI4v3tu_twSEe4X5-3bp84,4543
32
+ ngio/io_pipes/_io_pipes_types.py,sha256=xCeUd9rZe2wsgoZR1pUq6L4LSeawoPsb-9pmz5C6ztA,1393
33
+ ngio/io_pipes/_match_shape.py,sha256=eDy_Eqzld08m9zDuIjAvJnIhWh_HVjQS-5Pw9BMjdbw,13200
34
+ ngio/io_pipes/_ops_axes.py,sha256=Geg4ZXxB0njWWopX9YeiwRJJ9Ef2GKfG0NIUafOmi2c,10043
35
+ ngio/io_pipes/_ops_slices.py,sha256=hHMIOQ_niUSK9uFl8P2-10dP_K4GX3Do6vivN4fGRE0,14520
36
+ ngio/io_pipes/_ops_slices_utils.py,sha256=xjDaCVGmtME5Q0XSmGrY3nUKYgw5jOBQZW4YDq5s4vE,6580
37
+ ngio/io_pipes/_ops_transforms.py,sha256=uITs6v6sZ7DQ_Hpw3JdX8MuPOzir-bihvGzY84Qn4wY,2934
38
+ ngio/io_pipes/_zoom_transform.py,sha256=WBY1tO6_Qhf8FaDujfTdipuuqFf7PSi204wx5VKKs88,6884
39
+ ngio/ome_zarr_meta/__init__.py,sha256=tzxW2oVhfeMBVuv3XkcbOLzMnbDvUnie-AVsvSxRkdE,1265
40
+ ngio/ome_zarr_meta/_meta_handlers.py,sha256=P2Edraf2MlTMlwFOpXCkUqD1QTN2nTwGv5Ff0ab5csw,26715
41
+ ngio/ome_zarr_meta/ngio_specs/__init__.py,sha256=U2FqZR91Ob2N6CqKdyw-_Ll-wMgmGuPZGVRCr6wuRFY,1698
42
+ ngio/ome_zarr_meta/ngio_specs/_axes.py,sha256=gNzxCddn53m9dlNJlV5CL-aQS-nGJrbCDGfAp5L97LY,16412
43
+ ngio/ome_zarr_meta/ngio_specs/_channels.py,sha256=TDxIy-yVc2YaWPIFJRYnYwZbA8O5Ee_OiWppHYrEdpU,16647
44
+ ngio/ome_zarr_meta/ngio_specs/_dataset.py,sha256=CrHnjVWBGYPqErKkHR-E2DKrE3DmGznXMkd3Y9Z4uYo,3434
45
+ ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py,sha256=N1CGPOubwf0pvm8tiTnh-C1cOu9lToyDe3WagnEnPN4,17207
46
+ ngio/ome_zarr_meta/ngio_specs/_ngio_image.py,sha256=y44AVdB7IQD9t5yiZV6cXSvV9_-CGDiYrCfX3PeaclQ,16231
47
+ ngio/ome_zarr_meta/ngio_specs/_pixel_size.py,sha256=4VF1djY9T5tp6GCJXppFrUJwALI1XgIm0imoM5rNvdE,3876
48
+ ngio/ome_zarr_meta/v04/__init__.py,sha256=dJRzzxyYc81kf-0Hip_bqvbdManaM8XTdQX2meWyCSs,583
49
+ ngio/ome_zarr_meta/v04/_custom_models.py,sha256=5GxiDERvLuvq4QvApcA6EiKLS6hLFX1R0R_9rSaa85A,530
50
+ ngio/ome_zarr_meta/v04/_v04_spec_utils.py,sha256=xa3DT7VJJZyd-4EB-KGjlPcKkTmst_izTcoWj30mLiY,15766
51
+ ngio/ome_zarr_meta/v05/__init__.py,sha256=j6YuIKu2bxmhlhFCbhXg5UA4qD7V8CpyTAHl1vnIpq8,583
52
+ ngio/ome_zarr_meta/v05/_custom_models.py,sha256=ZN3bE9nwx4y3tElhsYafI4S2zp_WzdkQKcyuuBiaXXo,530
53
+ ngio/ome_zarr_meta/v05/_v05_spec_utils.py,sha256=vd9-EiZZjBpCXmwgLj8a1RWiwFpSjjxKBfbH8OpsG9M,16493
54
+ ngio/resources/__init__.py,sha256=4E4TXTNYEgRHt26C1XcC4pPobJJsmZRYm1Ml4uAuAkE,1664
55
+ ngio/resources/resource_model.py,sha256=eE1m0dyk-2psPC4X8Ifyan524QHUOd52TEQdvoU0m8I,861
56
+ ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/mask.png,sha256=g3QmxQdmeciAtBe5cTCRfR6yw3keG9cBYfjizMo6EGo,11890
57
+ ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/nuclei.png,sha256=Yw0k5pn2EHDMWTwyb7N51NX7WVk6-MlwfP9WZrhY-Ic,19446
58
+ ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/raw.jpg,sha256=82lejQAIokj5w9g-qqhysDTWpHtNvJTkdURG_BjqIxQ,37743
59
+ ngio/tables/__init__.py,sha256=_BV3sclNMLITu_J8_3DkkUrCB6Kro0HzeWLDCD1ivKM,877
60
+ ngio/tables/_abstract_table.py,sha256=rwGa47TzbFmosucBWVfFq6JEXtgGvOdUVtU9DIelV88,8204
61
+ ngio/tables/_tables_container.py,sha256=3xmpREaN671l40MPprnl1BD-VoOb6xfjECb5mNoMW0w,12173
62
+ ngio/tables/backends/__init__.py,sha256=MwSRXNF1rWQBFOTDA_vT3oGoNZpviVgytsL5Txnu08I,1619
63
+ ngio/tables/backends/_abstract_backend.py,sha256=M1ogsBpWBiQMV65YweZhA845PAtkzG2BsZCPN_7Xp8U,7613
64
+ ngio/tables/backends/_anndata.py,sha256=KBzXVxaXstVx3ofcLYYFm8ECVFDaHxfUWcKdg5vQPqY,2992
65
+ ngio/tables/backends/_anndata_utils.py,sha256=g0mIfihXd4p75bvMvCYTljBKTP13EZ9p_SVMifDKE3Y,3208
66
+ ngio/tables/backends/_csv.py,sha256=Ev61D-AUKo4LIhXRmWPJgYbHI7eQdxiajQR574DevEM,932
67
+ ngio/tables/backends/_json.py,sha256=1ZsEuXDJm1rOZV_KjFm8CB0qhv7L1W7L2EGWPf4q_p0,3137
68
+ ngio/tables/backends/_non_zarr_backends.py,sha256=5a1fbxiVnUXt1tiA025BqN0T7SQJvIERFtQHp4PhFHw,7294
69
+ ngio/tables/backends/_parquet.py,sha256=ic-p86h8lce8q9luBJGRzy6vxlWyJvA0-2l5cUD6OqY,1398
70
+ ngio/tables/backends/_table_backends.py,sha256=ksP2NAosXZkNMZf-IMrLx7bjQgp_eKfvPYK4vMdT1A8,7250
71
+ ngio/tables/backends/_utils.py,sha256=t4dLXSPxx2AnJvVtj0GIwrLoO11h4Ges6U7hj4md0hY,19730
72
+ ngio/tables/v1/__init__.py,sha256=Wr1_9RZFpaN8FYMTnxT9Yjkw4AS7y9FMWailmB_uj5g,617
73
+ ngio/tables/v1/_condition_table.py,sha256=T0Uq5BKkmMoEspt_Rx0U99Ow6S9GAMZDHqvUO5obCAM,1780
74
+ ngio/tables/v1/_feature_table.py,sha256=n9uMHwoBh-_dlOhUXCFbmAjXFVXncNCR3SjE2qzXI68,3821
75
+ ngio/tables/v1/_generic_table.py,sha256=1ktJHeuv7U1g5Z8PFUuTkCjOzcYMQd8xegKHKUedJB8,1240
76
+ ngio/tables/v1/_roi_table.py,sha256=g7UpMmpf3uAfaG59WYRnimUBgiB_T1qUJRwMZpMt9cI,17099
77
+ ngio/transforms/__init__.py,sha256=JA0-Ui7skbXkm9ofN-AEhU1FTLutkMkwTdVD-310frQ,113
78
+ ngio/transforms/_zoom.py,sha256=otyE-vxFnywUJ8U4mHjat-bNG_7_jv62ckTpqDMxyVQ,550
79
+ ngio/utils/__init__.py,sha256=XPYh8ehC7uXNU2cFFXZAw-S3DpWpX1Yq2xGkffZv5vI,1142
80
+ ngio/utils/_datasets.py,sha256=6GtxfPkjutNaeg5BHuJDBP0GudvQXHLU6mmHp_o0bGA,5650
81
+ ngio/utils/_errors.py,sha256=pKQ12LUjQLYE1nUawemA5h7HsgznjaSvV1n2PQU33N0,759
82
+ ngio/utils/_fractal_fsspec_store.py,sha256=RdcCFOgHexRKX9zZvJV5RI-5OPc7VOPS6q_IeRxm24I,1548
83
+ ngio/utils/_logger.py,sha256=N5W0a_xwze4blS1MolidBkTMbjTbg8GPguJZNun3mAE,1392
84
+ ngio/utils/_zarr_utils.py,sha256=ATehiEALPI__eNQSWdSW5PpJLmI2FECrexA9jTZAI2s,16103
85
+ ngio-0.5.0a1.dist-info/METADATA,sha256=AT0kbnHlYkhiL0_AmZpOm8DagaEPGCkI1xze_cJy3w8,6104
86
+ ngio-0.5.0a1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
87
+ ngio-0.5.0a1.dist-info/licenses/LICENSE,sha256=UgN_a1QCeNh9rZWfz-wORQFxE3elQzLWPQaoK6N6fxQ,1502
88
+ ngio-0.5.0a1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.28.0
2
+ Generator: hatchling 1.27.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,406 +0,0 @@
1
- """Utility functions for working with OME-Zarr images."""
2
-
3
- import warnings
4
- from collections.abc import Mapping, Sequence
5
- from typing import Any, Literal, TypeVar
6
-
7
- from zarr.core.array import CompressorLike
8
-
9
- from ngio.common._pyramid import ChunksLike, ImagePyramidBuilder, ShardsLike
10
- from ngio.ome_zarr_meta import (
11
- NgioImageMeta,
12
- NgioLabelMeta,
13
- update_ngio_meta,
14
- )
15
- from ngio.ome_zarr_meta.ngio_specs import (
16
- AxesHandler,
17
- Channel,
18
- ChannelsMeta,
19
- DefaultNgffVersion,
20
- DefaultSpaceUnit,
21
- DefaultTimeUnit,
22
- NgffVersions,
23
- SpaceUnits,
24
- TimeUnits,
25
- build_axes_handler,
26
- build_canonical_axes_handler,
27
- canonical_axes_order,
28
- canonical_label_axes_order,
29
- )
30
- from ngio.ome_zarr_meta.ngio_specs._axes import AxesSetup
31
- from ngio.utils import NgioValueError, StoreOrGroup, ZarrGroupHandler
32
-
33
- _image_or_label_meta = TypeVar("_image_or_label_meta", NgioImageMeta, NgioLabelMeta)
34
-
35
-
36
- def _align_to_axes(
37
- *,
38
- values: dict[str, float],
39
- axes_handler: AxesHandler,
40
- default_value: float = 1.0,
41
- ) -> tuple[float, ...]:
42
- """Align given values to axes names."""
43
- aligned_values = [default_value] * len(axes_handler.axes_names)
44
- for ax, value in values.items():
45
- index = axes_handler.get_index(ax)
46
- if index is not None:
47
- aligned_values[index] = value
48
- return tuple(aligned_values)
49
-
50
-
51
- def _check_deprecated_scaling_factors(
52
- *,
53
- yx_scaling_factor: float | tuple[float, float] | None = None,
54
- z_scaling_factor: float | None = None,
55
- scaling_factors: Sequence[float] | Literal["auto"] = "auto",
56
- shape: tuple[int, ...],
57
- ) -> Sequence[float] | Literal["auto"]:
58
- if yx_scaling_factor is not None or z_scaling_factor is not None:
59
- warnings.warn(
60
- "The 'yx_scaling_factor' and 'z_scaling_factor' arguments are deprecated "
61
- "and will be removed in ngio=0.6. Please use the 'scaling_factors' "
62
- "argument instead.",
63
- DeprecationWarning,
64
- stacklevel=2,
65
- )
66
- if scaling_factors != "auto":
67
- raise NgioValueError(
68
- "Cannot use both 'scaling_factors' and deprecated "
69
- "'yx_scaling_factor'/'z_scaling_factor' arguments."
70
- )
71
- if isinstance(yx_scaling_factor, tuple):
72
- if len(yx_scaling_factor) != 2:
73
- raise NgioValueError(
74
- "yx_scaling_factor tuple must have length 2 for y and x scaling."
75
- )
76
- y_scale = yx_scaling_factor[0]
77
- x_scale = yx_scaling_factor[1]
78
- else:
79
- y_scale = yx_scaling_factor if yx_scaling_factor is not None else 2.0
80
- x_scale = yx_scaling_factor if yx_scaling_factor is not None else 2.0
81
- z_scale = z_scaling_factor if z_scaling_factor is not None else 1.0
82
- scaling_factors = (z_scale, x_scale, y_scale)
83
- if len(scaling_factors) < len(shape):
84
- padding = (1.0,) * (len(shape) - len(scaling_factors))
85
- scaling_factors = padding + scaling_factors
86
-
87
- return scaling_factors
88
- return scaling_factors
89
-
90
-
91
- def _compute_scaling_factors(
92
- *,
93
- scaling_factors: Sequence[float] | Literal["auto"],
94
- shape: tuple[int, ...],
95
- axes_handler: AxesHandler,
96
- xy_scaling_factor: float | tuple[float, float] | None = None,
97
- z_scaling_factor: float | None = None,
98
- ) -> tuple[float, ...]:
99
- """Compute scaling factors for given axes names."""
100
- # TODO remove with ngio 0.6
101
- scaling_factors = _check_deprecated_scaling_factors(
102
- yx_scaling_factor=xy_scaling_factor,
103
- z_scaling_factor=z_scaling_factor,
104
- scaling_factors=scaling_factors,
105
- shape=shape,
106
- )
107
- if scaling_factors == "auto":
108
- return _align_to_axes(
109
- values={
110
- "x": 2.0,
111
- "y": 2.0,
112
- "z": 1.0,
113
- },
114
- axes_handler=axes_handler,
115
- )
116
- if len(scaling_factors) != len(shape):
117
- raise NgioValueError(
118
- "Length of scaling_factors does not match the number of dimensions."
119
- )
120
- return tuple(scaling_factors)
121
-
122
-
123
- def compute_base_scale(
124
- *,
125
- pixelsize: float | tuple[float, float],
126
- z_spacing: float,
127
- time_spacing: float,
128
- axes_handler: AxesHandler,
129
- ) -> tuple[float, ...]:
130
- """Compute base scale for given axes names."""
131
- if isinstance(pixelsize, tuple):
132
- if len(pixelsize) != 2:
133
- raise NgioValueError(
134
- "pixelsize tuple must have length 2 for y and x pixel sizes."
135
- )
136
- x_size = pixelsize[1]
137
- y_size = pixelsize[0]
138
- else:
139
- x_size = pixelsize
140
- y_size = pixelsize
141
- return _align_to_axes(
142
- values={
143
- "x": x_size,
144
- "y": y_size,
145
- "z": z_spacing,
146
- "t": time_spacing,
147
- },
148
- axes_handler=axes_handler,
149
- )
150
-
151
-
152
- def _create_image_like_group(
153
- *,
154
- store: StoreOrGroup,
155
- pyramid_builder: ImagePyramidBuilder,
156
- meta: _image_or_label_meta,
157
- overwrite: bool = False,
158
- ) -> ZarrGroupHandler:
159
- """Advanced create empty image container function placeholder."""
160
- mode = "w" if overwrite else "w-"
161
- group_handler = ZarrGroupHandler(
162
- store=store, mode=mode, cache=False, zarr_format=meta.zarr_format
163
- )
164
- update_ngio_meta(group_handler, meta)
165
- # Reopen in r+ mode
166
- group_handler = group_handler.reopen_handler()
167
- # Write the pyramid
168
- pyramid_builder.to_zarr(group=group_handler.group)
169
- return group_handler
170
-
171
-
172
- def _add_channels_meta(
173
- *,
174
- meta: _image_or_label_meta,
175
- channels_meta: Sequence[str | Channel] | None = None,
176
- ) -> _image_or_label_meta:
177
- """Create ChannelsMeta from given channels_meta input."""
178
- if isinstance(meta, NgioLabelMeta):
179
- if channels_meta is not None:
180
- raise NgioValueError(
181
- "Cannot add channels_meta to NgioLabelMeta. "
182
- "Labels do not have channels."
183
- )
184
- else:
185
- return meta
186
- if channels_meta is None:
187
- return meta
188
- list_of_channels = []
189
- for c in channels_meta:
190
- if isinstance(c, str):
191
- channel = Channel.default_init(label=c)
192
- elif isinstance(c, Channel):
193
- channel = c
194
- else:
195
- raise NgioValueError(
196
- "channels_meta must be a list of strings or Channel objects."
197
- )
198
- list_of_channels.append(channel)
199
-
200
- channels_meta_ = ChannelsMeta(channels=list_of_channels)
201
- meta.set_channels_meta(channels_meta=channels_meta_)
202
- return meta
203
-
204
-
205
- def _build_axes_handler(
206
- *,
207
- shape: tuple[int, ...],
208
- meta_type: type[_image_or_label_meta],
209
- axes_names: Sequence[str] | None = None,
210
- axes_setup: AxesSetup | None = None,
211
- ) -> AxesHandler:
212
- """Build axes handler for given shape and axes names."""
213
- if meta_type is NgioImageMeta:
214
- canonical_axes_order_ = canonical_axes_order()
215
- else:
216
- canonical_axes_order_ = canonical_label_axes_order()
217
- if axes_names is None:
218
- axes_names = canonical_axes_order_[-len(shape) :]
219
-
220
- if axes_setup is None:
221
- return build_canonical_axes_handler(
222
- axes_names=axes_names,
223
- canonical_channel_order=canonical_axes_order_,
224
- )
225
- return build_axes_handler(
226
- axes_names=axes_names,
227
- axes_setup=axes_setup,
228
- )
229
-
230
-
231
- def init_image_like(
232
- *,
233
- # Where to create the image
234
- store: StoreOrGroup,
235
- # Ngff image parameters
236
- meta_type: type[_image_or_label_meta],
237
- shape: Sequence[int],
238
- pixelsize: float | tuple[float, float],
239
- z_spacing: float = 1.0,
240
- time_spacing: float = 1.0,
241
- scaling_factors: Sequence[float] | Literal["auto"] = "auto",
242
- levels: int | list[str] = 5,
243
- translation: Sequence[float] | None = None,
244
- space_unit: SpaceUnits | str | None = DefaultSpaceUnit,
245
- time_unit: TimeUnits | str | None = DefaultTimeUnit,
246
- axes_names: Sequence[str] | None = None,
247
- name: str | None = None,
248
- channels_meta: Sequence[str | Channel] | None = None,
249
- ngff_version: NgffVersions = DefaultNgffVersion,
250
- # Zarr Array parameters
251
- chunks: ChunksLike = "auto",
252
- shards: ShardsLike | None = None,
253
- dtype: str = "uint16",
254
- dimension_separator: Literal[".", "/"] = "/",
255
- compressors: CompressorLike = "auto",
256
- extra_array_kwargs: Mapping[str, Any] | None = None,
257
- # internal axes configuration for advanced use cases
258
- axes_setup: AxesSetup | None = None,
259
- # Whether to overwrite existing image
260
- overwrite: bool = False,
261
- # Deprecated arguments
262
- yx_scaling_factor: float | tuple[float, float] | None = None,
263
- z_scaling_factor: float | None = None,
264
- ) -> tuple[ZarrGroupHandler, AxesSetup]:
265
- """Create an empty OME-Zarr image with the given shape and metadata."""
266
- shape = tuple(shape)
267
- axes_handler = _build_axes_handler(
268
- shape=shape,
269
- meta_type=meta_type,
270
- axes_names=axes_names,
271
- axes_setup=axes_setup,
272
- )
273
- if len(shape) != len(axes_handler.axes_names):
274
- raise NgioValueError(
275
- f"Mismatch between shape {shape} "
276
- f"and number of axes {len(axes_handler.axes_names)}."
277
- )
278
- base_scale = compute_base_scale(
279
- pixelsize=pixelsize,
280
- z_spacing=z_spacing,
281
- time_spacing=time_spacing,
282
- axes_handler=axes_handler,
283
- )
284
- scaling_factors = _compute_scaling_factors(
285
- scaling_factors=scaling_factors,
286
- shape=shape,
287
- axes_handler=axes_handler,
288
- xy_scaling_factor=yx_scaling_factor,
289
- z_scaling_factor=z_scaling_factor,
290
- )
291
- if isinstance(levels, int):
292
- levels_paths = tuple(str(i) for i in range(levels))
293
- else:
294
- levels_paths = tuple(levels)
295
-
296
- pyramid_builder = ImagePyramidBuilder.from_scaling_factors(
297
- levels_paths=levels_paths,
298
- scaling_factors=scaling_factors,
299
- base_shape=shape,
300
- base_scale=base_scale,
301
- base_translation=translation,
302
- axes=axes_handler.axes_names,
303
- chunks=chunks,
304
- data_type=dtype,
305
- dimension_separator=dimension_separator,
306
- compressors=compressors,
307
- shards=shards,
308
- zarr_format=2 if ngff_version == "0.4" else 3,
309
- other_array_kwargs=extra_array_kwargs,
310
- )
311
- meta = meta_type.default_init(
312
- levels=[p.path for p in pyramid_builder.levels],
313
- axes_handler=axes_handler,
314
- scales=[p.scale for p in pyramid_builder.levels],
315
- translations=[p.translation for p in pyramid_builder.levels],
316
- name=name,
317
- version=ngff_version,
318
- )
319
- meta = _add_channels_meta(meta=meta, channels_meta=channels_meta)
320
- # Keep this creation at the end to avoid partial creations on errors
321
- image_handler = _create_image_like_group(
322
- store=store,
323
- pyramid_builder=pyramid_builder,
324
- meta=meta,
325
- overwrite=overwrite,
326
- )
327
- return image_handler, axes_handler.axes_setup
328
-
329
-
330
- def init_image_like_from_shapes(
331
- *,
332
- # Where to create the image
333
- store: StoreOrGroup,
334
- # Ngff image parameters
335
- meta_type: type[_image_or_label_meta],
336
- shapes: Sequence[tuple[int, ...]],
337
- base_scale: tuple[float, ...] | list[tuple[float, ...]],
338
- levels: list[str] | None = None,
339
- translation: Sequence[float] | None = None,
340
- space_unit: SpaceUnits | str | None = DefaultSpaceUnit,
341
- time_unit: TimeUnits | str | None = DefaultTimeUnit,
342
- axes_names: Sequence[str] | None = None,
343
- name: str | None = None,
344
- channels_meta: Sequence[str | Channel] | None = None,
345
- ngff_version: NgffVersions = DefaultNgffVersion,
346
- # Zarr Array parameters
347
- chunks: ChunksLike = "auto",
348
- shards: ShardsLike | None = None,
349
- dtype: str = "uint16",
350
- dimension_separator: Literal[".", "/"] = "/",
351
- compressors: CompressorLike = "auto",
352
- extra_array_kwargs: Mapping[str, Any] | None = None,
353
- # internal axes configuration for advanced use cases
354
- axes_setup: AxesSetup | None = None,
355
- # Whether to overwrite existing image
356
- overwrite: bool = False,
357
- ) -> tuple[ZarrGroupHandler, AxesSetup]:
358
- """Create an empty OME-Zarr image with the given shape and metadata."""
359
- base_shape = shapes[0]
360
- axes_handler = _build_axes_handler(
361
- shape=base_shape,
362
- meta_type=meta_type,
363
- axes_names=axes_names,
364
- axes_setup=axes_setup,
365
- )
366
- if len(base_shape) != len(axes_handler.axes_names):
367
- raise NgioValueError(
368
- f"Mismatch between shape {base_shape} "
369
- f"and number of axes {len(axes_handler.axes_names)}."
370
- )
371
- if levels is None:
372
- levels_paths = tuple(str(i) for i in range(len(shapes)))
373
- else:
374
- levels_paths = tuple(levels)
375
-
376
- pyramid_builder = ImagePyramidBuilder.from_shapes(
377
- shapes=shapes,
378
- base_scale=base_scale,
379
- base_translation=translation,
380
- levels_paths=levels_paths,
381
- axes=axes_handler.axes_names,
382
- chunks=chunks,
383
- data_type=dtype,
384
- dimension_separator=dimension_separator,
385
- compressors=compressors,
386
- shards=shards,
387
- zarr_format=2 if ngff_version == "0.4" else 3,
388
- other_array_kwargs=extra_array_kwargs,
389
- )
390
- meta = meta_type.default_init(
391
- levels=[p.path for p in pyramid_builder.levels],
392
- axes_handler=axes_handler,
393
- scales=[p.scale for p in pyramid_builder.levels],
394
- translations=[p.translation for p in pyramid_builder.levels],
395
- name=name,
396
- version=ngff_version,
397
- )
398
- meta = _add_channels_meta(meta=meta, channels_meta=channels_meta)
399
- # Keep this creation at the end to avoid partial creations on errors
400
- image_handler = _create_image_like_group(
401
- store=store,
402
- pyramid_builder=pyramid_builder,
403
- meta=meta,
404
- overwrite=overwrite,
405
- )
406
- return image_handler, axes_handler.axes_setup