datamint 1.5.1__tar.gz → 1.5.4__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.

Potentially problematic release.


This version of datamint might be problematic. Click here for more details.

Files changed (28) hide show
  1. {datamint-1.5.1 → datamint-1.5.4}/PKG-INFO +1 -1
  2. {datamint-1.5.1 → datamint-1.5.4}/datamint/apihandler/annotation_api_handler.py +0 -1
  3. {datamint-1.5.1 → datamint-1.5.4}/datamint/utils/io_utils.py +29 -18
  4. {datamint-1.5.1 → datamint-1.5.4}/pyproject.toml +2 -2
  5. {datamint-1.5.1 → datamint-1.5.4}/README.md +0 -0
  6. {datamint-1.5.1 → datamint-1.5.4}/datamint/__init__.py +0 -0
  7. {datamint-1.5.1 → datamint-1.5.4}/datamint/apihandler/api_handler.py +0 -0
  8. {datamint-1.5.1 → datamint-1.5.4}/datamint/apihandler/base_api_handler.py +0 -0
  9. {datamint-1.5.1 → datamint-1.5.4}/datamint/apihandler/dto/annotation_dto.py +0 -0
  10. {datamint-1.5.1 → datamint-1.5.4}/datamint/apihandler/exp_api_handler.py +0 -0
  11. {datamint-1.5.1 → datamint-1.5.4}/datamint/apihandler/root_api_handler.py +0 -0
  12. {datamint-1.5.1 → datamint-1.5.4}/datamint/client_cmd_tools/__init__.py +0 -0
  13. {datamint-1.5.1 → datamint-1.5.4}/datamint/client_cmd_tools/datamint_config.py +0 -0
  14. {datamint-1.5.1 → datamint-1.5.4}/datamint/client_cmd_tools/datamint_upload.py +0 -0
  15. {datamint-1.5.1 → datamint-1.5.4}/datamint/configs.py +0 -0
  16. {datamint-1.5.1 → datamint-1.5.4}/datamint/dataset/__init__.py +0 -0
  17. {datamint-1.5.1 → datamint-1.5.4}/datamint/dataset/base_dataset.py +0 -0
  18. {datamint-1.5.1 → datamint-1.5.4}/datamint/dataset/dataset.py +0 -0
  19. {datamint-1.5.1 → datamint-1.5.4}/datamint/examples/__init__.py +0 -0
  20. {datamint-1.5.1 → datamint-1.5.4}/datamint/examples/example_projects.py +0 -0
  21. {datamint-1.5.1 → datamint-1.5.4}/datamint/experiment/__init__.py +0 -0
  22. {datamint-1.5.1 → datamint-1.5.4}/datamint/experiment/_patcher.py +0 -0
  23. {datamint-1.5.1 → datamint-1.5.4}/datamint/experiment/experiment.py +0 -0
  24. {datamint-1.5.1 → datamint-1.5.4}/datamint/logging.yaml +0 -0
  25. {datamint-1.5.1 → datamint-1.5.4}/datamint/utils/dicom_utils.py +0 -0
  26. {datamint-1.5.1 → datamint-1.5.4}/datamint/utils/logging_utils.py +0 -0
  27. {datamint-1.5.1 → datamint-1.5.4}/datamint/utils/torchmetrics.py +0 -0
  28. {datamint-1.5.1 → datamint-1.5.4}/datamint/utils/visualization.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: datamint
3
- Version: 1.5.1
3
+ Version: 1.5.4
4
4
  Summary: A library for interacting with the Datamint API, designed for efficient data management, processing and Deep Learning workflows.
5
5
  Requires-Python: >=3.10
6
6
  Classifier: Programming Language :: Python :: 3
@@ -221,7 +221,6 @@ class AnnotationAPIHandler(BaseAPIHandler):
221
221
  filename = os.path.basename(file_path)
222
222
  form = aiohttp.FormData()
223
223
  form.add_field('file', f, filename=filename, content_type='application/x-nifti')
224
- model_id = 'c9daf156-5335-4cb3-b374-5b3a776e0025'
225
224
  if model_id is not None:
226
225
  form.add_field('model_id', model_id) # Add model_id if provided
227
226
  if worklist_id is not None:
@@ -53,33 +53,42 @@ def read_video(file_path: str, index: int = None) -> np.ndarray:
53
53
  return imgs
54
54
 
55
55
 
56
- def read_nifti(file_path: str) -> np.ndarray:
56
+ def read_nifti(file_path: str, mimetype: str | None = None) -> np.ndarray:
57
57
  """
58
58
  Read a NIfTI file and return the image data in standardized format.
59
59
 
60
60
  Args:
61
61
  file_path: Path to the NIfTI file (.nii or .nii.gz)
62
+ mimetype: Optional MIME type of the file. If provided, it can help in determining how to read the file.
62
63
 
63
64
  Returns:
64
65
  np.ndarray: Image data with shape (#frames, C, H, W)
65
66
  """
