Skip to content
Snippets Groups Projects
Commit ec3495df authored by Tamino Huxohl's avatar Tamino Huxohl
Browse files

revice prepare script for a better mapping from projections to reconstructions and mu maps

parent abe29b30
No related branches found
No related tags found
No related merge requests found
anonymous.md
venv/ venv/
**__pycache__/ **__pycache__/
/data/ /data/
......
from datetime import datetime
from enum import Enum
import pydicom
class DICOMTime(Enum):
Study = 1
Series = 2
Acquisition = 3
Content = 4
def date_field(self):
return f"{self.name}Date"
def time_field(self):
return f"{self.name}Time"
def to_datetime(self, dicom: pydicom.dataset.FileDataset) -> datetime:
_date = dicom[self.date_field()].value
_time = dicom[self.time_field()].value
return datetime(
year=int(_date[0:4]),
month=int(_date[4:6]),
day=int(_date[6:8]),
hour=int(_time[0:2]),
minute=int(_time[2:4]),
second=int(_time[4:6]),
# microsecond=int(_time.split(".")[1]),
)
def parse_age(patient_age: str) -> int:
"""
Parse an age string as defined in the DICOM standard into an integer representing the age in years.
:param patient_age: age string as defined in the DICOM standard
:return: the age in years as a number
"""
assert (
type(patient_age) == str
), f"patient age needs to be a string and not {type(patient_age)}"
assert (
len(patient_age) == 4
), f"patient age [{patient_age}] has to be four characters long"
_num, _format = patient_age[:3], patient_age[3]
assert (
_format == "Y"
), f"currently, only patient ages in years [Y] is supported, not [{_format}]"
return int(_num)
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment