ngio 0.4.3__py3-none-any.whl → 0.4.5__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.
ngio/common/_pyramid.py CHANGED
@@ -2,6 +2,7 @@ import math
2
2
  from collections.abc import Callable, Sequence
3
3
  from typing import Literal
4
4
 
5
+ import dask
5
6
  import dask.array as da
6
7
  import numpy as np
7
8
  import zarr
@@ -36,9 +37,17 @@ def _on_disk_dask_zoom(
36
37
  ) -> None:
37
38
  source_array = da.from_zarr(source)
38
39
  target_array = dask_zoom(source_array, target_shape=target.shape, order=order)
39
-
40
+ # This is a potential fix for Dask 2025.11
41
+ # chunk_size_bytes = np.prod(target.chunks) * target_array.dtype.itemsize
42
+ # current_chunk_size = dask.config.get("array.chunk-size", 0)
43
+ #
44
+ #if current_chunk_size < chunk_size_bytes:
45
+ # # Increase the chunk size to avoid dask potentially creating
46
+ # # corrupted chunks when writing chunks that are not multiple of the
47
+ # # target chunk size
48
+ # dask.config.set({"array.chunk-size": f"{chunk_size_bytes}B"})
40
49
  target_array = target_array.rechunk(target.chunks)
41
- target_array.compute_chunk_sizes()
50
+ target_array = target_array.compute_chunk_sizes()
42
51
  target_array.to_zarr(target)
43
52
 
44
53
 
@@ -241,13 +250,11 @@ def init_empty_pyramid(
241
250
  compressor=compressor,
242
251
  )
243
252
 
244
- _shape = [
253
+ ref_shape = [
245
254
  math.floor(s / sc) for s, sc in zip(ref_shape, scaling_factors, strict=True)
246
255
  ]
247
- ref_shape = _shape
256
+ chunks = tuple(
257
+ min(c, s) for c, s in zip(new_arr.chunks, ref_shape, strict=True)
258
+ )
248
259
 
249
- if chunks is None:
250
- chunks = new_arr.chunks
251
- assert chunks is not None
252
- chunks = [min(c, s) for c, s in zip(chunks, ref_shape, strict=True)]
253
260
  return None
@@ -102,6 +102,20 @@ def valid_hex_color(v: str) -> bool:
102
102
  return True
103
103
 
104
104
 
105
+ def into_valid_hex_color(v: str) -> str:
106
+ """Convert a string into a valid hexadecimal color.
107
+
108
+ If the string is already a valid hexadecimal color, return it.
109
+ Otherwise, return a hexadecimal color based on the hash of the string.
110
+ """
111
+ # strip leading '#' if present
112
+ v = v.lstrip("#")
113
+ if valid_hex_color(v):
114
+ return v
115
+
116
+ return NgioColors.semi_random_pick(v.lower()).value
117
+
118
+
105
119
  class ChannelVisualisation(BaseModel):
106
120
  """Channel visualisation model.
107
121
 
@@ -135,13 +149,10 @@ class ChannelVisualisation(BaseModel):
135
149
  """
136
150
  if value is None:
137
151
  return NgioColors.semi_random_pick().value
138
- if isinstance(value, str) and valid_hex_color(value):
139
- return value
152
+ if isinstance(value, str):
153
+ return into_valid_hex_color(value)
140
154
  elif isinstance(value, NgioColors):
141
155
  return value.value
142
- elif isinstance(value, str):
143
- value_lower = value.lower()
144
- return NgioColors.semi_random_pick(value_lower).value
145
156
  else:
146
157
  raise NgioValueError(f"Invalid color {value}.")
147
158
 
@@ -159,19 +170,6 @@ class ChannelVisualisation(BaseModel):
159
170
  data["end"] = start + 1
160
171
  return data
161
172
 
162
- @model_validator(mode="after")
163
- def check_model(self) -> "ChannelVisualisation":
164
- """Check that the start and end values are within the min and max values."""
165
- if self.start < self.min or self.start > self.max:
166
- raise NgioValidationError(
167
- f"Start value {self.start} is out of range [{self.min}, {self.max}]"
168
- )
169
- if self.end < self.min or self.end > self.max:
170
- raise NgioValidationError(
171
- f"End value {self.end} is out of range [{self.min}, {self.max}]"
172
- )
173
- return self
174
-
175
173
  @classmethod
176
174
  def default_init(
177
175
  cls,
@@ -86,10 +86,10 @@ def _dataframe_to_rois(
86
86
  ) -> dict[str, Roi]:
87
87
  """Convert a DataFrame to a WorldCooROI object."""
88
88
  # Validate the columns of the DataFrame
89
- _required_columns = set(dataframe.columns).intersection(set(required_columns))
90
- if len(_required_columns) != len(required_columns):
89
+ _missing_columns = set(required_columns).difference(set(dataframe.columns))
90
+ if len(_missing_columns) != 0:
91
91
  raise NgioTableValidationError(
92
- f"Could not find required columns: {_required_columns} in the table."
92
+ f"Could not find required columns: {_missing_columns} in the table."
93
93
  )
94
94
 
95
95
  extra_columns = set(dataframe.columns).difference(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ngio
3
- Version: 0.4.3
3
+ Version: 0.4.5
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
@@ -17,8 +17,8 @@ Classifier: Typing :: Typed
17
17
  Requires-Python: <3.14,>=3.11
18
18
  Requires-Dist: aiohttp
19
19
  Requires-Dist: anndata<0.11.4,>=0.8.0
20
- Requires-Dist: dask[array]
21
- Requires-Dist: dask[distributed]
20
+ Requires-Dist: dask[array]<2025.11.0
21
+ Requires-Dist: dask[distributed]<2025.11.0
22
22
  Requires-Dist: filelock
23
23
  Requires-Dist: numpy
24
24
  Requires-Dist: ome-zarr-models
@@ -2,7 +2,7 @@ ngio/__init__.py,sha256=rEgnXuU6TCejUUGsxt4eKmjMhxjYh0fYBxWF4o5YjbE,1435
2
2
  ngio/common/__init__.py,sha256=aPSuUbdGryrxbnlWrsVNe3LZoBAWC4GijR1BNH1UwuU,612
3
3
  ngio/common/_dimensions.py,sha256=w8PYgyWxA8hgJETjFbw5CXf7WrasCL5FbzgfL1in86M,11361
4
4
  ngio/common/_masking_roi.py,sha256=ZZTXordEZoq_ADk0OzADvq-5dPOwUBSuNobzFR8fpTw,5697
5
- ngio/common/_pyramid.py,sha256=F5OI_mULxzMTpMeihC4Y22cjuB5GKN2jRdpwfMXJHiE,8018
5
+ ngio/common/_pyramid.py,sha256=Wxj8RXSWWEPm5ILqvga484Hd2j3IQ4tGzHZsL5WSOuo,8446
6
6
  ngio/common/_roi.py,sha256=9fKFTHoUiP0xmxvQiFkNmIuwWg3bFuRaAx-froCSqvA,11487
7
7
  ngio/common/_synt_images_utils.py,sha256=B6uYOW1NyrM06YMR-csca3_YnAAkPRTbvnbLdy9tk9E,3188
8
8
  ngio/common/_zoom.py,sha256=U01c-vqXjzZkrpd9Yvs24frVfTls_xPJeeaFCGmUwYI,6727
@@ -40,7 +40,7 @@ ngio/ome_zarr_meta/__init__.py,sha256=tzxW2oVhfeMBVuv3XkcbOLzMnbDvUnie-AVsvSxRkd
40
40
  ngio/ome_zarr_meta/_meta_handlers.py,sha256=ctknNDT8jxwyvxQf9on5gW31H1tRRsnneO38GT2UXoE,25880
41
41
  ngio/ome_zarr_meta/ngio_specs/__init__.py,sha256=U2FqZR91Ob2N6CqKdyw-_Ll-wMgmGuPZGVRCr6wuRFY,1698
42
42
  ngio/ome_zarr_meta/ngio_specs/_axes.py,sha256=gNzxCddn53m9dlNJlV5CL-aQS-nGJrbCDGfAp5L97LY,16412
43
- ngio/ome_zarr_meta/ngio_specs/_channels.py,sha256=CVsbG52U31TaMdTj8XqvClUdBya2Ar3qBjDo_xhP-NM,16967
43
+ ngio/ome_zarr_meta/ngio_specs/_channels.py,sha256=TDxIy-yVc2YaWPIFJRYnYwZbA8O5Ee_OiWppHYrEdpU,16647
44
44
  ngio/ome_zarr_meta/ngio_specs/_dataset.py,sha256=CrHnjVWBGYPqErKkHR-E2DKrE3DmGznXMkd3Y9Z4uYo,3434
45
45
  ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py,sha256=N1CGPOubwf0pvm8tiTnh-C1cOu9lToyDe3WagnEnPN4,17207
46
46
  ngio/ome_zarr_meta/ngio_specs/_ngio_image.py,sha256=XmqeffYRspBZmv8gCrfJvnykmBViWgDo2AtJJkR7OEs,15886
@@ -70,7 +70,7 @@ ngio/tables/v1/__init__.py,sha256=Wr1_9RZFpaN8FYMTnxT9Yjkw4AS7y9FMWailmB_uj5g,61
70
70
  ngio/tables/v1/_condition_table.py,sha256=T0Uq5BKkmMoEspt_Rx0U99Ow6S9GAMZDHqvUO5obCAM,1780
71
71
  ngio/tables/v1/_feature_table.py,sha256=n9uMHwoBh-_dlOhUXCFbmAjXFVXncNCR3SjE2qzXI68,3821
72
72
  ngio/tables/v1/_generic_table.py,sha256=1ktJHeuv7U1g5Z8PFUuTkCjOzcYMQd8xegKHKUedJB8,1240
73
- ngio/tables/v1/_roi_table.py,sha256=g7UpMmpf3uAfaG59WYRnimUBgiB_T1qUJRwMZpMt9cI,17099
73
+ ngio/tables/v1/_roi_table.py,sha256=b7lwjsdCSUOCMT6Lx4hwAqGBKC25Q5bdzoK3DQWnAQM,17074
74
74
  ngio/transforms/__init__.py,sha256=JA0-Ui7skbXkm9ofN-AEhU1FTLutkMkwTdVD-310frQ,113
75
75
  ngio/transforms/_zoom.py,sha256=otyE-vxFnywUJ8U4mHjat-bNG_7_jv62ckTpqDMxyVQ,550
76
76
  ngio/utils/__init__.py,sha256=XPYh8ehC7uXNU2cFFXZAw-S3DpWpX1Yq2xGkffZv5vI,1142
@@ -79,7 +79,7 @@ ngio/utils/_errors.py,sha256=pKQ12LUjQLYE1nUawemA5h7HsgznjaSvV1n2PQU33N0,759
79
79
  ngio/utils/_fractal_fsspec_store.py,sha256=RdcCFOgHexRKX9zZvJV5RI-5OPc7VOPS6q_IeRxm24I,1548
80
80
  ngio/utils/_logger.py,sha256=N5W0a_xwze4blS1MolidBkTMbjTbg8GPguJZNun3mAE,1392
81
81
  ngio/utils/_zarr_utils.py,sha256=GUOcAx02IcfrJ5tIdKu8ChtRUUaBbkkddW5jaCCYnS8,13797
82
- ngio-0.4.3.dist-info/METADATA,sha256=BPhEA2JyzaofdvVLPsB2O3ZGr-gr-3nPCZwJ4LOWn5A,6117
83
- ngio-0.4.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
84
- ngio-0.4.3.dist-info/licenses/LICENSE,sha256=UgN_a1QCeNh9rZWfz-wORQFxE3elQzLWPQaoK6N6fxQ,1502
85
- ngio-0.4.3.dist-info/RECORD,,
82
+ ngio-0.4.5.dist-info/METADATA,sha256=6g28iSwZ32mHJmEmOYOFaixVkTyQa-xaCy50teScyjk,6137
83
+ ngio-0.4.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
84
+ ngio-0.4.5.dist-info/licenses/LICENSE,sha256=UgN_a1QCeNh9rZWfz-wORQFxE3elQzLWPQaoK6N6fxQ,1502
85
+ ngio-0.4.5.dist-info/RECORD,,
File without changes