mirp 2.2.1__tar.gz → 2.2.3__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 (112) hide show
  1. {mirp-2.2.1 → mirp-2.2.3}/NEWS.md +38 -0
  2. {mirp-2.2.1 → mirp-2.2.3}/PKG-INFO +3 -3
  3. {mirp-2.2.1 → mirp-2.2.3}/README.md +2 -2
  4. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/dicom_file.py +112 -18
  5. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/dicom_file_pet.py +74 -39
  6. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/dicom_file_rtdose.py +12 -8
  7. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/dicom_file_rtstruct.py +32 -26
  8. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/dicom_file_seg.py +43 -34
  9. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/dicom_file_stack.py +36 -4
  10. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/generic_file.py +170 -50
  11. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/generic_file_stack.py +13 -6
  12. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/itk_file.py +27 -5
  13. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/itk_file_stack.py +8 -4
  14. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/numpy_file.py +20 -9
  15. {mirp-2.2.1 → mirp-2.2.3}/mirp/_featuresets/morphology_3d.py +7 -9
  16. {mirp-2.2.1 → mirp-2.2.3}/mirp/_images/base_image.py +16 -0
  17. {mirp-2.2.1 → mirp-2.2.3}/mirp/_images/generic_image.py +5 -0
  18. {mirp-2.2.1 → mirp-2.2.3}/mirp/_images/utilities.py +14 -1
  19. {mirp-2.2.1 → mirp-2.2.3}/mirp/_masks/base_mask.py +16 -0
  20. {mirp-2.2.1 → mirp-2.2.3}/mirp/_workflows/standardWorkflow.py +52 -20
  21. {mirp-2.2.1 → mirp-2.2.3}/mirp/config_settings.xml +15 -15
  22. {mirp-2.2.1 → mirp-2.2.3}/mirp/deep_learning_preprocessing.py +4 -4
  23. {mirp-2.2.1 → mirp-2.2.3}/mirp/extract_features_and_images.py +162 -12
  24. {mirp-2.2.1 → mirp-2.2.3}/mirp/settings/image_processing_parameters.py +1 -1
  25. {mirp-2.2.1 → mirp-2.2.3}/mirp/settings/import_config_parameters.py +9 -9
  26. {mirp-2.2.1 → mirp-2.2.3}/mirp/settings/resegmentation_parameters.py +0 -2
  27. {mirp-2.2.1 → mirp-2.2.3}/mirp/settings/utilities.py +18 -0
  28. {mirp-2.2.1 → mirp-2.2.3}/mirp.egg-info/PKG-INFO +3 -3
  29. {mirp-2.2.1 → mirp-2.2.3}/pyproject.toml +4 -1
  30. {mirp-2.2.1 → mirp-2.2.3}/CONTRIBUTING.md +0 -0
  31. {mirp-2.2.1 → mirp-2.2.3}/LICENSE.txt +0 -0
  32. {mirp-2.2.1 → mirp-2.2.3}/MANIFEST.in +0 -0
  33. {mirp-2.2.1 → mirp-2.2.3}/mirp/__init__.py +0 -0
  34. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/__init__.py +0 -0
  35. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/dicom_file_ct.py +0 -0
  36. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/dicom_file_mr.py +0 -0
  37. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/directory.py +0 -0
  38. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/mask_contour.py +0 -0
  39. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/numpy_file_stack.py +0 -0
  40. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/read_data.py +0 -0
  41. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/suv.py +0 -0
  42. {mirp-2.2.1 → mirp-2.2.3}/mirp/_data_import/utilities.py +0 -0
  43. {mirp-2.2.1 → mirp-2.2.3}/mirp/_featuresets/__init__.py +0 -0
  44. {mirp-2.2.1 → mirp-2.2.3}/mirp/_featuresets/cm.py +0 -0
  45. {mirp-2.2.1 → mirp-2.2.3}/mirp/_featuresets/dzm.py +0 -0
  46. {mirp-2.2.1 → mirp-2.2.3}/mirp/_featuresets/intensity_histogram.py +0 -0
  47. {mirp-2.2.1 → mirp-2.2.3}/mirp/_featuresets/intensity_volume_histogram.py +0 -0
  48. {mirp-2.2.1 → mirp-2.2.3}/mirp/_featuresets/local_intensity.py +0 -0
  49. {mirp-2.2.1 → mirp-2.2.3}/mirp/_featuresets/ngldm.py +0 -0
  50. {mirp-2.2.1 → mirp-2.2.3}/mirp/_featuresets/ngtdm.py +0 -0
  51. {mirp-2.2.1 → mirp-2.2.3}/mirp/_featuresets/rlm.py +0 -0
  52. {mirp-2.2.1 → mirp-2.2.3}/mirp/_featuresets/statistics.py +0 -0
  53. {mirp-2.2.1 → mirp-2.2.3}/mirp/_featuresets/szm.py +0 -0
  54. {mirp-2.2.1 → mirp-2.2.3}/mirp/_featuresets/utilities.py +0 -0
  55. {mirp-2.2.1 → mirp-2.2.3}/mirp/_image_processing/__init__.py +0 -0
  56. {mirp-2.2.1 → mirp-2.2.3}/mirp/_image_processing/alter_mask.py +0 -0
  57. {mirp-2.2.1 → mirp-2.2.3}/mirp/_image_processing/anti_aliasing.py +0 -0
  58. {mirp-2.2.1 → mirp-2.2.3}/mirp/_image_processing/cropping.py +0 -0
  59. {mirp-2.2.1 → mirp-2.2.3}/mirp/_image_processing/discretise_image.py +0 -0
  60. {mirp-2.2.1 → mirp-2.2.3}/mirp/_image_processing/randomise_mask.py +0 -0
  61. {mirp-2.2.1 → mirp-2.2.3}/mirp/_image_processing/split_mask.py +0 -0
  62. {mirp-2.2.1 → mirp-2.2.3}/mirp/_image_processing/tissue_mask.py +0 -0
  63. {mirp-2.2.1 → mirp-2.2.3}/mirp/_image_processing/utilities.py +0 -0
  64. {mirp-2.2.1 → mirp-2.2.3}/mirp/_imagefilters/__init__.py +0 -0
  65. {mirp-2.2.1 → mirp-2.2.3}/mirp/_imagefilters/exponential_transform.py +0 -0
  66. {mirp-2.2.1 → mirp-2.2.3}/mirp/_imagefilters/gabor.py +0 -0
  67. {mirp-2.2.1 → mirp-2.2.3}/mirp/_imagefilters/gaussian.py +0 -0
  68. {mirp-2.2.1 → mirp-2.2.3}/mirp/_imagefilters/generic.py +0 -0
  69. {mirp-2.2.1 → mirp-2.2.3}/mirp/_imagefilters/laplacian_of_gaussian.py +0 -0
  70. {mirp-2.2.1 → mirp-2.2.3}/mirp/_imagefilters/laws.py +0 -0
  71. {mirp-2.2.1 → mirp-2.2.3}/mirp/_imagefilters/log_transform.py +0 -0
  72. {mirp-2.2.1 → mirp-2.2.3}/mirp/_imagefilters/mean.py +0 -0
  73. {mirp-2.2.1 → mirp-2.2.3}/mirp/_imagefilters/nonseparable_wavelet.py +0 -0
  74. {mirp-2.2.1 → mirp-2.2.3}/mirp/_imagefilters/separable_wavelet.py +0 -0
  75. {mirp-2.2.1 → mirp-2.2.3}/mirp/_imagefilters/square_root_transform.py +0 -0
  76. {mirp-2.2.1 → mirp-2.2.3}/mirp/_imagefilters/square_transform.py +0 -0
  77. {mirp-2.2.1 → mirp-2.2.3}/mirp/_imagefilters/utilities.py +0 -0
  78. {mirp-2.2.1 → mirp-2.2.3}/mirp/_images/__init__.py +0 -0
  79. {mirp-2.2.1 → mirp-2.2.3}/mirp/_images/ct_image.py +0 -0
  80. {mirp-2.2.1 → mirp-2.2.3}/mirp/_images/mask_image.py +0 -0
  81. {mirp-2.2.1 → mirp-2.2.3}/mirp/_images/mr_image.py +0 -0
  82. {mirp-2.2.1 → mirp-2.2.3}/mirp/_images/pet_image.py +0 -0
  83. {mirp-2.2.1 → mirp-2.2.3}/mirp/_images/rtdose_image.py +0 -0
  84. {mirp-2.2.1 → mirp-2.2.3}/mirp/_images/transformed_image.py +0 -0
  85. {mirp-2.2.1 → mirp-2.2.3}/mirp/_masks/__init__.py +0 -0
  86. {mirp-2.2.1 → mirp-2.2.3}/mirp/_workflows/__init__.py +0 -0
  87. {mirp-2.2.1 → mirp-2.2.3}/mirp/_workflows/baseWorkflow.py +0 -0
  88. {mirp-2.2.1 → mirp-2.2.3}/mirp/config_data.xml +0 -0
  89. {mirp-2.2.1 → mirp-2.2.3}/mirp/data_import/__init__.py +0 -0
  90. {mirp-2.2.1 → mirp-2.2.3}/mirp/data_import/import_image.py +0 -0
  91. {mirp-2.2.1 → mirp-2.2.3}/mirp/data_import/import_image_and_mask.py +0 -0
  92. {mirp-2.2.1 → mirp-2.2.3}/mirp/data_import/import_mask.py +0 -0
  93. {mirp-2.2.1 → mirp-2.2.3}/mirp/deprecated.py +0 -0
  94. {mirp-2.2.1 → mirp-2.2.3}/mirp/extract_image_parameters.py +0 -0
  95. {mirp-2.2.1 → mirp-2.2.3}/mirp/extract_mask_labels.py +0 -0
  96. {mirp-2.2.1 → mirp-2.2.3}/mirp/settings/__init__.py +0 -0
  97. {mirp-2.2.1 → mirp-2.2.3}/mirp/settings/feature_parameters.py +0 -0
  98. {mirp-2.2.1 → mirp-2.2.3}/mirp/settings/general_parameters.py +0 -0
  99. {mirp-2.2.1 → mirp-2.2.3}/mirp/settings/generic.py +0 -0
  100. {mirp-2.2.1 → mirp-2.2.3}/mirp/settings/import_data_parameters.py +0 -0
  101. {mirp-2.2.1 → mirp-2.2.3}/mirp/settings/interpolation_parameters.py +0 -0
  102. {mirp-2.2.1 → mirp-2.2.3}/mirp/settings/perturbation_parameters.py +0 -0
  103. {mirp-2.2.1 → mirp-2.2.3}/mirp/settings/transformation_parameters.py +0 -0
  104. {mirp-2.2.1 → mirp-2.2.3}/mirp/utilities/__init__.py +0 -0
  105. {mirp-2.2.1 → mirp-2.2.3}/mirp/utilities/config_utilities.py +0 -0
  106. {mirp-2.2.1 → mirp-2.2.3}/mirp/utilities/parallel.py +0 -0
  107. {mirp-2.2.1 → mirp-2.2.3}/mirp/utilities/utilities.py +0 -0
  108. {mirp-2.2.1 → mirp-2.2.3}/mirp.egg-info/SOURCES.txt +0 -0
  109. {mirp-2.2.1 → mirp-2.2.3}/mirp.egg-info/dependency_links.txt +0 -0
  110. {mirp-2.2.1 → mirp-2.2.3}/mirp.egg-info/requires.txt +0 -0
  111. {mirp-2.2.1 → mirp-2.2.3}/mirp.egg-info/top_level.txt +0 -0
  112. {mirp-2.2.1 → mirp-2.2.3}/setup.cfg +0 -0
@@ -1,3 +1,41 @@
1
+ # Version 2.2.3
2
+
3
+ ## Minor changes
4
+
5
+ - Tables with feature values now contain extra columns. These columns specify the file name (for non-DICOM input),
6
+ the directory path of the image and masks and several DICOM tags for identifying the input.
7
+
8
+ - MIRP now checks whether there are potential problems between the frames of reference of image and mask files.
9
+
10
+ # Fixes
11
+
12
+ - Fixed an error that occurs when attempting to create a deep copy `ImageITKFile` objects.
13
+
14
+ # Version 2.2.2
15
+
16
+ ## Minor changes
17
+
18
+ - `show` method of `GenericImage` and subclasses now indicate if a user-provided `slice_id` is out-of-volume and
19
+ select the nearest slice instead.
20
+
21
+ - Naming of branches in the settings `xml` file now matches that of their respective settings classes. `xml` files
22
+ with the previous branch names still function.
23
+
24
+ - Errors encountered during file import and handling are now more descriptive.
25
+ - `extract_mask_labels` and `extract_image_parameters` now export extra information from DICOM metadata, e.g. series
26
+ UID.
27
+
28
+ ## Documentation
29
+
30
+ - Added a new tutorial on applying image filters to images.
31
+ - Added documentation on the feature naming system.
32
+ - Added documentation on the design of MIRP.
33
+
34
+ ## Fixes
35
+
36
+ - Computing features related to the minimum volume enclosing ellipsoid no longer produces warnings due to the use of
37
+ deprecated `numpy.matrix` class.
38
+
1
39
  # Version 2.2.1
2
40
 
3
41
  ## Minor changes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mirp
3
- Version: 2.2.1
3
+ Version: 2.2.3
4
4
  Summary: A package for standardised processing of medical imaging and computation of quantitative features.
5
5
  Author-email: Alex Zwanenburg <alexander.zwanenburg@nct-dresden.de>
6
6
  License: European Union Public Licence
@@ -354,8 +354,8 @@ pip install mirp
354
354
 
355
355
  MIRP can be used to compute quantitative features from regions of interest in images in an IBSI-compliant manner
356
356
  using a standardized workflow This requires both images and masks. MIRP can process DICOM, NIfTI, NRRD and numpy
357
- images. Masks are DICOM radiotherapy structure sets (RTSTRUCT), or volumetric data with integer labels (e.g. 1, 2,
358
- etc.).
357
+ images. Masks are DICOM radiotherapy structure sets (RTSTRUCT), DICOM segmentation (SEG) or volumetric data with
358
+ integer labels (e.g. 1, 2, etc.).
359
359
 
360
360
  Below is a minimal working example for extracting features from a single image file and its mask.
361
361
 
@@ -44,8 +44,8 @@ pip install mirp
44
44
 
45
45
  MIRP can be used to compute quantitative features from regions of interest in images in an IBSI-compliant manner
46
46
  using a standardized workflow This requires both images and masks. MIRP can process DICOM, NIfTI, NRRD and numpy
47
- images. Masks are DICOM radiotherapy structure sets (RTSTRUCT), or volumetric data with integer labels (e.g. 1, 2,
48
- etc.).
47
+ images. Masks are DICOM radiotherapy structure sets (RTSTRUCT), DICOM segmentation (SEG) or volumetric data with
48
+ integer labels (e.g. 1, 2, etc.).
49
49
 
50
50
  Below is a minimal working example for extracting features from a single image file and its mask.
51
51
 
@@ -107,8 +107,10 @@ class ImageDicomFile(ImageFile):
107
107
  if dicom_modality.lower() not in support_modalities:
108
108
  if raise_error:
109
109
  raise ValueError(
110
- f"The current DICOM file {self.file_path} does not have the expected modality. "
111
- f"Found: {dicom_modality.lower()}. Expected: {', '.join(support_modalities)}")
110
+ f"The current DICOM file does not have the expected modality. "
111
+ f"Found: {dicom_modality.lower()}. Expected: one of {', '.join(support_modalities)}. "
112
+ f"[{self.describe_self()}]"
113
+ )
112
114
 
113
115
  return False
114
116
 
@@ -140,9 +142,10 @@ class ImageDicomFile(ImageFile):
140
142
  if len(matching_sample_name) == 0:
141
143
  if raise_error:
142
144
  raise ValueError(
143
- f"The current DICOM file {self.file_path} does not have a matching sample name among "
144
- f"potential identifiers. Potential identifiers: {', '.join(dicom_sample_name)}; "
145
- f"Expected identifiers: {', '.join(allowed_sample_name)}."
145
+ f"The current DICOM file does not have a matching sample name among potential identifiers. "
146
+ f"Potential identifiers: {', '.join(dicom_sample_name)}; "
147
+ f"Expected identifiers: {', '.join(allowed_sample_name)}. "
148
+ f"[{self.describe_self()}]"
146
149
  )
147
150
  else:
148
151
  return False
@@ -169,7 +172,7 @@ class ImageDicomFile(ImageFile):
169
172
  modality = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0008, 0x0060), tag_type="str").lower()
170
173
 
171
174
  if modality is None:
172
- raise TypeError(f"Modality attribute could not be obtained from DICOM file ({self.file_path})")
175
+ raise TypeError(f"Modality attribute could not be obtained from DICOM file. [{self.describe_self()}]")
173
176
 
174
177
  if modality == "ct":
175
178
  file_class = ImageDicomFileCT
@@ -212,7 +215,11 @@ class ImageDicomFile(ImageFile):
212
215
  # Set SOP instance UID.
213
216
  if self.sop_instance_uid is None:
214
217
  self.load_metadata(limited=True)
215
- self.sop_instance_uid = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0008, 0x0018), tag_type="str")
218
+ self.sop_instance_uid = get_pydicom_meta_tag(
219
+ dcm_seq=self.image_metadata,
220
+ tag=(0x0008, 0x0018),
221
+ tag_type="str"
222
+ )
216
223
 
217
224
  # Set Frame of Reference UID (if any)
218
225
  self._complete_frame_of_reference_uid()
@@ -220,7 +227,11 @@ class ImageDicomFile(ImageFile):
220
227
  # Set series UID
221
228
  if self.series_instance_uid is None:
222
229
  self.load_metadata(limited=True)
223
- self.series_instance_uid = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0020, 0x000E), tag_type="str")
230
+ self.series_instance_uid = get_pydicom_meta_tag(
231
+ dcm_seq=self.image_metadata,
232
+ tag=(0x0020, 0x000E),
233
+ tag_type="str"
234
+ )
224
235
 
225
236
  if remove_metadata:
226
237
  self.remove_metadata()
@@ -231,7 +242,7 @@ class ImageDicomFile(ImageFile):
231
242
  self.modality = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0008, 0x0060), tag_type="str")
232
243
 
233
244
  if self.modality is None:
234
- warn(f"Could not ascertain the modality from the DICOM file ({self.file_path}).", UserWarning)
245
+ warn(f"Could not ascertain the modality from the DICOM file. [{self.describe_self()}]", UserWarning)
235
246
 
236
247
  self.modality = "generic"
237
248
  else:
@@ -385,7 +396,8 @@ class ImageDicomFile(ImageFile):
385
396
 
386
397
  if self.file_path is None or not os.path.exists(self.file_path):
387
398
  raise FileNotFoundError(
388
- f"The image file could not be found at the expected location: {self.file_path}")
399
+ f"The image file could not be found at the expected location: {self.file_path}. "
400
+ f"[{self.describe_self()}]")
389
401
 
390
402
  if limited:
