Skip to content

nifti_folders_mri_exam_repository

oxytcmri.interface.repositories.nifti_folders_mri_exam_repository

Classes:

Name Description
NiftiFoldersMRIExamRepository

NiftiFoldersMRIExamRepository(base_path, atlas_repository=None)

Bases: MRIExamRepository

Initialize the repository with a base path for NIfTI files.

Parameters:

Name Type Description Default
base_path str

The base path where NIfTI files are stored.

required

Methods:

Name Description
scan_nifti_folders

Scan the base path for NIfTI folders and create MRIExam objects.

get_exam_for_subject

Retrieve the MRI exam for a specific subject.

find_by_id

Find an MRIExam by its ID.

list_all

List all MRI exams in the repository.

delete
save

Attributes:

Name Type Description
base_path
atlas_repository
mri_exam_list
Source code in oxytcmri/interface/repositories/nifti_folders_mri_exam_repository.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def __init__(self,
             base_path: str,
             atlas_repository: AtlasRepository = None):
    """Initialize the repository with a base path for NIfTI files.

    Parameters
    ----------
    base_path : str
        The base path where NIfTI files are stored.
    """
    self.base_path = Path(base_path)

    # Ensure that the base path exists
    if not self.base_path.exists():
        raise FileNotFoundError(f"path '{base_path}' does not exist.")

    if atlas_repository is not None:
        self.atlas_repository = atlas_repository
        self.mri_exam_list = self.scan_nifti_folders()
    else:
        self.atlas_repository = None
        self.mri_exam_list = []

base_path = Path(base_path) instance-attribute

atlas_repository = atlas_repository instance-attribute

mri_exam_list = self.scan_nifti_folders() instance-attribute

scan_nifti_folders()

Scan the base path for NIfTI folders and create MRIExam objects.

Returns:

Type Description
list[MRIExam]

A list of MRIExam objects representing the NIfTI folders found in the base path.

Source code in oxytcmri/interface/repositories/nifti_folders_mri_exam_repository.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def scan_nifti_folders(self) -> list[MRIExam]:
    """
    Scan the base path for NIfTI folders and create MRIExam objects.

    Returns
    -------
    list[MRIExam]
        A list of MRIExam objects representing the NIfTI folders found in the base path.
    """
    result = []

    for mri_exam_folder in self.base_path.iterdir():
        if mri_exam_folder.is_dir():
            mri_exam = self._create_mri_exam_from_folder(mri_exam_folder)
            if mri_exam is not None:
                result.append(mri_exam)

    return result

get_exam_for_subject(subject_id)

Retrieve the MRI exam for a specific subject.

Parameters:

Name Type Description Default
subject_id SubjectId

The identifier of the subject

required

Returns:

Type Description
MRIExam

The MRI exam for the subject

Source code in oxytcmri/interface/repositories/nifti_folders_mri_exam_repository.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
def get_exam_for_subject(self, subject_id: SubjectId) -> MRIExam:
    """Retrieve the MRI exam for a specific subject.

    Parameters
    ----------
    subject_id : SubjectId
        The identifier of the subject

    Returns
    -------
    MRIExam
        The MRI exam for the subject
    """
    for mri_exam in self.mri_exam_list:
        if mri_exam.subject_id == subject_id:
            return mri_exam

    raise LookupError(f"No MRI exam found for subject {subject_id}")

find_by_id(entity_id)

Find an MRIExam by its ID.

Parameters:

Name Type Description Default
entity_id MRIExamId

The ID of the MRI exam

required

Returns:

Type Description
Entity

The entity if found, otherwise None

Source code in oxytcmri/interface/repositories/nifti_folders_mri_exam_repository.py
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
def find_by_id(self, entity_id: MRIExamId) -> Optional[MRIExam]:
    """Find an MRIExam by its ID.

    Parameters
    ----------
    entity_id : MRIExamId
        The ID of the MRI exam

    Returns
    -------
    Entity
        The entity if found, otherwise None
    """
    for mri_exam in self.mri_exam_list:
        if mri_exam.id == entity_id:
            return mri_exam
    return None

list_all()

List all MRI exams in the repository.

Returns:

Type Description
List[MRIExam]

A list of all MRI exams in the repository

Source code in oxytcmri/interface/repositories/nifti_folders_mri_exam_repository.py
151
152
153
154
155
156
157
158
159
def list_all(self) -> List[MRIExam]:
    """List all MRI exams in the repository.

    Returns
    -------
    List[MRIExam]
        A list of all MRI exams in the repository
    """
    return self.mri_exam_list

delete(entity)

Source code in oxytcmri/interface/repositories/nifti_folders_mri_exam_repository.py
161
162
def delete(self, entity: Entity) -> None:
    raise NotImplementedError("Deleting MRI exams is not supported in this repository.")

save(mri_exam)

Source code in oxytcmri/interface/repositories/nifti_folders_mri_exam_repository.py
164
165
def save(self, mri_exam: MRIExam) -> None:
    raise NotImplementedError("Saving MRI exams is not supported in this repository.")