Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions pytheranostics/imaging_tools/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,33 @@ def load_metadata(dir: str, modality: str) -> ImagingMetadata:
radionuclide = modality.split("_")[0]

# This only applies to Q-SPECT TODO: replace for something more generic.
try:
injected_activity = (
dicom_slices[0]
.RadiopharmaceuticalInformationSequence[0]
.RadionuclideTotalDose
)

# Currently we don't have a way to know the units ... so we use common sense.
if injected_activity > 20000: # Activity likely in Bq instead of MBq
injected_activity /= 1e6
print(
f"Injected activity found in DICOM Header: {injected_activity:2.1f} MBq. Please verify."
)

except (AttributeError, IndexError):
print(
"Injected activity not found in DICOM header. Using default: 7400 MBq"
)
injected_activity = None

if hasattr(dicom_slices[0], "RadiopharmaceuticalInformationSequence"):
rp_seq = dicom_slices[0].RadiopharmaceuticalInformationSequence
if len(rp_seq) > 0:
try:
injected_activity = rp_seq[0].RadionuclideTotalDose

# Currently we don't have a way to know the units ... so we use common sense.
if injected_activity > 20000: # Activity likely in Bq instead of MBq
injected_activity /= 1e6
print(
f"Injected activity found in DICOM Header: {injected_activity:2.1f} MBq. Please verify."
)
except AttributeError:
# Sequence exists but RadionuclideTotalDose attribute is missing
print(
"RadiopharmaceuticalInformationSequence found but RadionuclideTotalDose is missing."
)
else:
# Sequence exists but is empty - this may indicate a data quality issue
print(
"Warning: RadiopharmaceuticalInformationSequence is empty. This may indicate a data quality issue."
)

if injected_activity is None:
print("Using default injected activity: 7400 MBq")
injected_activity = 7400.0

# Global attributes. Should be the same in all slices!
Expand Down
Loading