mirp 2.2.1__tar.gz → 2.2.2__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.2}/NEWS.md +25 -0
  2. {mirp-2.2.1 → mirp-2.2.2}/PKG-INFO +1 -1
  3. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/dicom_file.py +63 -16
  4. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/dicom_file_pet.py +70 -38
  5. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/dicom_file_rtdose.py +12 -8
  6. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/dicom_file_rtstruct.py +29 -25
  7. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/dicom_file_seg.py +40 -33
  8. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/dicom_file_stack.py +5 -4
  9. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/generic_file.py +88 -47
  10. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/generic_file_stack.py +13 -6
  11. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/itk_file.py +12 -5
  12. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/itk_file_stack.py +8 -4
  13. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/numpy_file.py +20 -9
  14. {mirp-2.2.1 → mirp-2.2.2}/mirp/_featuresets/morphology_3d.py +7 -9
  15. {mirp-2.2.1 → mirp-2.2.2}/mirp/_images/utilities.py +14 -1
  16. {mirp-2.2.1 → mirp-2.2.2}/mirp/config_settings.xml +15 -15
  17. {mirp-2.2.1 → mirp-2.2.2}/mirp/deep_learning_preprocessing.py +4 -4
  18. {mirp-2.2.1 → mirp-2.2.2}/mirp/extract_features_and_images.py +158 -12
  19. {mirp-2.2.1 → mirp-2.2.2}/mirp/settings/image_processing_parameters.py +1 -1
  20. {mirp-2.2.1 → mirp-2.2.2}/mirp/settings/import_config_parameters.py +9 -9
  21. {mirp-2.2.1 → mirp-2.2.2}/mirp/settings/resegmentation_parameters.py +0 -2
  22. {mirp-2.2.1 → mirp-2.2.2}/mirp/settings/utilities.py +18 -0
  23. {mirp-2.2.1 → mirp-2.2.2}/mirp.egg-info/PKG-INFO +1 -1
  24. {mirp-2.2.1 → mirp-2.2.2}/pyproject.toml +4 -1
  25. {mirp-2.2.1 → mirp-2.2.2}/CONTRIBUTING.md +0 -0
  26. {mirp-2.2.1 → mirp-2.2.2}/LICENSE.txt +0 -0
  27. {mirp-2.2.1 → mirp-2.2.2}/MANIFEST.in +0 -0
  28. {mirp-2.2.1 → mirp-2.2.2}/README.md +0 -0
  29. {mirp-2.2.1 → mirp-2.2.2}/mirp/__init__.py +0 -0
  30. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/__init__.py +0 -0
  31. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/dicom_file_ct.py +0 -0
  32. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/dicom_file_mr.py +0 -0
  33. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/directory.py +0 -0
  34. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/mask_contour.py +0 -0
  35. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/numpy_file_stack.py +0 -0
  36. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/read_data.py +0 -0
  37. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/suv.py +0 -0
  38. {mirp-2.2.1 → mirp-2.2.2}/mirp/_data_import/utilities.py +0 -0
  39. {mirp-2.2.1 → mirp-2.2.2}/mirp/_featuresets/__init__.py +0 -0
  40. {mirp-2.2.1 → mirp-2.2.2}/mirp/_featuresets/cm.py +0 -0
  41. {mirp-2.2.1 → mirp-2.2.2}/mirp/_featuresets/dzm.py +0 -0
  42. {mirp-2.2.1 → mirp-2.2.2}/mirp/_featuresets/intensity_histogram.py +0 -0
  43. {mirp-2.2.1 → mirp-2.2.2}/mirp/_featuresets/intensity_volume_histogram.py +0 -0
  44. {mirp-2.2.1 → mirp-2.2.2}/mirp/_featuresets/local_intensity.py +0 -0
  45. {mirp-2.2.1 → mirp-2.2.2}/mirp/_featuresets/ngldm.py +0 -0
  46. {mirp-2.2.1 → mirp-2.2.2}/mirp/_featuresets/ngtdm.py +0 -0
  47. {mirp-2.2.1 → mirp-2.2.2}/mirp/_featuresets/rlm.py +0 -0
  48. {mirp-2.2.1 → mirp-2.2.2}/mirp/_featuresets/statistics.py +0 -0
  49. {mirp-2.2.1 → mirp-2.2.2}/mirp/_featuresets/szm.py +0 -0
  50. {mirp-2.2.1 → mirp-2.2.2}/mirp/_featuresets/utilities.py +0 -0
  51. {mirp-2.2.1 → mirp-2.2.2}/mirp/_image_processing/__init__.py +0 -0
  52. {mirp-2.2.1 → mirp-2.2.2}/mirp/_image_processing/alter_mask.py +0 -0
  53. {mirp-2.2.1 → mirp-2.2.2}/mirp/_image_processing/anti_aliasing.py +0 -0
  54. {mirp-2.2.1 → mirp-2.2.2}/mirp/_image_processing/cropping.py +0 -0
  55. {mirp-2.2.1 → mirp-2.2.2}/mirp/_image_processing/discretise_image.py +0 -0
  56. {mirp-2.2.1 → mirp-2.2.2}/mirp/_image_processing/randomise_mask.py +0 -0
  57. {mirp-2.2.1 → mirp-2.2.2}/mirp/_image_processing/split_mask.py +0 -0
  58. {mirp-2.2.1 → mirp-2.2.2}/mirp/_image_processing/tissue_mask.py +0 -0
  59. {mirp-2.2.1 → mirp-2.2.2}/mirp/_image_processing/utilities.py +0 -0
  60. {mirp-2.2.1 → mirp-2.2.2}/mirp/_imagefilters/__init__.py +0 -0
  61. {mirp-2.2.1 → mirp-2.2.2}/mirp/_imagefilters/exponential_transform.py +0 -0
  62. {mirp-2.2.1 → mirp-2.2.2}/mirp/_imagefilters/gabor.py +0 -0
  63. {mirp-2.2.1 → mirp-2.2.2}/mirp/_imagefilters/gaussian.py +0 -0
  64. {mirp-2.2.1 → mirp-2.2.2}/mirp/_imagefilters/generic.py +0 -0
  65. {mirp-2.2.1 → mirp-2.2.2}/mirp/_imagefilters/laplacian_of_gaussian.py +0 -0
  66. {mirp-2.2.1 → mirp-2.2.2}/mirp/_imagefilters/laws.py +0 -0
  67. {mirp-2.2.1 → mirp-2.2.2}/mirp/_imagefilters/log_transform.py +0 -0
  68. {mirp-2.2.1 → mirp-2.2.2}/mirp/_imagefilters/mean.py +0 -0
  69. {mirp-2.2.1 → mirp-2.2.2}/mirp/_imagefilters/nonseparable_wavelet.py +0 -0
  70. {mirp-2.2.1 → mirp-2.2.2}/mirp/_imagefilters/separable_wavelet.py +0 -0
  71. {mirp-2.2.1 → mirp-2.2.2}/mirp/_imagefilters/square_root_transform.py +0 -0
  72. {mirp-2.2.1 → mirp-2.2.2}/mirp/_imagefilters/square_transform.py +0 -0
  73. {mirp-2.2.1 → mirp-2.2.2}/mirp/_imagefilters/utilities.py +0 -0
  74. {mirp-2.2.1 → mirp-2.2.2}/mirp/_images/__init__.py +0 -0
  75. {mirp-2.2.1 → mirp-2.2.2}/mirp/_images/base_image.py +0 -0
  76. {mirp-2.2.1 → mirp-2.2.2}/mirp/_images/ct_image.py +0 -0
  77. {mirp-2.2.1 → mirp-2.2.2}/mirp/_images/generic_image.py +0 -0
  78. {mirp-2.2.1 → mirp-2.2.2}/mirp/_images/mask_image.py +0 -0
  79. {mirp-2.2.1 → mirp-2.2.2}/mirp/_images/mr_image.py +0 -0
  80. {mirp-2.2.1 → mirp-2.2.2}/mirp/_images/pet_image.py +0 -0
  81. {mirp-2.2.1 → mirp-2.2.2}/mirp/_images/rtdose_image.py +0 -0
  82. {mirp-2.2.1 → mirp-2.2.2}/mirp/_images/transformed_image.py +0 -0
  83. {mirp-2.2.1 → mirp-2.2.2}/mirp/_masks/__init__.py +0 -0
  84. {mirp-2.2.1 → mirp-2.2.2}/mirp/_masks/base_mask.py +0 -0
  85. {mirp-2.2.1 → mirp-2.2.2}/mirp/_workflows/__init__.py +0 -0
  86. {mirp-2.2.1 → mirp-2.2.2}/mirp/_workflows/baseWorkflow.py +0 -0
  87. {mirp-2.2.1 → mirp-2.2.2}/mirp/_workflows/standardWorkflow.py +0 -0
  88. {mirp-2.2.1 → mirp-2.2.2}/mirp/config_data.xml +0 -0
  89. {mirp-2.2.1 → mirp-2.2.2}/mirp/data_import/__init__.py +0 -0
  90. {mirp-2.2.1 → mirp-2.2.2}/mirp/data_import/import_image.py +0 -0
  91. {mirp-2.2.1 → mirp-2.2.2}/mirp/data_import/import_image_and_mask.py +0 -0
  92. {mirp-2.2.1 → mirp-2.2.2}/mirp/data_import/import_mask.py +0 -0
  93. {mirp-2.2.1 → mirp-2.2.2}/mirp/deprecated.py +0 -0
  94. {mirp-2.2.1 → mirp-2.2.2}/mirp/extract_image_parameters.py +0 -0
  95. {mirp-2.2.1 → mirp-2.2.2}/mirp/extract_mask_labels.py +0 -0
  96. {mirp-2.2.1 → mirp-2.2.2}/mirp/settings/__init__.py +0 -0
  97. {mirp-2.2.1 → mirp-2.2.2}/mirp/settings/feature_parameters.py +0 -0
  98. {mirp-2.2.1 → mirp-2.2.2}/mirp/settings/general_parameters.py +0 -0
  99. {mirp-2.2.1 → mirp-2.2.2}/mirp/settings/generic.py +0 -0
  100. {mirp-2.2.1 → mirp-2.2.2}/mirp/settings/import_data_parameters.py +0 -0
  101. {mirp-2.2.1 → mirp-2.2.2}/mirp/settings/interpolation_parameters.py +0 -0
  102. {mirp-2.2.1 → mirp-2.2.2}/mirp/settings/perturbation_parameters.py +0 -0
  103. {mirp-2.2.1 → mirp-2.2.2}/mirp/settings/transformation_parameters.py +0 -0
  104. {mirp-2.2.1 → mirp-2.2.2}/mirp/utilities/__init__.py +0 -0
  105. {mirp-2.2.1 → mirp-2.2.2}/mirp/utilities/config_utilities.py +0 -0
  106. {mirp-2.2.1 → mirp-2.2.2}/mirp/utilities/parallel.py +0 -0
  107. {mirp-2.2.1 → mirp-2.2.2}/mirp/utilities/utilities.py +0 -0
  108. {mirp-2.2.1 → mirp-2.2.2}/mirp.egg-info/SOURCES.txt +0 -0
  109. {mirp-2.2.1 → mirp-2.2.2}/mirp.egg-info/dependency_links.txt +0 -0
  110. {mirp-2.2.1 → mirp-2.2.2}/mirp.egg-info/requires.txt +0 -0
  111. {mirp-2.2.1 → mirp-2.2.2}/mirp.egg-info/top_level.txt +0 -0
  112. {mirp-2.2.1 → mirp-2.2.2}/setup.cfg +0 -0
@@ -1,3 +1,28 @@
1
+ # Version 2.2.2
2
+
3
+ ## Minor changes
4
+
5
+ - `show` method of `GenericImage` and subclasses now indicate if a user-provided `slice_id` is out-of-volume and
6
+ select the nearest slice instead.
7
+
8
+ - Naming of branches in the settings `xml` file now matches that of their respective settings classes. `xml` files
9
+ with the previous branch names still function.
10
+
11
+ - Errors encountered during file import and handling are now more descriptive.
12
+ - `extract_mask_labels` and `extract_image_parameters` now export extra information from DICOM metadata, e.g. series
13
+ UID.
14
+
15
+ ## Documentation
16
+
17
+ - Added a new tutorial on applying image filters to images.
18
+ - Added documentation on the feature naming system.
19
+ - Added documentation on the design of MIRP.
20
+
21
+ ## Fixes
22
+
23
+ - Computing features related to the minimum volume enclosing ellipsoid no longer produces warnings due to the use of
24
+ deprecated `numpy.matrix` class.
25
+
1
26
  # Version 2.2.1
2
27
 
3
28
  ## 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.2
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
@@ -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)
@@ -516,10 +528,42 @@ class ImageDicomFile(ImageFile):
516
528
 
517
529
  # Final check.
518
530
  if acquisition_ref_time is None:
519
- raise ValueError(f"Acquisition start time cannot be determined from DICOM metadata in {self.file_path}.")
531
+ raise ValueError(
532
+ f"Acquisition start time cannot be determined from DICOM metadata."
533
+ )
520
534
 
521
535
  return acquisition_ref_time
522
536
 
537
+ def _get_export_attributes(self) -> dict[str, Any]:
538
+ attributes = []
539
+ self.load_metadata()
540
+
541
+ study_description = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0008, 0x1030), tag_type="str")
542
+ if study_description is not None and study_description != "":
543
+ attributes += [("study_description", study_description)]
544
+
545
+ series_description = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0008, 0x103E), tag_type="str")
546
+ if series_description is not None and series_description != "":
547
+ attributes += [("series_description", series_description)]
548
+
549
+ # Try to find the acquisition time (which may be equal to series time).
550
+ try:
551
+ acquisition_time = self._get_acquisition_start_time()
552
+ except ValueError:
553
+ acquisition_time = None
554
+ if acquisition_time is not None:
555
+ attributes += [("acquisition_time", acquisition_time)]
556
+
557
+ if self.series_instance_uid is not None:
558
+ attributes += [("series_instance_uid", self.series_instance_uid)]
559
+ if self.frame_of_reference_uid is not None:
560
+ attributes += [("frame_of_reference_uid", self.frame_of_reference_uid)]
561
+
562
+ parent_attributes = super()._get_export_attributes()
563
+ parent_attributes.update(dict(attributes))
564
+
565
+ return parent_attributes
566
+
523
567
 
524
568
  class MaskDicomFile(ImageDicomFile, MaskFile):
525
569
  def __init__(self, **kwargs):
@@ -531,8 +575,11 @@ class MaskDicomFile(ImageDicomFile, MaskFile):
531
575
  if dicom_modality.lower() not in support_modalities:
532
576
  if raise_error:
533
577
  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)}")
578
+ f"The current DICOM file does not have the expected modality. "
579
+ f"Found: {dicom_modality.lower()}. "
580
+ f"Expected: {', '.join(support_modalities)}. "
581
+ f"[{self.describe_self()}]"
582
+ )
536
583
 
537
584
  return False
538
585
 
@@ -561,7 +608,7 @@ class MaskDicomFile(ImageDicomFile, MaskFile):
561
608
  modality = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0008, 0x0060), tag_type="str").lower()
562
609
 
563
610
  if modality is None:
564
- raise TypeError(f"Modality attribute could not be obtained from DICOM file ({self.file_path})")
611
+ raise TypeError(f"Modality attribute could not be obtained from the DICOM file. [{self.describe_self()}]")
565
612
 
566
613
  if modality == "rtstruct":
567
614
  file_class = MaskDicomFileRTSTRUCT
@@ -53,28 +53,44 @@ 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
89
  # Get SUV conversion factor.
