mlarray 0.0.42__tar.gz → 0.0.44__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.
Files changed (43) hide show
  1. {mlarray-0.0.42 → mlarray-0.0.44}/PKG-INFO +1 -1
  2. {mlarray-0.0.42 → mlarray-0.0.44}/examples/example_asarray.py +3 -1
  3. mlarray-0.0.44/examples/example_bboxes_only.py +36 -0
  4. {mlarray-0.0.42 → mlarray-0.0.44}/mlarray/mlarray.py +9 -3
  5. {mlarray-0.0.42 → mlarray-0.0.44}/mlarray.egg-info/PKG-INFO +1 -1
  6. {mlarray-0.0.42 → mlarray-0.0.44}/mlarray.egg-info/SOURCES.txt +1 -0
  7. {mlarray-0.0.42 → mlarray-0.0.44}/.github/workflows/workflow.yml +0 -0
  8. {mlarray-0.0.42 → mlarray-0.0.44}/.gitignore +0 -0
  9. {mlarray-0.0.42 → mlarray-0.0.44}/LICENSE +0 -0
  10. {mlarray-0.0.42 → mlarray-0.0.44}/MANIFEST.in +0 -0
  11. {mlarray-0.0.42 → mlarray-0.0.44}/README.md +0 -0
  12. {mlarray-0.0.42 → mlarray-0.0.44}/assets/banner.png +0 -0
  13. {mlarray-0.0.42 → mlarray-0.0.44}/assets/banner.png~ +0 -0
  14. {mlarray-0.0.42 → mlarray-0.0.44}/docs/api.md +0 -0
  15. {mlarray-0.0.42 → mlarray-0.0.44}/docs/cli.md +0 -0
  16. {mlarray-0.0.42 → mlarray-0.0.44}/docs/index.md +0 -0
  17. {mlarray-0.0.42 → mlarray-0.0.44}/docs/optimization.md +0 -0
  18. {mlarray-0.0.42 → mlarray-0.0.44}/docs/schema.md +0 -0
  19. {mlarray-0.0.42 → mlarray-0.0.44}/docs/usage.md +0 -0
  20. {mlarray-0.0.42 → mlarray-0.0.44}/docs/why.md +0 -0
  21. {mlarray-0.0.42 → mlarray-0.0.44}/examples/example_channel.py +0 -0
  22. {mlarray-0.0.42 → mlarray-0.0.44}/examples/example_metadata_only.py +0 -0
  23. {mlarray-0.0.42 → mlarray-0.0.44}/examples/example_non_spatial.py +0 -0
  24. {mlarray-0.0.42 → mlarray-0.0.44}/examples/example_open.py +0 -0
  25. {mlarray-0.0.42 → mlarray-0.0.44}/examples/example_save_load.py +0 -0
  26. {mlarray-0.0.42 → mlarray-0.0.44}/mkdocs.yml +0 -0
  27. {mlarray-0.0.42 → mlarray-0.0.44}/mlarray/__init__.py +0 -0
  28. {mlarray-0.0.42 → mlarray-0.0.44}/mlarray/cli.py +0 -0
  29. {mlarray-0.0.42 → mlarray-0.0.44}/mlarray/meta.py +0 -0
  30. {mlarray-0.0.42 → mlarray-0.0.44}/mlarray/utils.py +0 -0
  31. {mlarray-0.0.42 → mlarray-0.0.44}/mlarray.egg-info/dependency_links.txt +0 -0
  32. {mlarray-0.0.42 → mlarray-0.0.44}/mlarray.egg-info/entry_points.txt +0 -0
  33. {mlarray-0.0.42 → mlarray-0.0.44}/mlarray.egg-info/requires.txt +0 -0
  34. {mlarray-0.0.42 → mlarray-0.0.44}/mlarray.egg-info/top_level.txt +0 -0
  35. {mlarray-0.0.42 → mlarray-0.0.44}/pyproject.toml +0 -0
  36. {mlarray-0.0.42 → mlarray-0.0.44}/setup.cfg +0 -0
  37. {mlarray-0.0.42 → mlarray-0.0.44}/tests/test_asarray.py +0 -0
  38. {mlarray-0.0.42 → mlarray-0.0.44}/tests/test_bboxes.py +0 -0
  39. {mlarray-0.0.42 → mlarray-0.0.44}/tests/test_create.py +0 -0
  40. {mlarray-0.0.42 → mlarray-0.0.44}/tests/test_metadata.py +0 -0
  41. {mlarray-0.0.42 → mlarray-0.0.44}/tests/test_open.py +0 -0
  42. {mlarray-0.0.42 → mlarray-0.0.44}/tests/test_optimization.py +0 -0
  43. {mlarray-0.0.42 → mlarray-0.0.44}/tests/test_usage.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mlarray
3
- Version: 0.0.42
3
+ Version: 0.0.44
4
4
  Summary: Array format specialized for Machine Learning with Blosc2 backend and standardized metadata.
5
5
  Author-email: Karol Gotkowski <karol.gotkowski@dkfz.de>
6
6
  License: MIT
@@ -1,7 +1,7 @@
1
1
  import gc
2
2
  import os
3
3
  import numpy as np
4
-
4
+ import time
5
5
  from mlarray import MLArray
6
6
 
7
7
 
@@ -68,7 +68,9 @@ if __name__ == "__main__":
68
68
  numpy_bytes = array.nbytes
69
69
 
70
70
  # Convert to in-memory compressed MLArray.
71
+ start_time = time.time()
71
72
  image = MLArray.asarray(array, memory_compressed=True)
73
+ print("MLArray conversion duration: ", time.time() - start_time)
72
74
  rss_after_compressed = get_process_rss_bytes()