391
403
  dcm = dcmread(
@@ -420,11 +432,11 @@ class ImageDicomFile(ImageFile):
420
432
 
421
433
  if self.file_path is not None and not os.path.exists(self.file_path):
422
434
  raise FileNotFoundError(
423
- f"The image file could not be found at the expected location: {self.file_path}"
435
+ f"The image file could not be found at the expected location: {self.file_path}. [{self.describe_self()}]"
424
436
  )
425
437
 
426
438
  if self.file_path is None:
427
- raise ValueError(f"A path to a file was expected, but not present.")
439
+ raise ValueError(f"A path to a file was expected, but not present. [{self.describe_self()}]")
428
440
 
429
441
  # Load metadata.
430
442
  self.load_metadata(include_image=True)
@@ -437,14 +449,61 @@ class ImageDicomFile(ImageFile):
437
449
 
438
450
  return image_data
439
451
 
452
+ def set_object_metadata(self):
453
+ """
454
+ Updates the object metadata that is passed to native image and mask classes in to_object.
455
+ """
456
+ metadata = []
457
+ super().set_object_metadata()
458
+
459
+ # Ensure that metadata are present.
460
+ self.load_metadata(limited=False)
461
+
462
+ # Study date
463
+ study_date = get_pydicom_meta_tag(
464
+ dcm_seq=self.image_metadata,
465
+ tag=(0x0008, 0x0020),
466
+ tag_type="str"
467
+ )
468
+
469
+ if study_date is not None and not study_date == "":
470
+ metadata += [("study_date", study_date)]
471
+
472
+ # Study description
473
+ study_description = get_pydicom_meta_tag(
474
+ dcm_seq=self.image_metadata,
475
+ tag=(0x0008, 0x1030),
476
+ tag_type="str"
477
+ )
478
+
479
+ if study_description is not None and not study_description == "":
480
+ metadata += [("study_description", study_description)]
481
+
482
+ # Series description
483
+ series_description = get_pydicom_meta_tag(
484
+ dcm_seq=self.image_metadata,
485
+ tag=(0x0008, 0x103E),
486
+ tag_type="str"
487
+ )
488
+
489
+ if series_description is not None and not series_description == "":
490
+ metadata += [("series_description", series_description)]
491
+
492
+ # Series instance UID
493
+ if self.series_instance_uid is not None:
494
+ metadata += [("series_instance_uid", self.series_instance_uid)]
495
+
496
+ # Update object_metadata
497
+ self.object_metadata.update(dict(metadata))
498
+
440
499
  @staticmethod
441
500
  def _get_limited_metadata_tags():
442
501
  # Limited tags are read to populate basic
443
502
  return [
444
503
  (0x0008, 0x0018), # SOP instance UID
445
504
  (0x0008, 0x0060), # modality
446
- (0x0008, 0x1030), # series description
447
- (0x0008, 0x103E), # study description
505
+ (0x0008, 0x1030), # study description
506
+ (0x0008, 0x103E), # series description
448
507
  (0x0010, 0x0010), # patient name
449
508
  (0x0010, 0x0020), # patient id
450
509
  (0x0018, 0x0050), # slice thickness
@@ -516,10 +575,42 @@ class ImageDicomFile(ImageFile):
516
575
 
517
576
  # Final check.
518
577
  if acquisition_ref_time is None:
519
- raise ValueError(f"Acquisition start time cannot be determined from DICOM metadata in {self.file_path}.")
578
+ raise ValueError(
579
+ f"Acquisition start time cannot be determined from DICOM metadata."
580
+ )
520
581
 
521
582
  return acquisition_ref_time
522
583
 
584
+ def _get_export_attributes(self) -> dict[str, Any]:
585
+ attributes = []
586
+ self.load_metadata()
587
+
588
+ study_description = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0008, 0x1030), tag_type="str")
589
+ if study_description is not None and study_description != "":
590
+ attributes += [("study_description", study_description)]
591
+
592
+ series_description = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0008, 0x103E), tag_type="str")
593
+ if series_description is not None and series_description != "":
594
+ attributes += [("series_description", series_description)]
595
+
596
+ # Try to find the acquisition time (which may be equal to series time).
597
+ try:
598
+ acquisition_time = self._get_acquisition_start_time()
599
+ except ValueError:
600
+ acquisition_time = None
601
+ if acquisition_time is not None:
602
+ attributes += [("acquisition_time", acquisition_time)]
603
+
604
+ if self.series_instance_uid is not None:
605
+ attributes += [("series_instance_uid", self.series_instance_uid)]
606
+ if self.frame_of_reference_uid is not None:
607
+ attributes += [("frame_of_reference_uid", self.frame_of_reference_uid)]
608
+
609
+ parent_attributes = super()._get_export_attributes()
610
+ parent_attributes.update(dict(attributes))
611
+
612
+ return parent_attributes
613
+
523
614
 
524
615
  class MaskDicomFile(ImageDicomFile, MaskFile):
525
616
  def __init__(self, **kwargs):
@@ -531,8 +622,11 @@ class MaskDicomFile(ImageDicomFile, MaskFile):
531
622
  if dicom_modality.lower() not in support_modalities:
532
623
  if raise_error:
533
624
  raise ValueError(
534
- f"The current DICOM file {self.file_path} does not have the expected modality. "
535
- f"Found: {dicom_modality.lower()}. Expected: {', '.join(support_modalities)}")
625
+ f"The current DICOM file does not have the expected modality. "
626
+ f"Found: {dicom_modality.lower()}. "
627
+ f"Expected: {', '.join(support_modalities)}. "
628
+ f"[{self.describe_self()}]"
629
+ )
536
630
 
537
631
  return False
538
632
 
@@ -561,7 +655,7 @@ class MaskDicomFile(ImageDicomFile, MaskFile):
561
655
  modality = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0008, 0x0060), tag_type="str").lower()
562
656
 
563
657
  if modality is None:
564
- raise TypeError(f"Modality attribute could not be obtained from DICOM file ({self.file_path})")
658
+ raise TypeError(f"Modality attribute could not be obtained from the DICOM file. [{self.describe_self()}]")
565
659
 
566
660
  if modality == "rtstruct":
567
661
  file_class = MaskDicomFileRTSTRUCT
@@ -53,28 +53,47 @@ class ImageDicomFilePT(ImageDicomFile):
53
53
  ):
54
54
  image_data = self.load_data_generic()
55
55
 
56
+ conversion_possible = True
56
57
  # Get decay correction factor
57
58
  try:
58
59
  decay_factor = self._get_administration_decay_factor()
59
60
  except ValueError as err:
60
61
  warnings.warn(
61
- f"Decay correction factor could not be determined. {str(err)}",
62
+ f"SUV cannot be computed as decay correction factor could not be determined. {str(err)}",
62
63
  UserWarning
63
64
  )
65
+ conversion_possible = False
64
66
  decay_factor = 1.0
65
67
 
66
68
  # Get conversion factor to BQML
67
69
  try:
68
70
  bqml_factor = self._get_pet_unit_conversion_factor()
69
71
  except ValueError as err:
70
- warnings.warn(
71
- f"BQML conversion factor could not be determined. {str(err)}",
72
- UserWarning
73
- )
72
+ if pet_suv_conversion != "none":
73
+ warnings.warn(
74
+ f"SUV cannot be computed. BQML conversion factor could not be determined. {str(err)}",
75
+ UserWarning
76
+ )
77
+ conversion_possible = False
78
+ bqml_factor = 1.0
79
+
80
+ except NotImplementedError as err:
81
+ if pet_suv_conversion != "none":
82
+ warnings.warn(
83
+ f"SUV cannot be computed. BQML conversion factor could not be determined. {str(err)}",
84
+ UserWarning
85
+ )
86
+ conversion_possible = False
74
87
  bqml_factor = 1.0
75
88
 
