Skip to content

Commit df126dc

Browse files
committed
TEST: Modified from_file_map() in brikhead.py
`brikhead.AFNIImage.from_file_map()` was needlessly opening the 'image' file before passing it to ImageArrayProxy, potentially causing issues seen on AppVeyor with mmaps. This commit modifies the call to be more in line with how this is handled in analyze.py.
1 parent dce22dc commit df126dc

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

nibabel/brikhead.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,10 @@ def __init__(self, file_like, header, mmap=True, keep_file_open=None):
207207
``'auto'``, and the optional ``indexed_gzip`` dependency is
208208
present, a single file handle is created and persisted. If
209209
``indexed_gzip`` is not available, behaviour is the same as if
210-
``keep_file_open is False``. If ``file_like`` is an open file
211-
handle, this setting has no effect. The default value (``None``)
212-
will result in the value of ``KEEP_FILE_OPEN_DEFAULT`` being used.
210+
``keep_file_open is False``. If ``file_like`` refers to an open
211+
file handle, this setting has no effect. The default value
212+
(``None``) will result in the value of
213+
``nibabel.arrayproxy.KEEP_FILE_OPEN_DEFAULT` being used.
213214
"""
214215
super(AFNIArrayProxy, self).__init__(file_like,
215216
header,
@@ -437,11 +438,11 @@ def from_file_map(klass, file_map, mmap=True):
437438
read array from file.
438439
"""
439440
with file_map['header'].get_prepare_fileobj('rt') as hdr_fobj:
440-
hdr = klass.header_class.from_fileobj(
441-
hdr_fobj)
442-
brik_fobj = file_map['image'].get_prepare_fileobj()
443-
data = klass.ImageArrayProxy(brik_fobj, hdr,
444-
mmap=mmap)
441+
hdr = klass.header_class.from_fileobj(hdr_fobj)
442+
imgf = file_map['image'].fileobj
443+
if imgf is None:
444+
imgf = file_map['image'].filename
445+
data = klass.ImageArrayProxy(imgf, hdr.copy(), mmap=mmap)
445446
return klass(data, hdr.get_affine(), header=hdr, extra=None,
446447
file_map=file_map)
447448

0 commit comments

Comments
 (0)