77
- suv_factor = self._get_suv_conversion_factor(new_suv_type=pet_suv_conversion)
90
+ if conversion_possible:
91
+ suv_factor = self._get_suv_conversion_factor(new_suv_type=pet_suv_conversion)
92
+ else:
93
+ suv_factor = 1.0
78
94
 
79
95
  # Update image_data
80
96
  image_data *= decay_factor * bqml_factor * suv_factor
@@ -461,7 +477,7 @@ class ImageDicomFilePT(ImageDicomFile):
461
477
  # Final check.
462
478
  if admin_ref_time is None:
463
479
  raise ValueError(
464
- f"Radiopharmaceutical start time cannot be determined from DICOM metadata in {self.file_path}."
480
+ f"Radiopharmaceutical start time cannot be determined from DICOM metadata. [{self.describe_self()}]"
465
481
  )
466
482
 
467
483
  return admin_ref_time
@@ -481,8 +497,8 @@ class ImageDicomFilePT(ImageDicomFile):
481
497
 
482
498
  elif decay_correction not in ["NONE", "START"]:
483
499
  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."
500
+ f"Decay correction DICOM tag was not recognised: {decay_correction}. One of ",
501
+ f"NONE, START or ADMIN was expected. [{self.describe_self()}]"
486
502
  )
487
503
 
488
504
  # Get acquisition start time and tracer administration time.
@@ -492,7 +508,7 @@ class ImageDicomFilePT(ImageDicomFile):
492
508
  # Get frame duration in seconds.
493
509
  frame_duration = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0018, 0x1242), tag_type="float")
494
510
  if frame_duration is None:
495
- raise ValueError(f"Frame duration cannot be determined from DICOM metadata in {self.file_path}.")
511
+ raise ValueError(f"Frame duration cannot be determined from DICOM metadata. [{self.describe_self()}]")
496
512
  frame_duration /= 1000.0 # From milliseconds to seconds.
497
513
 
498
514
  # Radionuclide total dose and radionuclide half-life
@@ -507,7 +523,7 @@ class ImageDicomFilePT(ImageDicomFile):
507
523
  if half_life is None:
508
524
  raise ValueError(
509
525
  f"Radionuclide half-life (0x0018, 0x1075) was missing in the Radiopharmaceutical "
510
- f"information sequence (0x0054, 0x0016) of {self.file_path}."
526
+ f"information sequence (0x0054, 0x0016). [{self.describe_self()}]"
511
527
  )
512
528
 
513
529
  # Decay constant.
@@ -532,16 +548,24 @@ class ImageDicomFilePT(ImageDicomFile):
532
548
  # vendorneutral pseudocode.
533
549
 
534
550
  # 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")
551
+ frame_reference_time = get_pydicom_meta_tag(
552
+ dcm_seq=self.image_metadata,
553
+ tag=(0x0054, 0x1300),
554
+ tag_type="float"
555
+ )
536
556
  if frame_reference_time is None:
537
- raise ValueError(f"Frame reference time (0x0054, 0x1300) was missing in {self.file_path}.")
557
+ raise ValueError(f"Frame reference time (0x0054, 0x1300) was missing. [{self.describe_self()}]")
538
558
  frame_reference_time /= 1000.0
539
559
 
540
560
  # 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)))
561
+ time_count_average = 1.0 / _lambda * np.log(
562
+ _lambda * frame_duration / (1.0 - np.exp(-_lambda * frame_duration))
563
+ )
542
564
 
543
565
  # 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)
566
+ reference_start_time = acquisition_start_time + datetime.timedelta(
567
+ seconds=time_count_average - frame_reference_time
568
+ )
545
569
  time_to_reference_start = reference_start_time - tracer_administration_time
546
570
  time_to_reference_start = (
547
571
  time_to_reference_start.days * 86400.0 +
@@ -552,8 +576,8 @@ class ImageDicomFilePT(ImageDicomFile):
552
576
 
553
577
  else:
554
578
  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."
579
+ f"Decay correction DICOM tag was not recognised: {decay_correction}. One of NONE, START or ADMIN "
580
+ f"was expected. [{self.describe_self()}]"
557
581
  )
558
582
 
559
583
  return decay_factor