76
- # Get SUV conversion factor.
77
- suv_factor = self._get_suv_conversion_factor(new_suv_type=pet_suv_conversion)
89
+ # Get SUV conversion factor and update the object_metadata attribute.
90
+ if conversion_possible:
91
+ suv_factor = self._get_suv_conversion_factor(new_suv_type=pet_suv_conversion)
92
+ self.object_metadata.update(dict([("suv_type", pet_suv_conversion)]))
93
+
94
+ else:
95
+ suv_factor = 1.0
96
+ self.object_metadata.update(dict([("suv_type", "none")]))
78
97
 
79
98
  # Update image_data
80
99
  image_data *= decay_factor * bqml_factor * suv_factor
@@ -461,7 +480,7 @@ class ImageDicomFilePT(ImageDicomFile):
461
480
  # Final check.
462
481
  if admin_ref_time is None:
463
482
  raise ValueError(
464
- f"Radiopharmaceutical start time cannot be determined from DICOM metadata in {self.file_path}."
483
+ f"Radiopharmaceutical start time cannot be determined from DICOM metadata. [{self.describe_self()}]"
465
484
  )
466
485
 
467
486
  return admin_ref_time
@@ -481,8 +500,8 @@ class ImageDicomFilePT(ImageDicomFile):
481
500
 
482
501
  elif decay_correction not in ["NONE", "START"]:
483
502
  raise ValueError(
484
- f"Decay correction DICOM tag in {self.file_path} was not recognised: {decay_correction}. One of ",
485
- f"NONE, START or ADMIN was expected."
503
+ f"Decay correction DICOM tag was not recognised: {decay_correction}. One of ",
504
+ f"NONE, START or ADMIN was expected. [{self.describe_self()}]"
486
505
  )
487
506
 
488
507
  # Get acquisition start time and tracer administration time.
@@ -492,7 +511,7 @@ class ImageDicomFilePT(ImageDicomFile):
492
511
  # Get frame duration in seconds.
493
512
  frame_duration = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0018, 0x1242), tag_type="float")
494
513
  if frame_duration is None:
495
- raise ValueError(f"Frame duration cannot be determined from DICOM metadata in {self.file_path}.")
514
+ raise ValueError(f"Frame duration cannot be determined from DICOM metadata. [{self.describe_self()}]")
496
515
  frame_duration /= 1000.0 # From milliseconds to seconds.
497
516
 
498
517
  # Radionuclide total dose and radionuclide half-life
@@ -507,7 +526,7 @@ class ImageDicomFilePT(ImageDicomFile):
507
526
  if half_life is None:
508
527
  raise ValueError(
509
528
  f"Radionuclide half-life (0x0018, 0x1075) was missing in the Radiopharmaceutical "
510
- f"information sequence (0x0054, 0x0016) of {self.file_path}."
529
+ f"information sequence (0x0054, 0x0016). [{self.describe_self()}]"
511
530
  )
512
531
 
513
532
  # Decay constant.
@@ -532,16 +551,24 @@ class ImageDicomFilePT(ImageDicomFile):
532
551
  # vendorneutral pseudocode.
533
552
 
534
553
  # Get frame_reference_time in seconds.
535
- frame_reference_time = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0054, 0x1300), tag_type="float")
554
+ frame_reference_time = get_pydicom_meta_tag(
555
+ dcm_seq=self.image_metadata,
556
+ tag=(0x0054, 0x1300),
557
+ tag_type="float"
558
+ )
536
559
  if frame_reference_time is None:
537
- raise ValueError(f"Frame reference time (0x0054, 0x1300) was missing in {self.file_path}.")
560
+ raise ValueError(f"Frame reference time (0x0054, 0x1300) was missing. [{self.describe_self()}]")
538
561
  frame_reference_time /= 1000.0
539
562
 
540
563
  # Time at which the average count rate is found, relative to acquisition start time.
541
- time_count_average = 1.0 / _lambda * np.log(_lambda * frame_duration / (1.0 - np.exp(-_lambda * frame_duration)))
564
+ time_count_average = 1.0 / _lambda * np.log(
565
+ _lambda * frame_duration / (1.0 - np.exp(-_lambda * frame_duration))
566
+ )
542
567
 
543
568
  # Set reference start time (this may coincide with the acquisition start time).
544
- reference_start_time = acquisition_start_time + datetime.timedelta(seconds=time_count_average - frame_reference_time)
569
+ reference_start_time = acquisition_start_time + datetime.timedelta(
570
+ seconds=time_count_average - frame_reference_time
571
+ )
545
572
  time_to_reference_start = reference_start_time - tracer_administration_time
546
573
  time_to_reference_start = (
547
574
  time_to_reference_start.days * 86400.0 +
@@ -552,8 +579,8 @@ class ImageDicomFilePT(ImageDicomFile):
552
579
 
553
580
  else:
554
581
  raise ValueError(
555
- f"Decay correction DICOM tag in {self.file_path} was not recognised: {decay_correction}. One of ",
556
- f"NONE, START or ADMIN was expected."
582
+ f"Decay correction DICOM tag was not recognised: {decay_correction}. One of NONE, START or ADMIN "
583
+ f"was expected. [{self.describe_self()}]"
557
584
  )
558
585
 
559
586
  return decay_factor
@@ -564,7 +591,7 @@ class ImageDicomFilePT(ImageDicomFile):
564
591
 
565
592
  pet_unit = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0054, 0x1001), tag_type="str")
566
593
  if pet_unit is None:
567
- raise ValueError(f"PET Units (0x0054, 0x1001) was missing in {self.file_path}.")
594
+ raise ValueError(f"PET Units (0x0054, 0x1001) was missing. [{self.describe_self()}]")
568
595
 
569
596
  if pet_unit in ["CNTS", "CPS"]:
570
597
  conversion_factor = self._pet_unit_cnt_to_bqml()
@@ -573,7 +600,9 @@ class ImageDicomFilePT(ImageDicomFile):
573
600
  elif pet_unit in ["GML", "CM2ML"]:
574
601
  conversion_factor = 1.0
575
602
  else:
576
- raise NotImplementedError(f"Conversion factor for converting {pet_unit} to BQML is not implemented")
603
+ raise NotImplementedError(
604
+ f"Conversion factor for converting {pet_unit} to BQML is not implemented. [{self.describe_self()}]"
605
+ )
577
606
 
578
607
  return conversion_factor
579
608
 
@@ -595,7 +624,9 @@ class ImageDicomFilePT(ImageDicomFile):
595
624
  tag_type="float"
596
625
  )
597
626
  if frame_duration is None:
598
- raise ValueError(f"Frame duration cannot be determined from DICOM metadata in {self.file_path}.")
627
+ raise ValueError(
628
+ f"Frame duration cannot be determined from DICOM metadata. [{self.describe_self()}]"
629
+ )
599
630
  frame_duration /= 1000.0 # From milliseconds to seconds.
600
631
  conversion_factor = 1.0 / frame_duration
601
632
 
@@ -608,7 +639,7 @@ class ImageDicomFilePT(ImageDicomFile):
608
639
  )
609
640
  if administered_volume is None:
610
641
  raise ValueError(
611
- f"Radiopharmaceutical volume cannot be determined from DICOM metadata in {self.file_path}"
642
+ f"Radiopharmaceutical volume cannot be determined from DICOM metadata. [{self.describe_self()}]"
612
643
  )
613
644
 
614
645
  # Divide by administered volume (in cubic cm == milliliter)
@@ -616,13 +647,16 @@ class ImageDicomFilePT(ImageDicomFile):
616
647
 
617
648
  else:
618
649
  raise ValueError(
619
- f"Radiopharmaceutical Information Sequence (0x0054, 0x0016) is missing in DICOM metadata in "
620
- f"{self.file_path}."
650
+ f"Radiopharmaceutical Information Sequence (0x0054, 0x0016) is missing in DICOM metadata. "
651
+ f"[{self.describe_self()}]"
621
652
  )
622
653
 
623
654
  # Final check
624
655
  if conversion_factor is None:
625
- raise ValueError(f"Conversion factor for converting {pet_unit} to BQML could not be established")
656
+ raise ValueError(
657
+ f"Conversion factor for converting {pet_unit} to BQML could not be established. "
658
+ f"[{self.describe_self()}]"
659
+ )
626
660
 
627
661
  return conversion_factor
628
662
 
@@ -639,7 +673,7 @@ class ImageDicomFilePT(ImageDicomFile):
639
673
  if current_suv_type is None:
640
674
  pet_unit = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0054, 0x1001), tag_type="str")
641
675
  if pet_unit is None:
642
- raise ValueError(f"PET Units (0x0054, 0x1001) was missing in {self.file_path}.")
676
+ raise ValueError(f"PET Units (0x0054, 0x1001) was missing. [{self.describe_self()}]")
643
677
 
644
678
  if pet_unit == "GML":
645
679
  # If absent, and the Units (0054,1001) are GML, then the type of SUV shall be assumed to be BW.
@@ -687,12 +721,13 @@ class ImageDicomFilePT(ImageDicomFile):
687
721
  patient_weight = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0010, 0x1030), tag_type="float")
688
722
  if patient_weight is None:
689
723
  raise ValueError(
690
- f"Patient weight (0x0010, 0x1030) was missing in {self.file_path}. SUV normalisation is not possible."
724
+ f"Patient weight (0x0010, 0x1030) was missing. SUV normalisation is not possible. "
725
+ f"[{self.describe_self()}]"
691
726
  )
692
727
  elif patient_weight <= 0.0:
693
728
  raise ValueError(
694
- f"Patient weight (0x0010, 0x1030) was not positive ({patient_weight}) in {self.file_path}. SUV "
695
- f"normalisation is not possible."
729
+ f"Patient weight (0x0010, 0x1030) was not positive ({patient_weight}). SUV normalisation is not "
730
+ f"possible. [{self.describe_self()}]"
696
731
  )
697
732
  elif patient_weight >= 1000.0:
698
733
  # Weight is likely provide in grams, not kilograms. Convert to kg.
@@ -710,13 +745,13 @@ class ImageDicomFilePT(ImageDicomFile):
710
745
 
711
746
  if administered_dose is None:
712
747
  raise ValueError(
713
- f"Radionuclide Total Dose (0x0018, 0x1074) was missing in {self.file_path}. SUV normalisation is not "
714
- f"possible."
748
+ f"Radionuclide Total Dose (0x0018, 0x1074) was missing. SUV normalisation is not possible. "
749
+ f"[{self.describe_self()}]"
715
750
  )
716
751
  elif administered_dose <= 0.0:
717
752
  raise ValueError(
718
- f"Radionuclide Total Dose (0x0018, 0x1074) was not positive ({administered_dose}) in "
719
- f"{self.file_path}. SUV normalisation is not possible."
753
+ f"Radionuclide Total Dose (0x0018, 0x1074) was not positive ({administered_dose}). "
754
+ f"SUV normalisation is not possible. [{self.describe_self()}]"
720
755
  )