67
+ from nibabel.filebasedimages import ImageFileError
66
68
  try:
67
- nii_img = nib.load(file_path)
68
- imgs = nii_img.get_fdata() # shape: (W, H, #frame) or (W, H)
69
-
70
- if imgs.ndim == 2:
71
- imgs = imgs.transpose(1, 0) # (W, H) -> (H, W)
72
- imgs = imgs[np.newaxis, np.newaxis] # -> (1, 1, H, W)
73
- elif imgs.ndim == 3:
74
- imgs = imgs.transpose(2, 1, 0) # (W, H, #frame) -> (#frame, H, W)
75
- imgs = imgs[:, np.newaxis] # -> (#frame, 1, H, W)
69
+ imgs = nib.load(file_path).get_fdata() # shape: (W, H, #frame) or (W, H)
70
+ except ImageFileError as e:
71
+ if mimetype is None:
72
+ raise e
73
+ # has_ext = os.path.splitext(file_path)[1] != ''
74
+ if mimetype == 'application/gzip':
75
+ with gzip.open(file_path, 'rb') as f:
76
+ imgs = nib.Nifti1Image.from_stream(f).get_fdata()
77
+ elif mimetype in ('image/x.nifti', 'application/x-nifti'):
78
+ with open(file_path, 'rb') as f:
79
+ imgs = nib.Nifti1Image.from_stream(f).get_fdata()
76
80
  else:
77
- raise ValueError(f"Unsupported number of dimensions in '{file_path}': {imgs.ndim}")
81
+ raise e
82
+ if imgs.ndim == 2:
83
+ imgs = imgs.transpose(1, 0)
84
+ imgs = imgs[np.newaxis, np.newaxis]
85
+ elif imgs.ndim == 3:
86
+ imgs = imgs.transpose(2, 1, 0)
87
+ imgs = imgs[:, np.newaxis]
88
+ else:
89
+ raise ValueError(f"Unsupported number of dimensions in '{file_path}': {imgs.ndim}")
78
90
 
79
- return imgs
80
- except Exception as e:
81
- _LOGGER.error(f"Failed to read NIfTI file '{file_path}': {e}")
82
- raise e
91
+ return imgs
83
92
 
84
93
 
85
94
  def read_image(file_path: str) -> np.ndarray:
@@ -94,7 +103,7 @@ def read_image(file_path: str) -> np.ndarray:
94
103
 
95
104
 
96
105
  def read_array_normalized(file_path: str,
97
- index: int = None,
106
+ index: int | None = None,
98
107
  return_metainfo: bool = False,
99
108
  use_magic=False) -> np.ndarray | tuple[np.ndarray, Any]:
100
109
  """
@@ -102,6 +111,8 @@ def read_array_normalized(file_path: str,
102
111
 
103
112
  Args:
104
113
  file_path: The path to the file.
114
+ index: If specified, read only the frame at this index (0-based).
115
+ If None, read all frames.
105
116
  Supported file formats are NIfTI (.nii, .nii.gz), PNG (.png), JPEG (.jpg, .jpeg) and npy (.npy).
106
117
 
107
118
  Returns:
@@ -136,8 +147,8 @@ def read_array_normalized(file_path: str,
136
147
  if mime_type.startswith('video/') or file_path.endswith(VIDEO_EXTS):
137
148
  imgs = read_video(file_path, index)
138
149
  else:
139
- if mime_type == 'image/x.nifti' or file_path.endswith(NII_EXTS):
140
- imgs = read_nifti(file_path)
150
+ if mime_type in ('image/x.nifti', 'application/x-nifti') or mime_type == 'application/gzip' or file_path.endswith(NII_EXTS):
151
+ imgs = read_nifti(file_path, mimetype=mime_type)
141
152
  # For NIfTI files, try to load associated JSON metadata
142
153
  if return_metainfo:
143
154
  json_path = file_path.replace('.nii.gz', '.json').replace('.nii', '.json')
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "datamint"
3
3
  description = "A library for interacting with the Datamint API, designed for efficient data management, processing and Deep Learning workflows."
4
- version = "1.5.1"
4
+ version = "1.5.4"
5
5
  dynamic = ["dependencies"]
6
6
  requires-python = ">=3.10"
7
7
  readme = "README.md"
@@ -66,6 +66,6 @@ docs = ["sphinx", "sphinx_rtd_theme", "sphinx-tabs", "setuptools"]
66
66
  dev = ["pytest", "pytest-cov", "responses", "aioresponses"]
67
67
 
68
68
  [build-system]
69
- requires = ["poetry-core>=2.0.0"]
69
+ requires = ["poetry-core>=1.0.0"]
70
70
  build-backend = "poetry.core.masonry.api"
71
71
 
File without changes
File without changes
File without changes
File without changes