73
75
 
74
76
  # Compressed payload size stored by Blosc2 in RAM.
@@ -0,0 +1,36 @@
1
+ import json
2
+ import os
3
+ from pathlib import Path
4
+
5
+ from mlarray import MLArray, Meta, MetaBbox
6
+
7
+
8
+ if __name__ == "__main__":
9
+ filepath = "tmp_metadata_bboxes_only.mla"
10
+
11
+ if Path(filepath).is_file():
12
+ os.remove(filepath)
13
+
14
+ # Five example 3D bounding boxes in [z, y, x] order.
15
+ bboxes = [
16
+ [[12, 28], [40, 75], [55, 90]],
17
+ [[48, 70], [18, 36], [10, 24]],
18
+ [[20, 33], [80, 108], [44, 73]],
19
+ [[72, 95], [52, 81], [88, 118]],
20
+ [[5, 16], [12, 30], [100, 126]],
21
+ ]
22
+ scores = [0.97, 0.84, 0.76, 0.91, 0.68]
23
+ labels = ["tumor", "lymph_node", "lesion", "organ_part", "cyst"]
24
+
25
+ meta = Meta(
26
+ source={"case_id": "case-001", "modality": "CT"},
27
+ bbox=MetaBbox(bboxes=bboxes, scores=scores, labels=labels)
28
+ )
29
+
30
+ # No array data: this MLArray stores metadata only.
31
+ image = MLArray(meta=meta)
32
+ image.save(filepath)
33
+
34
+ loaded = MLArray(filepath)
35
+ print("Saved metadata-only MLArray with 3D bboxes:")
36
+ print(json.dumps(loaded.meta.to_mapping(), indent=2, sort_keys=True))
@@ -64,9 +64,10 @@ class MLArray:
64
64
  else:
65
65
  self._store = array
66
66
  has_array = array is not None
67
- self._validate_and_add_meta(meta, spacing, origin, direction, axis_labels, has_array)
67
+ self._validate_and_add_meta(meta, spacing, origin, direction, axis_labels, has_array, validate=False)
68
68
  if copy is not None:
69
69
  self.meta.copy_from(copy.meta)
70
+ self._validate_and_add_meta(self.meta, validate=True)
70
71
 
71
72
  @classmethod
72
73
  def open(
@@ -1009,12 +1010,16 @@ class MLArray:
1009
1010
  raise NotImplementedError("Chunk and block size optimization based on patch size is only implemented for 2D and 3D spatial images with at most one further non-spatial axis. Please set the chunk and block size manually or set to None for blosc2 to determine a chunk and block size.")
1010
1011
  if patch_size is not None and patch_size != "default" and (chunk_size is not None or block_size is not None):
1011
1012
  raise RuntimeError("patch_size and chunk_size / block_size cannot both be explicitly set.")
1013
+ if (chunk_size is not None and block_size is None) or (chunk_size is None and block_size is not None):
1014
+ raise RuntimeError("If either chunk/block size is used then both must be set.")
1012
1015
 
1013
1016
  if patch_size == "default":
1014
1017
  if meta_blosc2 is not None and meta_blosc2.patch_size is not None: # Use previously loaded patch size, when patch size is not explicitly set and a patch size from a previously loaded image exists
1015
1018
  patch_size = meta_blosc2.patch_size
1016
1019
  else: # Use default patch size, when patch size is not explicitly set and no patch size from a previously loaded image exists
1017
1020
  patch_size = [MLARRAY_DEFAULT_PATCH_SIZE] * num_spatial_axes
1021
+ if chunk_size is not None or block_size is not None:
1022
+ patch_size = None
1018
1023
 
1019
1024
  patch_size = [patch_size] * len(shape) if isinstance(patch_size, int) else patch_size
1020
1025
 
@@ -1056,7 +1061,7 @@ class MLArray:
1056
1061
  raise RuntimeError("Metadata is not serializable.")
1057
1062
  self._store.vlmeta["mlarray"] = metadata
1058
1063
 
1059
- def _validate_and_add_meta(self, meta, spacing=None, origin=None, direction=None, axis_labels=None, has_array=None):
1064
+ def _validate_and_add_meta(self, meta, spacing=None, origin=None, direction=None, axis_labels=None, has_array=None, validate=True):
1060
1065
  """Validate and attach metadata to the MLArray instance.
1061
1066
 
1062
1067
  Args:
@@ -1097,7 +1102,8 @@ class MLArray:
1097
1102
  self.meta._has_array.has_array = True
1098
1103
  if self.meta._has_array.has_array:
1099
1104
  self.meta.spatial.shape = self.shape
1100
- self.meta.spatial._validate_and_cast(ndims=self.ndim, spatial_ndims=self._spatial_ndim)
1105
+ if validate:
1106
+ self.meta.spatial._validate_and_cast(ndims=self.ndim, spatial_ndims=self._spatial_ndim)
1101
1107
 
1102
1108
  def _update_blosc2_meta(self):
1103
1109
  """Sync Blosc2 chunk and block sizes into metadata.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mlarray
3
- Version: 0.0.42
3
+ Version: 0.0.44
4
4
  Summary: Array format specialized for Machine Learning with Blosc2 backend and standardized metadata.
5
5
  Author-email: Karol Gotkowski <karol.gotkowski@dkfz.de>
6
6
  License: MIT
@@ -20,6 +20,7 @@ docs/schema.md
20
20
  docs/usage.md
21
21
  docs/why.md
22
22
  examples/example_asarray.py
23
+ examples/example_bboxes_only.py
23
24
  examples/example_channel.py
24
25
  examples/example_metadata_only.py
25
26
  examples/example_non_spatial.py
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