def test_scan_label_quality(self): tmp_dir = tempfile.mkdtemp() repository = XnatRepo( project_id=self.project, server=SERVER, cache_dir=tmp_dir) tree = repository.tree( subject_ids=[self.SUBJECT], visit_ids=[self.VISIT]) for accepted, expected in ( (None, '1unusable'), ((None, 'questionable', 'usable'), '2unlabelled'), (('questionable', 'usable'), '3questionable'), ('usable', '4usable')): inpt = InputFilesets('dummy', order=0, valid_formats=text_format, acceptable_quality=accepted) matched = inpt.match(tree).item(subject_id=self.SUBJECT, visit_id=self.VISIT) self.assertEqual(matched.name, expected)
def test_cache_on_path_access(self): tmp_dir = tempfile.mkdtemp() repository = XnatRepo(server=SERVER, cache_dir=tmp_dir) dataset = repository.dataset(self.project, subject_ids=[self.SUBJECT], visit_ids=[self.VISIT]) tree = dataset.tree # Get a fileset fileset = list(list(list(tree.subjects)[0].sessions)[0].filesets)[0] fileset.format = text_format self.assertEqual(fileset._path, None) target_path = op.join( tmp_dir, self.project, '{}_{}'.format(self.project, self.SUBJECT), '{}_{}_{}'.format(self.project, self.SUBJECT, self.VISIT), '{}-{}'.format(fileset.id, fileset.basename), fileset.fname) # This should implicitly download the fileset self.assertEqual(fileset.path, target_path) with open(target_path) as f: self.assertEqual(f.read(), self.INPUT_FILESETS[fileset.basename])
def test_dicom_match(self): analysis = test_data.TestMatchAnalysis( name='test_dicom', dataset=XnatRepo(server=SERVER, cache_dir=tempfile.mkdtemp()).dataset( self.project), processor=SingleProc(self.work_dir), inputs=test_data.TestDicomTagMatch.DICOM_MATCH) phase = list(analysis.data('gre_phase', derive=True))[0] mag = list(analysis.data('gre_mag', derive=True))[0] self.assertEqual(phase.name, 'gre_field_mapping_3mm_phase') self.assertEqual(mag.name, 'gre_field_mapping_3mm_mag')
def test_connect_disconnect(self): repository = XnatRepo(server=SERVER, cache_dir=tempfile.mkdtemp()) with repository: self._test_open(repository) self._test_closed(repository) with repository: self._test_open(repository) with repository: self._test_open(repository) self._test_open(repository) self._test_closed(repository)
def test_dicom_match(self): study = test_data.TestMatchStudy( name='test_dicom', repository=XnatRepo( project_id=self.project, server=SERVER, cache_dir=tempfile.mkdtemp()), processor=SingleProc(self.work_dir), inputs=test_data.TestDicomTagMatch.DICOM_MATCH) phase = list(study.data('gre_phase'))[0] mag = list(study.data('gre_mag'))[0] self.assertEqual(phase.name, 'gre_field_mapping_3mm_phase') self.assertEqual(mag.name, 'gre_field_mapping_3mm_mag')
def test_id_match(self): study = test_data.TestMatchStudy( name='test_dicom', repository=XnatRepo( project_id=self.project, server=SERVER, cache_dir=tempfile.mkdtemp()), processor=SingleProc(self.work_dir), inputs=[ InputFilesets('gre_phase', valid_formats=dicom_format, id=7), InputFilesets('gre_mag', valid_formats=dicom_format, id=6)]) phase = list(study.data('gre_phase'))[0] mag = list(study.data('gre_mag'))[0] self.assertEqual(phase.name, 'gre_field_mapping_3mm_phase') self.assertEqual(mag.name, 'gre_field_mapping_3mm_mag')
def test_id_match(self): analysis = test_data.TestMatchAnalysis( name='test_dicom', dataset=XnatRepo(server=SERVER, cache_dir=tempfile.mkdtemp()).dataset( self.project), processor=SingleProc(self.work_dir), inputs=[ FilesetFilter('gre_phase', valid_formats=dicom_format, id=7), FilesetFilter('gre_mag', valid_formats=dicom_format, id=6) ]) phase = list(analysis.data('gre_phase', derive=True))[0] mag = list(analysis.data('gre_mag', derive=True))[0] self.assertEqual(phase.name, 'gre_field_mapping_3mm_phase') self.assertEqual(mag.name, 'gre_field_mapping_3mm_mag')