def test_loadSeries(): # test a pre-CRC and a post-CRC version for version in ('1.0.20190410', '1.0.20190902'): with install_dcm2niix(version): datafile = op.join(datadir, 'example_dicom.tbz2') with tarfile.open(datafile) as f: f.extractall() dcmdir = os.getcwd() series = fsldcm.scanDir(dcmdir) expShape = (512, 512, 1) explens = [1, 1] for s, explen in zip(series, explens): imgs = fsldcm.loadSeries(s) assert len(imgs) == explen for img in imgs: assert img.dicomDir == dcmdir assert img.shape == expShape assert img[:].shape == expShape assert img.getMeta('PatientName') == 'MCCARTHY_PAUL' or \ img.getMeta('PatientName') == 'MCCARTHY_PAUL_2' assert 'PatientName' in img.metaKeys() assert 'MCCARTHY_PAUL' in img.metaValues() or \ 'MCCARTHY_PAUL_2' in img.metaValues() assert ('PatientName', 'MCCARTHY_PAUL') in img.metaItems() or \ ('PatientName', 'MCCARTHY_PAUL_2') in img.metaItems()
def load(): try: for s in series: images.extend(fsldcm.loadSeries(s)) if len(images) == 0: raise Exception('No images could be loaded ' 'from {}'.format(dcmdir)) except Exception as e: images.insert(0, e)
def test_disabled(): with mock.patch('fsl.data.dicom.enabled', return_value=False): with pytest.raises(RuntimeError): fsldcm.scanDir('.') with pytest.raises(RuntimeError): fsldcm.loadSeries({})