Skip to content

Commit

Permalink
Merge pull request #18 from ArcanaFramework/develop
Browse files Browse the repository at this point in the history
Added Siemens Biograph Raw data types
  • Loading branch information
tclose authored Nov 14, 2023
2 parents b7f90ae + 4e5d91f commit a07a193
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 72 deletions.
12 changes: 9 additions & 3 deletions fileformats/medimage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@
# SiemensDicomDir,
)
from .raw import ( # noqa: F401
ListMode,
Kspace,
TwixVb,
# CustomKspace,
Rda,
PetListMode,
PetSinogram,
PetCountRate,
PetNormalisation,
Vnd_Siemens_Biograph128Vision_Vr20b_PetRawData,
Vnd_Siemens_Biograph128Vision_Vr20b_PetListMode,
Vnd_Siemens_Biograph128Vision_Vr20b_PetSinogram,
Vnd_Siemens_Biograph128Vision_Vr20b_PetCountRate,
Vnd_Siemens_Biograph128Vision_Vr20b_PetNormalisation,
)
17 changes: 10 additions & 7 deletions fileformats/medimage/dicom.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,31 @@ class DicomDir(DicomCollection, DirectoryContaining[Dicom]):


class DicomSeries(DicomCollection, SetOf[Dicom]):

@classmethod
def from_paths(
cls, fspaths: ty.Iterable[Path], common_ok: bool = False
) -> ty.Tuple[ty.Set[FileSet], ty.Set[Path]]:
dicoms, remaining = Dicom.from_paths(fspaths, common_ok=common_ok)
series_dict = defaultdict(list)
for dicom in dicoms:
series_dict[dicom["SeriesNumber"]].append(dicom)
series_dict[(str(dicom["StudyInstanceUID"]), str(dicom["SeriesNumber"]))].append(dicom)
return set([cls(s) for s in series_dict.values()]), remaining


@FileSet.read_metadata.register
def dicom_collection_read_metadata(collection: DicomCollection) -> ty.Dict[str, ty.Any]:
# Collated DICOM headers across series
collated = copy(collection.contents[0].metadata)
if len(collection.contents) > 1:
for key, val in collection.contents[1].metadata.items():
if val != collated[key]: # Turn field into list
collated[key] = [collated[key], val]
for dicom in collection.contents[2:]:
for i, dicom in enumerate(collection.contents[1:], start=1):
for key, val in dicom.metadata.items():
if val != collated[key]:
# Check whether the value is the same as the values in the previous
# images in the series
if (
not isinstance(collated[key], list)
or isinstance(val, list)
and not isinstance(collated[key][0], list)
):
collated[key] = [collated[key]] * i + [val]
collated[key].append(val)
return collated
62 changes: 0 additions & 62 deletions fileformats/medimage/raw.py

This file was deleted.

16 changes: 16 additions & 0 deletions fileformats/medimage/raw/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from .mri import ( # noqa: F401
Kspace,
Rda,
)
from .pet import (
PetRawData,
PetListMode,
PetSinogram,
PetCountRate,
PetNormalisation,
Vnd_Siemens_Biograph128Vision_Vr20b_PetRawData,
Vnd_Siemens_Biograph128Vision_Vr20b_PetListMode,
Vnd_Siemens_Biograph128Vision_Vr20b_PetSinogram,
Vnd_Siemens_Biograph128Vision_Vr20b_PetCountRate,
Vnd_Siemens_Biograph128Vision_Vr20b_PetNormalisation,
)
14 changes: 14 additions & 0 deletions fileformats/medimage/raw/mri/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from fileformats.generic import File


class Kspace(File):

binary = True
iana_mime = None


class Rda(File):
"""MRS format"""

ext = ".rda"
binary = True
14 changes: 14 additions & 0 deletions fileformats/medimage/raw/pet/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from .base import (
PetRawData,
PetListMode,
PetSinogram,
PetCountRate,
PetNormalisation,
)
from .siemens import (
Vnd_Siemens_Biograph128Vision_Vr20b_PetRawData,
Vnd_Siemens_Biograph128Vision_Vr20b_PetListMode,
Vnd_Siemens_Biograph128Vision_Vr20b_PetSinogram,
Vnd_Siemens_Biograph128Vision_Vr20b_PetCountRate,
Vnd_Siemens_Biograph128Vision_Vr20b_PetNormalisation,
)
27 changes: 27 additions & 0 deletions fileformats/medimage/raw/pet/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from fileformats.generic import File


class PetRawData(File):

binary = True
iana_mime = None


class PetListMode(PetRawData):
"raw projection data"
iana_mime = None


class PetSinogram(PetRawData):
"histogrammed projection data in a reconstruction-friendly format"
iana_mime = None


class PetCountRate(PetRawData):
"number of prompt/random/single events per unit time"
iana_mime = None


class PetNormalisation(PetRawData):
"normalisation scan or the current cross calibration factor"
iana_mime = None
36 changes: 36 additions & 0 deletions fileformats/medimage/raw/pet/siemens.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from .base import (
PetRawData,
PetListMode,
PetSinogram,
PetCountRate,
PetNormalisation,
)


class Vnd_Siemens_Biograph128Vision_Vr20b_PetRawData(PetRawData):
iana_mime = None
ext = ".ptd"


class Vnd_Siemens_Biograph128Vision_Vr20b_PetListMode(
Vnd_Siemens_Biograph128Vision_Vr20b_PetRawData, PetListMode
):
pass


class Vnd_Siemens_Biograph128Vision_Vr20b_PetSinogram(
Vnd_Siemens_Biograph128Vision_Vr20b_PetRawData, PetSinogram
):
"histogrammed projection data in a reconstruction-friendly format"


class Vnd_Siemens_Biograph128Vision_Vr20b_PetCountRate(
Vnd_Siemens_Biograph128Vision_Vr20b_PetRawData, PetCountRate
):
"number of prompt/random/single events per unit time"


class Vnd_Siemens_Biograph128Vision_Vr20b_PetNormalisation(
Vnd_Siemens_Biograph128Vision_Vr20b_PetRawData, PetNormalisation
):
"normalisation scan or the current cross calibration factor"

0 comments on commit a07a193

Please sign in to comment.