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 test_scanDir(): with install_dcm2niix(): series = fsldcm.scanDir('.') assert len(series) == 0 datafile = op.join(datadir, 'example_dicom.tbz2') with tarfile.open(datafile) as f: f.extractall() series = fsldcm.scanDir('.') assert len(series) == 2 for s in series: assert (s['PatientName'] == 'MCCARTHY_PAUL' or s['PatientName'] == 'MCCARTHY_PAUL_2')
def scan(): try: series.extend(fsldcm.scanDir(dcmdir)) if len(series) == 0: raise Exception('Could not find any DICOM ' 'data series in {}'.format(dcmdir)) except Exception as e: series.append(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({})