Skip to content

Commit 23f5f6c

Browse files
authored
Merge pull request #18 from cancan101/handle_file
allow taking in nifti file rather than filename
2 parents d260490 + c0e33e4 commit 23f5f6c

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

niwidgets/niwidget_volume.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,18 @@ def __init__(self, filename):
4141
The path to your ``.nii`` file. Can be a string, or a
4242
``PosixPath`` from python3's pathlib.
4343
"""
44-
self.filename = Path(filename).resolve()
45-
if not os.path.isfile(self.filename):
46-
raise OSError('File ' + self.filename.name + ' not found.')
47-
48-
# load data in advance
49-
# this ensures once the widget is created that the file is of a format
50-
# readable by nibabel
51-
self.data = nib.load(str(self.filename))
44+
if hasattr(filename, 'get_data'):
45+
self.data = filename
46+
else:
47+
filename = Path(filename).resolve()
48+
if not os.path.isfile(filename):
49+
raise OSError('File ' + filename.name + ' not found.')
50+
51+
# load data in advance
52+
# this ensures once the widget is created that the file is of a format
53+
# readable by nibabel
54+
self.data = nib.load(str(filename))
55+
5256
# initialise where the image handles will go
5357
self.image_handles = None
5458

0 commit comments

Comments
 (0)