diff --git a/niwidgets/niwidget_volume.py b/niwidgets/niwidget_volume.py index d6b1a86..a8a622e 100644 --- a/niwidgets/niwidget_volume.py +++ b/niwidgets/niwidget_volume.py @@ -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