@@ -564,7 +588,7 @@ class ImageDicomFilePT(ImageDicomFile):
564
588
 
565
589
  pet_unit = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0054, 0x1001), tag_type="str")
566
590
  if pet_unit is None:
567
- raise ValueError(f"PET Units (0x0054, 0x1001) was missing in {self.file_path}.")
591
+ raise ValueError(f"PET Units (0x0054, 0x1001) was missing. [{self.describe_self()}]")
568
592
 
569
593
  if pet_unit in ["CNTS", "CPS"]:
570
594
  conversion_factor = self._pet_unit_cnt_to_bqml()
@@ -573,7 +597,9 @@ class ImageDicomFilePT(ImageDicomFile):
573
597
  elif pet_unit in ["GML", "CM2ML"]:
574
598
  conversion_factor = 1.0
575
599
  else:
576
- raise NotImplementedError(f"Conversion factor for converting {pet_unit} to BQML is not implemented")
600
+ raise NotImplementedError(
601
+ f"Conversion factor for converting {pet_unit} to BQML is not implemented. [{self.describe_self()}]"
602
+ )
577
603
 
578
604
  return conversion_factor
579
605
 
@@ -595,7 +621,9 @@ class ImageDicomFilePT(ImageDicomFile):
595
621
  tag_type="float"
596
622
  )
597
623
  if frame_duration is None:
598
- raise ValueError(f"Frame duration cannot be determined from DICOM metadata in {self.file_path}.")
624
+ raise ValueError(
625
+ f"Frame duration cannot be determined from DICOM metadata. [{self.describe_self()}]"
626
+ )
599
627
  frame_duration /= 1000.0 # From milliseconds to seconds.
600
628
  conversion_factor = 1.0 / frame_duration
601
629
 
@@ -608,7 +636,7 @@ class ImageDicomFilePT(ImageDicomFile):
608
636
  )
609
637
  if administered_volume is None:
610
638
  raise ValueError(
611
- f"Radiopharmaceutical volume cannot be determined from DICOM metadata in {self.file_path}"
639
+ f"Radiopharmaceutical volume cannot be determined from DICOM metadata. [{self.describe_self()}]"
612
640
  )
613
641
 
614
642
  # Divide by administered volume (in cubic cm == milliliter)
@@ -616,13 +644,16 @@ class ImageDicomFilePT(ImageDicomFile):
616
644
 
617
645
  else:
618
646
  raise ValueError(
619
- f"Radiopharmaceutical Information Sequence (0x0054, 0x0016) is missing in DICOM metadata in "
620
- f"{self.file_path}."
647
+ f"Radiopharmaceutical Information Sequence (0x0054, 0x0016) is missing in DICOM metadata. "
648
+ f"[{self.describe_self()}]"
621
649
  )
622
650
 
623
651
  # Final check
624
652
  if conversion_factor is None:
625
- raise ValueError(f"Conversion factor for converting {pet_unit} to BQML could not be established")
653
+ raise ValueError(
654
+ f"Conversion factor for converting {pet_unit} to BQML could not be established. "
655
+ f"[{self.describe_self()}]"
656
+ )
626
657
 
627
658
  return conversion_factor
628
659
 
@@ -639,7 +670,7 @@ class ImageDicomFilePT(ImageDicomFile):
639
670
  if current_suv_type is None:
640
671
  pet_unit = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0054, 0x1001), tag_type="str")
641
672
  if pet_unit is None:
642
- raise ValueError(f"PET Units (0x0054, 0x1001) was missing in {self.file_path}.")
673
+ raise ValueError(f"PET Units (0x0054, 0x1001) was missing. [{self.describe_self()}]")
643
674
 
644
675
  if pet_unit == "GML":
645
676
  # If absent, and the Units (0054,1001) are GML, then the type of SUV shall be assumed to be BW.
@@ -687,12 +718,13 @@ class ImageDicomFilePT(ImageDicomFile):
687
718
  patient_weight = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0010, 0x1030), tag_type="float")
688
719
  if patient_weight is None:
689
720
  raise ValueError(
690
- f"Patient weight (0x0010, 0x1030) was missing in {self.file_path}. SUV normalisation is not possible."
721
+ f"Patient weight (0x0010, 0x1030) was missing. SUV normalisation is not possible. "
722
+ f"[{self.describe_self()}]"
691
723
  )
692
724
  elif patient_weight <= 0.0:
693
725
  raise ValueError(
694
- f"Patient weight (0x0010, 0x1030) was not positive ({patient_weight}) in {self.file_path}. SUV "
695
- f"normalisation is not possible."
726
+ f"Patient weight (0x0010, 0x1030) was not positive ({patient_weight}). SUV normalisation is not "
727
+ f"possible. [{self.describe_self()}]"
696
728
  )
697
729
  elif patient_weight >= 1000.0:
698
730
  # Weight is likely provide in grams, not kilograms. Convert to kg.
@@ -710,13 +742,13 @@ class ImageDicomFilePT(ImageDicomFile):
710
742
 
711
743
  if administered_dose is None:
712
744
  raise ValueError(
713
- f"Radionuclide Total Dose (0x0018, 0x1074) was missing in {self.file_path}. SUV normalisation is not "
714
- f"possible."
745
+ f"Radionuclide Total Dose (0x0018, 0x1074) was missing. SUV normalisation is not possible. "
746
+ f"[{self.describe_self()}]"
715
747
  )
716
748
  elif administered_dose <= 0.0:
717
749
  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."
750
+ f"Radionuclide Total Dose (0x0018, 0x1074) was not positive ({administered_dose}). "
751
+ f"SUV normalisation is not possible. [{self.describe_self()}]"
720
752
  )
721
753
 
722
754
  # Body weight-corrected SUV ------------------------------------------------------------------------------------
@@ -727,13 +759,13 @@ class ImageDicomFilePT(ImageDicomFile):
727
759
  patient_height = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0010, 0x1020), tag_type="float")
728
760
  if patient_height is None:
729
761
  raise ValueError(
730
- f"Patient Size (0x0010, 0x1020) was missing in {self.file_path}. SUV normalisation ({suv_type}) is not "
731
- f"possible."
762
+ f"Patient Size (0x0010, 0x1020) was missing. SUV normalisation ({suv_type}) is not possible. "
763
+ f"[{self.describe_self()}]"
732
764
  )
733
765
  elif patient_height <= 0.0:
734
766
  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."
767
+ f"Patient Size (0x0010, 0x1020) was not positive ({patient_height}). SUV normalisation ({suv_type}) "
768
+ f"is not possible. [{self.describe_self()}]"
737
769
  )
738
770
  elif patient_height > 3.0:
739
771
  # Interpret patient height as cm and convert to meter.
@@ -750,8 +782,8 @@ class ImageDicomFilePT(ImageDicomFile):
750
782
  patient_biological_sex = "O"
751
783
  if patient_biological_sex.lower() not in ["m", "f", "w", "o", "d", "u"]:
752
784
  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."
785
+ f"Patient Sex (0x0010, 0x0040) was not recognised ({patient_biological_sex}. SUV normalisation "
786
+ f"({suv_type}) is not possible. [{self.describe_self()}]"
755
787
  )
756
788
 
757
789
  # 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
@@ -50,7 +50,8 @@ class MaskDicomFileRTSTRUCT(MaskDicomFile):
50
50
  self.frame_of_reference_uid = get_pydicom_meta_tag(
51
51
  dcm_seq=self.image_metadata,
52
52
  tag=(0x0020, 0x0052),
53
- tag_type="str")
53
+ tag_type="str"
54
+ )
54
55
 
55
56
  # For RT structure sets, the FOR UID may be tucked away in the Structure Set ROI Sequence
56
57
  if self.frame_of_reference_uid is None and \
@@ -62,7 +63,8 @@ class MaskDicomFileRTSTRUCT(MaskDicomFile):
62
63
  self.frame_of_reference_uid = get_pydicom_meta_tag(
63
64
  dcm_seq=structure_set_roi_element,
64
65
  tag=(0x3006, 0x0024),
65
- tag_type="str")
66
+ tag_type="str"
67
+ )
66
68
  break
