diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 78b627b8ec8c27fdb1070606fb2590798ca179bf..2391a3bafd065ff8ce23cd7107b033ce3785cb19 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,17 @@ This document contains the ``fslpy`` release history in reverse chronological order. +2.8.1 (Under development) +------------------------- + + +Fixed +^^^^^ + + +* Fixed a bug where an error would be raised on attempts to load an image file + without a BIDS-compatible name from a BIDS-like directory. + 2.8.0 (Wednesday 29th January 2020) ----------------------------------- diff --git a/fsl/data/image.py b/fsl/data/image.py index b65f28105668b76867f41f6d3f0c7a0fa8100c44..2060aad046a95f998625ac0f2520240a500b845c 100644 --- a/fsl/data/image.py +++ b/fsl/data/image.py @@ -1540,7 +1540,8 @@ def loadMetadata(image): basename = op.basename(removeExt(filename)) dirname = op.dirname(filename) - if fslbids.inBIDSDir(image.dataSource): + if fslbids.isBIDSFile(image.dataSource) and \ + fslbids.inBIDSDir( image.dataSource): return fslbids.loadMetadata(image.dataSource) jsonfile = op.join(dirname, '{}.json'.format(basename)) diff --git a/tests/test_image.py b/tests/test_image.py index e12c6acb7dd2b829a588b13551949e83d4bb9e43..06801c11fae442edcb1e68ab1c3eeda2e440f3a6 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -1401,6 +1401,25 @@ def test_loadMeta(): assert img.getMeta('b') == 2 +def test_loadMeta_nonBids(): + with tempdir(): + + # non-bids file in a BIDS-like directory + imgfile = op.join('data', 'sub-01', 'anat', 'sub-01_T1w_nonbids.nii.gz') + + os.makedirs(op.dirname(imgfile)) + + make_image(imgfile) + + with open(op.join('data', 'dataset_description.json'), 'wt') as f: + pass + + + img = fslimage.Image(imgfile, loadMeta=True) + assert list(img.metaKeys()) == [] + + + def test_loadMetadata(): with tempdir(): make_image('image.nii.gz')