ngio 0.3.2__py3-none-any.whl → 0.3.4__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/hcs/_plate.py CHANGED
@@ -200,7 +200,7 @@ class OmeZarrWell:
200
200
  )
201
201
 
202
202
 
203
- def _buil_extras(paths: Collection[str]) -> list[dict[str, str]]:
203
+ def _build_extras(paths: Collection[str]) -> list[dict[str, str]]:
204
204
  """Build the extras for the images.
205
205
 
206
206
  Args:
@@ -1021,7 +1021,7 @@ class OmeZarrPlate:
1021
1021
  if 'lazy', the table will be loaded as a lazy frame.
1022
1022
  """
1023
1023
  images = self.get_images(acquisition=acquisition)
1024
- extras = _buil_extras(images.keys())
1024
+ extras = _build_extras(images.keys())
1025
1025
  return concatenate_image_tables(
1026
1026
  images=images.values(),
1027
1027
  extras=extras,
@@ -1055,7 +1055,7 @@ class OmeZarrPlate:
1055
1055
  if 'lazy', the table will be loaded as a lazy frame.
1056
1056
  """
1057
1057
  images = self.get_images(acquisition=acquisition)
1058
- extras = _buil_extras(images.keys())
1058
+ extras = _build_extras(images.keys())
1059
1059
  return concatenate_image_tables_as(
1060
1060
  images=images.values(),
1061
1061
  extras=extras,
@@ -1088,7 +1088,7 @@ class OmeZarrPlate:
1088
1088
  if 'lazy', the table will be loaded as a lazy frame.
1089
1089
  """
1090
1090
  images = await self.get_images_async(acquisition=acquisition)
1091
- extras = _buil_extras(images.keys())
1091
+ extras = _build_extras(images.keys())
1092
1092
  return await concatenate_image_tables_async(
1093
1093
  images=images.values(),
1094
1094
  extras=extras,
@@ -1122,7 +1122,7 @@ class OmeZarrPlate:
1122
1122
  if 'lazy', the table will be loaded as a lazy frame.
1123
1123
  """
1124
1124
  images = await self.get_images_async(acquisition=acquisition)
1125
- extras = _buil_extras(images.keys())
1125
+ extras = _build_extras(images.keys())
1126
1126
  return await concatenate_image_tables_as_async(
1127
1127
  images=images.values(),
1128
1128
  extras=extras,
@@ -97,7 +97,7 @@ class Table(Protocol):
97
97
 
98
98
  Either a handler or a backend must be provided.
99
99
 
100
- If the hanlder in none it will be inferred from the backend.
100
+ If the handler in none it will be inferred from the backend.
101
101
  If the backend is none, it will be inferred from the group attrs
102
102
  """
103
103
  ...
@@ -1,7 +1,7 @@
1
1
  """Ngio Tables backend implementations."""
2
2
 
3
3
  from ngio.tables.backends._abstract_backend import AbstractTableBackend, BackendMeta
4
- from ngio.tables.backends._anndata import AnnDataBackend
4
+ from ngio.tables.backends._anndata import AnnDataBackend, AnnDataBackendV1
5
5
  from ngio.tables.backends._csv import CsvTableBackend
6
6
  from ngio.tables.backends._json import JsonTableBackend
7
7
  from ngio.tables.backends._parquet import ParquetTableBackend
@@ -31,6 +31,7 @@ from ngio.tables.backends._utils import (
31
31
  __all__ = [
32
32
  "AbstractTableBackend",
33
33
  "AnnDataBackend",
34
+ "AnnDataBackendV1",
34
35
  "BackendMeta",
35
36
  "CsvTableBackend",
36
37
  "DefaultTableBackend",
@@ -75,3 +75,13 @@ class AnnDataBackend(AbstractTableBackend):
75
75
  index_key=self.index_key,
76
76
  )
77
77
  self.write_from_anndata(anndata)
78
+
79
+
80
+
81
+ class AnnDataBackendV1(AnnDataBackend):
82
+ """A wrapper for the AnnData backend that for backwards compatibility."""
83
+
84
+ @staticmethod
85
+ def backend_name() -> str:
86
+ """Return the name of the backend."""
87
+ return "anndata_v1"
@@ -7,7 +7,7 @@ from pandas import DataFrame
7
7
  from polars import DataFrame as PolarsDataFrame
8
8
  from polars import LazyFrame
9
9
 
10
- from ngio.tables.backends._anndata import AnnDataBackend
10
+ from ngio.tables.backends._anndata import AnnDataBackend, AnnDataBackendV1
11
11
  from ngio.tables.backends._csv import CsvTableBackend
12
12
  from ngio.tables.backends._json import JsonTableBackend
13
13
  from ngio.tables.backends._parquet import ParquetTableBackend
@@ -213,7 +213,8 @@ class ImplementedTableBackends:
213
213
  )
214
214
 
215
215
 
216
- ImplementedTableBackends().add_backend(AnnDataBackend, aliases=["anndata_v1"])
216
+ ImplementedTableBackends().add_backend(AnnDataBackend)
217
+ ImplementedTableBackends().add_backend(AnnDataBackendV1)
217
218
  ImplementedTableBackends().add_backend(
218
219
  JsonTableBackend, aliases=["experimental_json_v1"]
219
220
  )
@@ -23,7 +23,7 @@ class ConditionTableV1(AbstractBaseTable):
23
23
  The condition table is a generic table that does not
24
24
  have a specific definition.
25
25
 
26
- It is used to store informations about the particular conditions
26
+ It is used to store information about the particular conditions
27
27
  used to generate the data.
28
28
  - How much drug was used in the experiment
29
29
  - What treatment was used
ngio/utils/__init__.py CHANGED
@@ -3,7 +3,11 @@
3
3
  import os
4
4
 
5
5
  from ngio.common._common_types import ArrayLike
6
- from ngio.utils._datasets import download_ome_zarr_dataset, list_ome_zarr_datasets
6
+ from ngio.utils._datasets import (
7
+ download_ome_zarr_dataset,
8
+ list_ome_zarr_datasets,
9
+ print_datasets_infos,
10
+ )
7
11
  from ngio.utils._errors import (
8
12
  NgioFileExistsError,
9
13
  NgioFileNotFoundError,
@@ -34,13 +38,13 @@ __all__ = [
34
38
  "NgioValueError",
35
39
  "StoreOrGroup",
36
40
  "ZarrGroupHandler",
37
- # Datasets
41
+ # Other
38
42
  "download_ome_zarr_dataset",
39
- # Fractal
40
43
  "fractal_fsspec_store",
41
44
  "list_ome_zarr_datasets",
42
45
  # Logger
43
46
  "ngio_logger",
44
47
  "open_group_wrapper",
48
+ "print_datasets_infos",
45
49
  "set_logger_level",
46
50
  ]
ngio/utils/_datasets.py CHANGED
@@ -1,35 +1,124 @@
1
1
  """Download testing OME-Zarr datasets."""
2
2
 
3
+ import shutil
3
4
  from pathlib import Path
5
+ from typing import Literal
4
6
 
5
7
  import pooch
6
8
 
7
9
  from ngio.utils._errors import NgioValueError
8
10
 
11
+
12
+ class UnzipAndRename(pooch.Unzip):
13
+ """Unzip and rename the extracted directory."""
14
+
15
+ def __init__(
16
+ self,
17
+ extract_dir: str = "",
18
+ out_name: str = "ome-zarr.zarr",
19
+ re_unzip: bool = True,
20
+ **kwargs,
21
+ ):
22
+ super().__init__(extract_dir=extract_dir, **kwargs)
23
+ self.out_name = out_name
24
+ self.re_unzip = re_unzip
25
+
26
+ def output_file(self) -> Path:
27
+ """Return the output file path."""
28
+ if self.extract_dir is None:
29
+ raise NgioValueError("extract_dir must be set for UnzipAndRename.")
30
+
31
+ return Path(self.extract_dir) / self.out_name
32
+
33
+ def _extract_file(self, fname, extract_dir):
34
+ """Extract the file and rename it."""
35
+ output_path = self.output_file()
36
+ if output_path.exists() and not self.re_unzip:
37
+ # Nothing to do, the file already exists and we are not re-unzipping
38
+ return None
39
+
40
+ tmp_dir = Path(extract_dir) / "tmp"
41
+ super()._extract_file(fname, tmp_dir)
42
+
43
+ list_extracted_dirs = tmp_dir.iterdir()
44
+ # Keep only if ends with .zarr
45
+ list_extracted_dirs = filter(
46
+ lambda x: x.name.endswith(".zarr"),
47
+ list_extracted_dirs,
48
+ )
49
+ list_extracted_dirs = list(list_extracted_dirs)
50
+ if len(list_extracted_dirs) != 1:
51
+ raise NgioValueError(
52
+ "Expected one directory to be extracted, "
53
+ f"got {len(list_extracted_dirs)}."
54
+ )
55
+
56
+ extracted_dir = list_extracted_dirs[0]
57
+ if output_path.exists():
58
+ shutil.rmtree(output_path, ignore_errors=True)
59
+
60
+ extracted_dir.rename(output_path)
61
+ # Clean up the temporary directory
62
+ shutil.rmtree(tmp_dir, ignore_errors=True)
63
+
64
+
9
65
  _ome_zarr_zoo = {
10
66
  "CardiomyocyteTiny": {
11
67
  "url": "https://zenodo.org/records/13305156/files/20200812-CardiomyocyteDifferentiation14-Cycle1.zarr.zip",
12
68
  "known_hash": "md5:efc21fe8d4ea3abab76226d8c166452c",
13
- "fname": "20200812-CardiomyocyteDifferentiation14-Cycle1.zarr.zip",
14
- "processor": pooch.Unzip(extract_dir=""),
69
+ "fname": "20200812-CardiomyocyteDifferentiation14-Cycle1-tiny.zarr.zip",
70
+ "description": "Tiny cardiomyocyte dataset 3D (32MB).",
71
+ },
72
+ "CardiomyocyteTinyMip": {
73
+ "url": "https://zenodo.org/records/13305156/files/20200812-CardiomyocyteDifferentiation14-Cycle1_mip.zarr.zip",
74
+ "known_hash": "md5:51809479777cafbe9ac0f9fa5636aa95",
75
+ "fname": "20200812-CardiomyocyteDifferentiation14-Cycle1-tiny-mip.zarr.zip",
76
+ "description": "Tiny cardiomyocyte dataset 2D MIP (16.4MB).",
77
+ },
78
+ "CardiomyocyteSmall": {
79
+ "url": "https://zenodo.org/records/13305316/files/20200812-CardiomyocyteDifferentiation14-Cycle1.zarr.zip",
80
+ "known_hash": "md5:d5752ed4b72a9092a0290b3c04c0b9c2",
81
+ "fname": "20200812-CardiomyocyteDifferentiation14-Cycle1-small.zarr.zip",
82
+ "description": "Small cardiomyocyte dataset 3D (750MB).",
15
83
  },
16
84
  "CardiomyocyteSmallMip": {
17
85
  "url": "https://zenodo.org/records/13305316/files/20200812-CardiomyocyteDifferentiation14-Cycle1_mip.zarr.zip",
18
86
  "known_hash": "md5:3ed3ea898e0ed42d397da2e1dbe40750",
87
+ "fname": "20200812-CardiomyocyteDifferentiation14-Cycle1-small-mip.zarr.zip",
88
+ "description": "Small cardiomyocyte dataset 2D MIP (106MB).",
89
+ },
90
+ "CardiomyocyteMediumMip": {
91
+ "url": "https://zenodo.org/records/14826000/files/20200812-CardiomyocyteDifferentiation14-Cycle1_mip.zarr.zip",
92
+ "known_hash": "md5:3f932bbf7fc0577f58b97471707816a1",
19
93
  "fname": "20200812-CardiomyocyteDifferentiation14-Cycle1_mip.zarr.zip",
20
- "processor": pooch.Unzip(extract_dir=""),
94
+ "description": "Medium cardiomyocyte dataset 2D MIP (30GB).",
21
95
  },
22
96
  }
23
97
 
98
+ AVAILABLE_DATASETS = Literal[
99
+ "CardiomyocyteTiny",
100
+ "CardiomyocyteTinyMip",
101
+ "CardiomyocyteSmall",
102
+ "CardiomyocyteSmallMip",
103
+ "CardiomyocyteMediumMip",
104
+ ]
105
+
24
106
 
25
107
  def list_ome_zarr_datasets() -> list[str]:
26
108
  """List available OME-Zarr datasets."""
27
109
  return list(_ome_zarr_zoo.keys())
28
110
 
29
111
 
112
+ def print_datasets_infos() -> None:
113
+ for dataset_name, dataset_info in _ome_zarr_zoo.items():
114
+ print(f"{dataset_name} - Description: {dataset_info['description']}")
115
+
116
+
30
117
  def download_ome_zarr_dataset(
31
- dataset_name: str,
118
+ dataset_name: AVAILABLE_DATASETS | str,
32
119
  download_dir: str | Path = "data",
120
+ re_unzip: bool = True,
121
+ progressbar: bool = False,
33
122
  ) -> Path:
34
123
  """Download an OME-Zarr dataset.
35
124
 
@@ -38,16 +127,28 @@ def download_ome_zarr_dataset(
38
127
  Args:
39
128
  dataset_name (str): The dataset name.
40
129
  download_dir (str): The download directory. Defaults to "data".
130
+ re_unzip (bool): If True, it will unzip the dataset even if it already exists.
131
+ progressbar (bool): If True, show a progress bar during download.
41
132
  """
42
133
  if dataset_name not in _ome_zarr_zoo:
43
134
  raise NgioValueError(f"Dataset {dataset_name} not found in the OME-Zarr zoo.")
44
- ome_zarr_url = _ome_zarr_zoo[dataset_name]
135
+ zenodo_infos = _ome_zarr_zoo[dataset_name]
136
+
137
+ fname = zenodo_infos["fname"]
138
+ zarrname = fname.replace(".zip", "")
139
+
140
+ processor = UnzipAndRename(
141
+ extract_dir="",
142
+ out_name=zarrname,
143
+ re_unzip=re_unzip,
144
+ )
145
+
45
146
  pooch.retrieve(
147
+ url=zenodo_infos["url"],
148
+ known_hash=zenodo_infos["known_hash"],
149
+ fname=fname,
46
150
  path=download_dir,
47
- **ome_zarr_url,
151
+ processor=processor,
152
+ progressbar=progressbar,
48
153
  )
49
- path = Path(download_dir) / ome_zarr_url["fname"]
50
-
51
- if isinstance(ome_zarr_url["processor"], pooch.Unzip):
52
- path = path.with_suffix("")
53
- return path
154
+ return processor.output_file()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ngio
3
- Version: 0.3.2
3
+ Version: 0.3.4
4
4
  Summary: Next Generation file format IO
5
5
  Project-URL: homepage, https://github.com/fractal-analytics-platform/ngio
6
6
  Project-URL: repository, https://github.com/fractal-analytics-platform/ngio
@@ -11,7 +11,7 @@ ngio/common/_slicer.py,sha256=AKpwXRncOmF9nhjKYma0C_41WqAgSv860beKGx-aw-0,3075
11
11
  ngio/common/_table_ops.py,sha256=ToNR7F053l1dubVv-gvBD-523T10HnE2UzqeU2BuNy8,15494
12
12
  ngio/common/_zoom.py,sha256=KsURa5VuixmpbAAY5-6obmuQV8vfiHKZqBxZDXvchpM,5473
13
13
  ngio/hcs/__init__.py,sha256=G8j9vD-liLeB_UeGtKYIgshWvJnUA6ks9GwjvWBLdHs,357
14
- ngio/hcs/_plate.py,sha256=o8g4WkbFPABV8mBRqyVLbLrKhwFvsf94LwwcBZac_7A,44260
14
+ ngio/hcs/_plate.py,sha256=o-Myg1sPUT9mCfYjHOuUTIpm2Nl0siacmuztGoPcYc0,44265
15
15
  ngio/images/__init__.py,sha256=PlYvbHOMvZLDgn_PeGrytOEU3e_-AO8GWpRjEqoX_Gw,536
16
16
  ngio/images/_abstract_image.py,sha256=8PNQPZjiDz-pcTFXSJAVw7nUr4yL_iRwqDEUTKkAnp0,10266
17
17
  ngio/images/_create.py,sha256=XYn30m_2OSZeHHASYHc3eK9u_gZIYy9wo6mGdRGaq5c,9473
@@ -33,29 +33,29 @@ ngio/ome_zarr_meta/v04/_custom_models.py,sha256=5GxiDERvLuvq4QvApcA6EiKLS6hLFX1R
33
33
  ngio/ome_zarr_meta/v04/_v04_spec_utils.py,sha256=05tEr2eEP_XVIfBMOAWLT7lzJV4KS5eYrpK8l94tn3w,15876
34
34
  ngio/tables/__init__.py,sha256=_BV3sclNMLITu_J8_3DkkUrCB6Kro0HzeWLDCD1ivKM,877
35
35
  ngio/tables/_abstract_table.py,sha256=rwGa47TzbFmosucBWVfFq6JEXtgGvOdUVtU9DIelV88,8204
36
- ngio/tables/_tables_container.py,sha256=w1rT_5kMh23OHXpFJI3edTH1-tul0YLIYY6x5lMn2k4,12173
37
- ngio/tables/backends/__init__.py,sha256=nQZVazwTL1IHU08gL-BZcFZd7Cehhbc_AsJ3t3XSps0,1577
36
+ ngio/tables/_tables_container.py,sha256=3xmpREaN671l40MPprnl1BD-VoOb6xfjECb5mNoMW0w,12173
37
+ ngio/tables/backends/__init__.py,sha256=MwSRXNF1rWQBFOTDA_vT3oGoNZpviVgytsL5Txnu08I,1619
38
38
  ngio/tables/backends/_abstract_backend.py,sha256=tsbHzSPTX88fiCbVc8khXv5aN68ck6HKG8r5OHkY3S8,7457
39
- ngio/tables/backends/_anndata.py,sha256=8RX2NO15CLxys3p6gw54Nd-_0WATU4WBlNndX06wvzI,2587
39
+ ngio/tables/backends/_anndata.py,sha256=EdzGH0Zr85GBjVVBy3OxnRoDGgsi5zZLWRWpSLF2GhQ,2832
40
40
  ngio/tables/backends/_anndata_utils.py,sha256=DBWIcR0btnH-DIvDvzlcnMXoYhhtXc9DstryiOP0Qsg,3122
41
41
  ngio/tables/backends/_csv.py,sha256=Ev61D-AUKo4LIhXRmWPJgYbHI7eQdxiajQR574DevEM,932
42
42
  ngio/tables/backends/_json.py,sha256=1ZsEuXDJm1rOZV_KjFm8CB0qhv7L1W7L2EGWPf4q_p0,3137
43
43
  ngio/tables/backends/_non_zarr_backends.py,sha256=SvPPhT6n5TrKUOyV1mNcdHQK49huZ5lwR8EVe9MdydM,7254
44
44
  ngio/tables/backends/_parquet.py,sha256=ic-p86h8lce8q9luBJGRzy6vxlWyJvA0-2l5cUD6OqY,1398
45
- ngio/tables/backends/_table_backends.py,sha256=QUS59VU395966AEul2SNJQAzklSitvISL0wnZTKWZa0,7267
45
+ ngio/tables/backends/_table_backends.py,sha256=56lMLrkmRS8-NTwNF0wkMzrRwTmOFLk1g_LBDA2i6wg,7318
46
46
  ngio/tables/backends/_utils.py,sha256=tJBSWN6OhO_1ybxl4vT2l3ImB028Fb6h0vaitPRcr8A,19668
47
47
  ngio/tables/v1/__init__.py,sha256=Wr1_9RZFpaN8FYMTnxT9Yjkw4AS7y9FMWailmB_uj5g,617
48
- ngio/tables/v1/_condition_table.py,sha256=IMU3sds8wrKGqU-C20HbpFCVGZX1L_V7Sh8f7CHB_x0,1781
48
+ ngio/tables/v1/_condition_table.py,sha256=T0Uq5BKkmMoEspt_Rx0U99Ow6S9GAMZDHqvUO5obCAM,1780
49
49
  ngio/tables/v1/_feature_table.py,sha256=n9uMHwoBh-_dlOhUXCFbmAjXFVXncNCR3SjE2qzXI68,3821
50
50
  ngio/tables/v1/_generic_table.py,sha256=1ktJHeuv7U1g5Z8PFUuTkCjOzcYMQd8xegKHKUedJB8,1240
51
51
  ngio/tables/v1/_roi_table.py,sha256=DgXhp-DHTeEJwzSsSRSlnPghjMhYGa3IGSpwTt5LKZU,13603
52
- ngio/utils/__init__.py,sha256=r3nuLWgp6-cQlS4ODjYSBrfgdTLkCOVke9jKbn1NpkA,1129
53
- ngio/utils/_datasets.py,sha256=EdYJHIifpRou4f43dIuiKsdxe4K6FaeS4f1_e_EYrcI,1727
52
+ ngio/utils/__init__.py,sha256=VxPVDKF0QF9HtG8wY0J6PXESNcWLaMXQNZiw5dHflBU,1179
53
+ ngio/utils/_datasets.py,sha256=2g-Neg78dNcqyDz39QQw-Ifp9GITHjVHisdqgvvDNDE,5475
54
54
  ngio/utils/_errors.py,sha256=pKQ12LUjQLYE1nUawemA5h7HsgznjaSvV1n2PQU33N0,759
55
55
  ngio/utils/_fractal_fsspec_store.py,sha256=RdcCFOgHexRKX9zZvJV5RI-5OPc7VOPS6q_IeRxm24I,1548
56
56
  ngio/utils/_logger.py,sha256=HIuqD_2ShfFGDswBddcouStbKfL0Vz_ah8cAIFGhbS8,888
57
57
  ngio/utils/_zarr_utils.py,sha256=qOI-HL2HsfFLCj_yxsTR-aq4oHpSqS9KR13aEIvhGDY,13593
58
- ngio-0.3.2.dist-info/METADATA,sha256=lTCmsFw4q7EZUvjlH6aSpnqVDnUnP025vdUrp1o7pyY,5868
59
- ngio-0.3.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
60
- ngio-0.3.2.dist-info/licenses/LICENSE,sha256=UgN_a1QCeNh9rZWfz-wORQFxE3elQzLWPQaoK6N6fxQ,1502
61
- ngio-0.3.2.dist-info/RECORD,,
58
+ ngio-0.3.4.dist-info/METADATA,sha256=CejDvwMriZ2JvTO2bLW3AA0W3zlAGmWjU10Hw20thy8,5868
59
+ ngio-0.3.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
60
+ ngio-0.3.4.dist-info/licenses/LICENSE,sha256=UgN_a1QCeNh9rZWfz-wORQFxE3elQzLWPQaoK6N6fxQ,1502
61
+ ngio-0.3.4.dist-info/RECORD,,
File without changes