67
69
 
68
70
  def check_mask(self, raise_error=True):
@@ -72,7 +74,7 @@ class MaskDicomFileRTSTRUCT(MaskDicomFile):
72
74
  if not get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x3006, 0x0020), test_tag=True):
73
75
  if raise_error:
74
76
  warnings.warn(
75
- f"The RT-structure set ({self.file_path}) did not contain any ROI sequences.",
77
+ f"The current RT-structure set did not contain any ROI sequences. [{self.describe_self()}]",
76
78
  )
77
79
  return False
78
80
 
@@ -84,13 +86,13 @@ class MaskDicomFileRTSTRUCT(MaskDicomFile):
84
86
 
85
87
  if len(roi_name_present) == 0 and raise_error:
86
88
  warnings.warn(
87
- f"The current RT-structure set ({self.file_path}) does not contain any ROI contours."
89
+ f"The current RT-structure set does not contain any ROI contours. [{self.describe_self()}]"
88
90
  )
89
91
  return False
90
92
 
91
93
  if any(x is None for x in roi_name_present) and raise_error:
92
94
  warnings.warn(
93
- f"The current RT-structure set ({self.file_path}) lacks one or more ROI names."
95
+ f"The current RT-structure set lacks one or more ROI names. [{self.describe_self()}]"
94
96
  )
95
97
  return False
96
98
 
@@ -108,7 +110,7 @@ class MaskDicomFileRTSTRUCT(MaskDicomFile):
108
110
  if image is None:
109
111
  raise TypeError(
110
112
  f"Converting an RT-structure to a segmentation mask requires that the corresponding image is set. "
111
- f"No image was provided ({self.file_path})."
113
+ f"No image was provided. [{self.describe_self()}]"
112
114
  )
113
115
  else:
114
116
  image.complete()
@@ -692,19 +694,19 @@ class MaskDicomFileRTSTRUCT(MaskDicomFile):
692
694
 
693
695
  return merged_contour_list
694
696
 
695
- @staticmethod
696
- def _match_slice_position(slice_position, known_position, image_spacing_z):
697
- # Match slice position of mask with any known slice position.
698
- img_slice_position = slice_position * image_spacing_z
699
- position_difference = np.around(np.abs(img_slice_position - known_position), 3)
700
-
701
- # Check if there is any matching position.
702
- if np.any(position_difference == 0.0):
703
- int_slice_position = int(np.argwhere(position_difference == 0.0))
704
- else:
705
- int_slice_position = None
706
-
707
- return int_slice_position
697
+ # @staticmethod
698
+ # def _match_slice_position(slice_position, known_position, image_spacing_z):
699
+ # # Match slice position of mask with any known slice position.
700
+ # img_slice_position = slice_position * image_spacing_z
701
+ # position_difference = np.around(np.abs(img_slice_position - known_position), 3)
702
+ #
703
+ # # Check if there is any matching position.
704
+ # if np.any(position_difference == 0.0):
705
+ # int_slice_position = int(np.argwhere(position_difference == 0.0))
706
+ # else:
707
+ # int_slice_position = None
708
+ #
709
+ # return int_slice_position
708
710
 
709
711
  def export_roi_labels(self):
710
712
 
@@ -722,9 +724,11 @@ class MaskDicomFileRTSTRUCT(MaskDicomFile):
722
724
  if len(labels) == 0:
723
725
  labels = [None]
724
726
 
725
- return {
726
- "sample_name": [self.sample_name] * n_labels,
727
- "dir_path": [self.dir_path] * n_labels,
728
- "file_path": [self.file_name] * n_labels,
729
- "roi_label": labels
730
- }
727
+ # Get general attributes.
728
+ parent_attributes = self._get_export_attributes()
729
+
730
+ # Add roi labels as attribute.
731
+ attributes = [("roi_label", labels)]
732
+ parent_attributes.update(dict(attributes))
733
+
734
+ return parent_attributes