[docs]classEPISURG(SubjectsDataset):""" `EPISURG <https://doi.org/10.5522/04/9996158.v1>`_ is a clinical dataset of :math:`T_1`-weighted MRI from 430 epileptic patients who underwent resective brain surgery at the National Hospital of Neurology and Neurosurgery (Queen Square, London, United Kingdom) between 1990 and 2018. The dataset comprises 430 postoperative MRI. The corresponding preoperative MRI is present for 268 subjects. Three human raters segmented the resection cavity on partially overlapping subsets of EPISURG. If you use this dataset for your research, you agree with the *Data use agreement* presented at the EPISURG entry on the `UCL Research Data Repository <https://doi.org/10.5522/04/9996158.v1>`_ and you must cite the corresponding publications. Args: root: Root directory to which the dataset will be downloaded. transform: An instance of :class:`~torchio.transforms.transform.Transform`. download: If set to ``True``, will download the data into :attr:`root`. .. warning:: The size of this dataset is multiple GB. If you set :attr:`download` to ``True``, it will take some time to be downloaded if it is not already present. """data_url='https://s3-eu-west-1.amazonaws.com/pstorage-ucl-2748466690/26153588/EPISURG.zip'# noqa: B950md5='5ec5831a2c6fbfdc8489ba2910a6504b'def__init__(self,root:TypePath,transform:Optional[Transform]=None,download:bool=False,**kwargs,):root=Path(root).expanduser().absolute()ifdownload:self._download(root)subjects_list=self._get_subjects_list(root)self.kwargs=kwargssuper().__init__(subjects_list,transform=transform,**kwargs)@staticmethoddef_check_exists(root,modalities):formodalityinmodalities:modality_dir=root/modalityifnotmodality_dir.is_dir():exists=Falsebreakelse:exists=Truereturnexists@staticmethoddef_get_subjects_list(root):episurg_dir=root/'EPISURG'subjects_dir=episurg_dir/'subjects'csv_path=episurg_dir/'subjects.csv'withopen(csv_path)ascsvfile:reader=csv.DictReader(csvfile)subjects=[]forrowinreader:subject_id=row['Subject']subject_dir=subjects_dir/subject_idsubject_dict={'subject_id':subject_id,'hemisphere':row['Hemisphere'],'surgery_type':row['Type'],}preop_dir=subject_dir/'preop'preop_paths=list(preop_dir.glob('*preop*'))assertlen(preop_paths)<=1ifpreop_paths:subject_dict['preop_mri']=ScalarImage(preop_paths[0])postop_dir=subject_dir/'postop'postop_path=list(postop_dir.glob('*postop-t1mri*'))[0]subject_dict['postop_mri']=ScalarImage(postop_path)forseg_pathinpostop_dir.glob('*seg*'):seg_id=seg_path.name[-8]subject_dict[f'seg_{seg_id}']=LabelMap(seg_path)subjects.append(Subject(**subject_dict))returnsubjectsdef_download(self,root:Path):"""Download the EPISURG data if it does not exist already."""if(root/'EPISURG').is_dir():returnroot.mkdir(exist_ok=True,parents=True)download_and_extract_archive(self.data_url,download_root=root,md5=self.md5,)(root/'EPISURG.zip').unlink()# cleanupdef_glob_subjects(self,string):subjects=[]forsubjectinself._subjects:forimage_nameinsubject:ifstringinimage_name:subjects.append(subject)breakreturnsubjectsdef_get_labeled_subjects(self):returnself._glob_subjects('seg')def_get_paired_subjects(self):returnself._glob_subjects('preop')def_get_subset(self,subjects):dataset=SubjectsDataset(subjects,transform=self._transform,**(self.kwargs),)returndataset
[docs]defget_labeled(self)->SubjectsDataset:"""Get dataset from subjects with manual annotations."""returnself._get_subset(self._get_labeled_subjects())
[docs]defget_unlabeled(self)->SubjectsDataset:"""Get dataset from subjects without manual annotations."""subjects=[sforsinself._subjectsifsnotinself._get_labeled_subjects()]returnself._get_subset(subjects)
[docs]defget_paired(self)->SubjectsDataset:"""Get dataset from subjects with pre- and post-op MRI."""returnself._get_subset(self._get_paired_subjects())