Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions niwidgets/niwidget_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ def __init__(self, filename):
The path to your ``.nii`` file. Can be a string, or a
``PosixPath`` from python3's pathlib.
"""
self.filename = Path(filename).resolve()
if not os.path.isfile(self.filename):
raise OSError('File ' + self.filename.name + ' not found.')

# load data in advance
# this ensures once the widget is created that the file is of a format
# readable by nibabel
self.data = nib.load(str(self.filename))
if hasattr(filename, 'get_data'):
self.data = filename
else:
filename = Path(filename).resolve()
if not os.path.isfile(filename):
raise OSError('File ' + filename.name + ' not found.')

# load data in advance
# this ensures once the widget is created that the file is of a format
# readable by nibabel
self.data = nib.load(str(filename))

# initialise where the image handles will go
self.image_handles = None

Expand Down