dicube 0.2.2__cp310-cp310-macosx_11_0_arm64.whl → 0.2.3__cp310-cp310-macosx_11_0_arm64.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.
dicube/__init__.py CHANGED
@@ -64,7 +64,7 @@ def set_num_threads(num_threads: int) -> None:
64
64
  _num_threads = num_threads
65
65
 
66
66
  # Top-level convenience methods
67
- def load(file_path: str) -> DicomCubeImage:
67
+ def load(file_path: str, skip_meta: bool = False) -> DicomCubeImage:
68
68
  """Load a DicomCubeImage from a file.
69
69
 
70
70
  Args:
@@ -73,8 +73,15 @@ def load(file_path: str) -> DicomCubeImage:
73
73
  Returns:
74
74
  DicomCubeImage: The loaded image object.
75
75
  """
76
- return DicomCubeImageIO.load(file_path)
76
+ return DicomCubeImageIO.load(file_path, skip_meta)
77
77
 
78
+ def load_meta(file_path: str) -> DicomMeta:
79
+ """Load the metadata from a file.
80
+
81
+ Args:
82
+ file_path (str): Path to the input file.
83
+ """
84
+ return DicomCubeImageIO.load_meta(file_path)
78
85
 
79
86
  def save(
80
87
  image: DicomCubeImage,
dicube/core/io.py CHANGED
@@ -107,18 +107,13 @@ class DicomCubeImageIO:
107
107
  details={"file_path": file_path, "file_type": file_type}
108
108
  ) from e
109
109
 
110
+
110
111
  @staticmethod
111
- def load(file_path: str) -> 'DicomCubeImage':
112
- """Load DicomCubeImage from a file.
112
+ def _get_reader(file_path: str) -> DcbFile:
113
+ """Get the appropriate reader based on the file path.
113
114
 
114
115
  Args:
115
- file_path (str): Input file path.
116
-
117
- Returns:
118
- DicomCubeImage: The loaded object from the file.
119
-
120
- Raises:
121
- ValueError: When the file format is not supported.
116
+ file_path (str): Path to the input file.
122
117
  """
123
118
  # Validate required parameters
124
119
  validate_not_none(file_path, "file_path", "load operation", InvalidCubeFileError)
@@ -143,9 +138,44 @@ class DicomCubeImageIO:
143
138
  details={"file_path": file_path, "magic_number": magic},
144
139
  suggestion="Ensure the file is a valid DicomCube file"
145
140
  )
141
+ return reader
142
+
143
+ except Exception as e:
144
+ if isinstance(e, (InvalidCubeFileError, CodecError)):
145
+ raise
146
+ raise InvalidCubeFileError(
147
+ f"Failed to load file: {str(e)}",
148
+ context="load operation",
149
+ details={"file_path": file_path}
150
+ ) from e
151
+
152
+ @staticmethod
153
+ def load_meta(file_path: str) -> DicomMeta:
154
+ """Load the metadata from a file.
155
+
156
+ Args:
157
+ file_path (str): Path to the input file.
158
+ """
159
+ reader = DicomCubeImageIO._get_reader(file_path)
160
+ return reader.read_meta()
161
+
162
+ @staticmethod
163
+ def load(file_path: str, skip_meta: bool = False) -> 'DicomCubeImage':
164
+ """Load DicomCubeImage from a file.
165
+
166
+ Args:
167
+ file_path (str): Input file path.
168
+
169
+ Returns:
170
+ DicomCubeImage: The loaded object from the file.
146
171
 
172
+ Raises:
173
+ ValueError: When the file format is not supported.
174
+ """
175
+ reader = DicomCubeImageIO._get_reader(file_path)
176
+ try:
147
177
  # Read file contents
148
- dicom_meta = reader.read_meta()
178
+ dicom_meta = None if skip_meta else reader.read_meta()
149
179
  space = reader.read_space()
150
180
  pixel_header = reader.read_pixel_header()
151
181
  dicom_status = reader.read_dicom_status()
@@ -101,9 +101,9 @@ def _display(meta, show_shared=True, show_non_shared=True):
101
101
  Returns:
102
102
  pandas.DataFrame: Formatted metadata tables.
103
103
  """
104
+
104
105
  import pandas as pd
105
106
  from .dicom_tags import CommonTags
106
-
107
107
  # Prepare shared and non-shared data
108
108
  shared_data = []
109
109
  non_shared_data = {}
@@ -137,7 +137,7 @@ def _display(meta, show_shared=True, show_non_shared=True):
137
137
  # Process each tag
138
138
  for tag_key in meta.keys():
139
139
  tag = Tag(int(tag_key[:4], 16), int(tag_key[4:], 16))
140
- tag_name = datadict.dicom_dict_summary.get(tag, {}).get("name", f"({tag.group:04X},{tag.element:04X})")
140
+ tag_name = datadict.keyword_for_tag(tag)
141
141
  vr = meta.get_vr(tag)
142
142
 
143
143
  if meta.is_shared(tag):
@@ -198,7 +198,7 @@ def _display(meta, show_shared=True, show_non_shared=True):
198
198
  for tag in non_shared_tags
199
199
  }
200
200
  name_row = {
201
- f"({tag.group:04X},{tag.element:04X})": non_shared_data[tag.key]["Name"]
201
+ f"({tag.group:04X},{tag.element:04X})": non_shared_data[get_tag_key(tag)]["Name"]
202
202
  for tag in non_shared_tags
203
203
  }
204
204
 
@@ -206,7 +206,7 @@ def _display(meta, show_shared=True, show_non_shared=True):
206
206
  values_rows = []
207
207
  for idx in range(meta.slice_count):
208
208
  row = {
209
- f"({tag.group:04X},{tag.element:04X})": non_shared_data[tag.key]["Values"][idx]
209
+ f"({tag.group:04X},{tag.element:04X})": non_shared_data[get_tag_key(tag)]["Values"][idx]
210
210
  for tag in non_shared_tags
211
211
  }
212
212
  values_rows.append(row)
@@ -288,8 +288,11 @@ class DicomMeta:
288
288
  # Convert each dataset to a dict representation
289
289
  dicts = []
290
290
  for ds in datasets:
291
- dicts.append(ds.to_json_dict())
292
-
291
+ tmp = ds.to_json_dict(
292
+ bulk_data_threshold=10240, bulk_data_element_handler=lambda x: None
293
+ )
294
+ tmp.pop(get_tag_key(CommonTags.PixelData), None)
295
+ dicts.append(tmp)
293
296
  # Merge the dictionaries
294
297
  merged_data = _merge_dataset_list(dicts)
295
298
  return cls(merged_data, filenames)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: dicube
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Medical Image Storage Library with DICOM compatibility
5
5
  Author: Fangzhou Liao
6
6
  License: MIT
@@ -1,7 +1,4 @@
1
- dicube-0.2.2.dist-info/RECORD,,
2
- dicube-0.2.2.dist-info/WHEEL,sha256=nFSIsNnUJn_8RF-FUhBaXtCep1yHZRCxSkBom4ebATM,114
3
- dicube-0.2.2.dist-info/METADATA,sha256=nBhXpfkqIUhGO2LUB-HmTwmDIolxcvd-cr8tW4CJNzM,10627
4
- dicube/__init__.py,sha256=TK2-JGOB_aPa6ilHw4WUc9l5Whc3Fb-tlZSPzbf5HIw,4886
1
+ dicube/__init__.py,sha256=aXkL9me2X6Msreu30ui2wbdguLV_kqe7UH23nmSFd4E,5125
5
2
  dicube/exceptions.py,sha256=YrwBD93oWI4yhvFfO-SOPCNMQ4z_1FSVL2gCVSnx-LU,6689
6
3
  dicube/validation.py,sha256=Edmx3yKhRShdzvM7uRK6N9j58GNV8rUv_k9w43JcaMs,12478
7
4
  dicube/codecs/__init__.py,sha256=NNus-iAv4JXsNH1kALf5vnLYnESFBoYaN72yJ7kQoqk,3754
@@ -13,7 +10,7 @@ dicube/codecs/jph/ojph_decode_complete.cpython-38-darwin.so,sha256=HHzNB5C3xZ0yh
13
10
  dicube/codecs/jph/ojph_decode_complete.cpython-310-darwin.so,sha256=QGryn2an05KfDHa9-WDSp5Z1MbZFNTO0WEiWxLGEyUY,448968
14
11
  dicube/codecs/jph/ojph_decode_complete.cpython-39-darwin.so,sha256=OMAfYyAQra6xF_Zv5Y-LGBkg68MYpTK4qwB8lWqlf6U,448968
15
12
  dicube/codecs/jph/codec.py,sha256=d4bAoVAatSrWiC1k7gQLzWODZZTGo_1xeRRXO0NAtqo,5460
16
- dicube/core/io.py,sha256=g8uKbcX7zz9LCq65spBeeodZEf6l4HSF9jzl60HZVyw,15629
13
+ dicube/core/io.py,sha256=cR7OrFk7k2lXsUy-Yi9VgkApeOEv7GBtjrX1GSFW12g,16600
17
14
  dicube/core/__init__.py,sha256=tU9vaPHbTkF8V78T8D6werr0nC7k6bMPIlatEIEdHU4,656
18
15
  dicube/core/pixel_header.py,sha256=x3-gNiyL4lFRQ6c1TVdvsm2mG36xCQx78hq4vjYkqJI,4005
19
16
  dicube/core/image.py,sha256=DAyBwKlWeCU6oDWsmdSdAzVW3IieHNLUINIAhS_ZtRg,14177
@@ -22,10 +19,13 @@ dicube/storage/__init__.py,sha256=q36sJqdI9acURBXjOW_g3QiyHw0XLGFCukMsQ-qioZc,46
22
19
  dicube/storage/dcb_file.py,sha256=GfOx2C6fexKojxwzak3_Q0K3gRBHB_UTMNVBY4NPRzg,31232
23
20
  dicube/storage/pixel_utils.py,sha256=-xMMnjSMzYk6WRvLAPktMELhSXJPmLBnt5wxKgOw5zg,9759
24
21
  dicube/dicom/dcb_streaming.py,sha256=Acsdusc6jIKuu1kd-VuDOoteZGdpt3UmwsxF-HQYZtM,9088
25
- dicube/dicom/dicom_meta.py,sha256=Iv-kEcV39vhK2qgSqGpqDhgg28RuUm8ddzSdpToIVPc,26813
22
+ dicube/dicom/dicom_meta.py,sha256=Fvhid95Gu4qqRX9zMDbIDX1t--KIYyIRvfSUQnERGis,26947
26
23
  dicube/dicom/dicom_io.py,sha256=EBa72RGHfifFKygBwCWf6r2YCTNxE9onO8d65ws_5VU,4917
27
24
  dicube/dicom/dicom_status.py,sha256=NXi-sj3mhyaFGfpechewTjhI201vziVsyfLotsLr3Fs,10117
28
25
  dicube/dicom/__init__.py,sha256=9b7liSXx5vlpEYAr59GZGkcUw16kULELTX5SlLfcXPw,371
29
26
  dicube/dicom/merge_utils.py,sha256=6flzoK_6gzpvv4WSTaWq4SjVdr1gh3gtUPMsRfKDSNM,9312
30
27
  dicube/dicom/space_from_meta.py,sha256=__B7UTmvgV1N-LMJg9O_ObHgNWa39mbRF4ZSkQXm3Vs,2420
31
28
  dicube/dicom/dicom_tags.py,sha256=sOjrK9SoAhGqynF0e3YH70j8wbtvwGRezV-tM0wp40Q,3945
29
+ dicube-0.2.3.dist-info/RECORD,,
30
+ dicube-0.2.3.dist-info/WHEEL,sha256=nFSIsNnUJn_8RF-FUhBaXtCep1yHZRCxSkBom4ebATM,114
31
+ dicube-0.2.3.dist-info/METADATA,sha256=NWFpkVhrchy-PksUdnOaC3WnpGb35w7XebMFavyqYF8,10627
File without changes