721
756
 
722
757
  # Body weight-corrected SUV ------------------------------------------------------------------------------------
@@ -727,13 +762,13 @@ class ImageDicomFilePT(ImageDicomFile):
727
762
  patient_height = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0010, 0x1020), tag_type="float")
728
763
  if patient_height is None:
729
764
  raise ValueError(
730
- f"Patient Size (0x0010, 0x1020) was missing in {self.file_path}. SUV normalisation ({suv_type}) is not "
731
- f"possible."
765
+ f"Patient Size (0x0010, 0x1020) was missing. SUV normalisation ({suv_type}) is not possible. "
766
+ f"[{self.describe_self()}]"
732
767
  )
733
768
  elif patient_height <= 0.0:
734
769
  raise ValueError(
735
- f"Patient Size (0x0010, 0x1020) was not positive ({patient_height}) in {self.file_path}. SUV "
736
- f"normalisation ({suv_type}) is not possible."
770
+ f"Patient Size (0x0010, 0x1020) was not positive ({patient_height}). SUV normalisation ({suv_type}) "
771
+ f"is not possible. [{self.describe_self()}]"
737
772
  )
738
773
  elif patient_height > 3.0:
739
774
  # Interpret patient height as cm and convert to meter.
@@ -750,8 +785,8 @@ class ImageDicomFilePT(ImageDicomFile):
750
785
  patient_biological_sex = "O"
751
786
  if patient_biological_sex.lower() not in ["m", "f", "w", "o", "d", "u"]:
752
787
  raise ValueError(
753
- f"Patient Sex (0x0010, 0x0040) was not recognised ({patient_biological_sex} in {self.file_path}. SUV "
754
- f"normalisation ({suv_type}) is not possible."
788
+ f"Patient Sex (0x0010, 0x0040) was not recognised ({patient_biological_sex}. SUV normalisation "
789
+ f"({suv_type}) is not possible. [{self.describe_self()}]"
755
790
  )
756
791
 
757
792
  # Erroneous lean body mass-corrected SUV -----------------------------------------------------------------------
@@ -4,7 +4,6 @@ import os
4
4
  import numpy as np
5
5
 
6
6
  from typing import Any
7
- from pydicom import dcmread
8
7
  from mirp._data_import.dicom_file import ImageDicomFile
9
8
  from mirp._data_import.utilities import get_pydicom_meta_tag
10
9
 
@@ -62,7 +61,6 @@ class ImageDicomFileRTDose(ImageDicomFile):
62
61
 
63
62
  # First compute z-orientation.
64
63
  orientation += list(np.cross(orientation[0:3], orientation[3:6]))
65
-
66
64
  self.image_orientation = np.reshape(orientation[::-1], [3, 3], order="F")
67
65
 
68
66
  def _complete_image_spacing(self, force=False):
@@ -86,15 +84,16 @@ class ImageDicomFileRTDose(ImageDicomFile):
86
84
  z_spacing = np.unique(np.diff(z_spacing))
87
85
  if len(z_spacing) > 1:
88
86
  raise ValueError(
89
- f"Spacing of radiation dose grid in {self.file_path} is inconsistent: {', '.join(z_spacing)}"
87
+ f"Spacing of radiation dose grid is inconsistent: {', '.join(z_spacing)}. "
88
+ f"[{self.describe_self()}]"
90
89
  )
91
90
  z_spacing = z_spacing[0]
92
91
  else:
93
92
  # DICOM file contains only a single frame. Use a default 1.0 mm value.
94
93
  z_spacing = 1.0
95
94
  warnings.warn(
96
- f"Radiation dose grid in {self.file_path} only contains a single frame (slice). A default frame "
97
- f"spacing of 1.0 mm is assumed. Within-plane spacing is not affected."
95
+ f"Radiation dose grid only contains a single frame (slice). A default frame spacing of 1.0 mm is "
96
+ f"assumed. Within-plane spacing is not affected. [{self.describe_self()}]"
98
97
  )
99
98
 
100
99
  if z_spacing < 0.0:
@@ -127,18 +126,23 @@ class ImageDicomFileRTDose(ImageDicomFile):
127
126
 
128
127
  if self.file_path is not None and not os.path.exists(self.file_path):
129
128
  raise FileNotFoundError(
130
- f"The image file could not be found at the expected location: {self.file_path}"
129
+ f"The image file could not be found at the expected location: {self.file_path} [{self.describe_self()}]"
131
130
  )
132
131
 
133
132
  if self.file_path is None:
134
- raise ValueError(f"A path to a file was expected, but not present.")
133
+ raise ValueError(f"A path to a file was expected, but not present. [{self.describe_self()}]")
135
134
 
136
135
  # Load metadata.
137
136
  self.load_metadata(include_image=True)
138
137
  image_data = self.image_metadata.pixel_array.astype(np.float32)
139
138
 
140
139
  # Update data with dose grid scaling
141
- dose_grid_scaling = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x3004, 0x000E), tag_type="float", default=1.0)
140
+ dose_grid_scaling = get_pydicom_meta_tag(
141
+ dcm_seq=self.image_metadata,
142
+ tag=(0x3004, 0x000E),
143
+ tag_type="float",
144
+ default=1.0
145
+ )
142
146
  image_data = image_data * dose_grid_scaling
143
147
 
144
148
  self.image_data = image_data