Skip to content
Snippets Groups Projects
Commit ee0a37b7 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Merge branch 'bf/meta' into 'master'

Bf/meta

See merge request fsl/fslpy!221
parents 0a972e0c b2f25b10
No related branches found
No related tags found
No related merge requests found
...@@ -74,7 +74,8 @@ Fixed ...@@ -74,7 +74,8 @@ Fixed
functions. functions.
* Fixed the :func:`.DeformationField.transform` method so it works with * Fixed the :func:`.DeformationField.transform` method so it works with
a single set of coordinates. a single set of coordinates.
* :class:`.Image` creation does not fail if ``loadMeta`` is set, and a
sidecar file containing invalid JSON is present.
Removed Removed
^^^^^^^ ^^^^^^^
......
...@@ -1162,11 +1162,19 @@ class Image(Nifti): ...@@ -1162,11 +1162,19 @@ class Image(Nifti):
self.register(self.name, self.__headerChanged, topic='transform') self.register(self.name, self.__headerChanged, topic='transform')
self.register(self.name, self.__headerChanged, topic='header') self.register(self.name, self.__headerChanged, topic='header')
# calculate min/max
# of image data
if calcRange: if calcRange:
self.calcRange() self.calcRange()
# try and load metadata
# from JSON sidecar files
if self.dataSource is not None and loadMeta: if self.dataSource is not None and loadMeta:
self.updateMeta(loadMetadata(self)) try:
self.updateMeta(loadMetadata(self))
except Exception as e:
log.warning('Failed to load metadata for %s: %s',
self.dataSource, e)
self.__imageWrapper.register(self.__lName, self.__dataRangeChanged) self.__imageWrapper.register(self.__lName, self.__dataRangeChanged)
......
...@@ -1414,11 +1414,23 @@ def test_loadMeta_nonBids(): ...@@ -1414,11 +1414,23 @@ def test_loadMeta_nonBids():
with open(op.join('data', 'dataset_description.json'), 'wt') as f: with open(op.join('data', 'dataset_description.json'), 'wt') as f:
pass pass
img = fslimage.Image(imgfile, loadMeta=True) img = fslimage.Image(imgfile, loadMeta=True)
assert list(img.metaKeys()) == [] assert list(img.metaKeys()) == []
def test_loadMeta_badJSON():
with tempdir():
make_image('image.nii.gz')
# spurious comma after b:2
with open('image.json', 'wt') as f:
f.write('{"a" : 1, "b" : 2,}')
# bad json should not cause failure
img = fslimage.Image('image.nii.gz', loadMeta=True)
assert list(img.metaKeys()) == []
def test_loadMetadata(): def test_loadMetadata():
with tempdir(): with tempdir():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment