<div dir="ltr"><div><div>Well after all it seems to load the array in memory (and use it of course), since it is not a memmap anymore.<br><br>In [1]: import nibabel as nib<br><br>In [2]: %load_ext memory_profiler<br><br>In [3]: %memit a=vol.get_data()<br><br>In [4]: vol = nib.load('data.nii')<br><br>In [5]: %memit a=vol.get_data()<br>peak memory: 101.39 MiB, increment: 0.00 MiB<br><br>In [6]: %memit a=np.array(vol.get_data())<br>peak memory: 8139.60 MiB, increment: 8038.21 MiB<br><br></div>And it also seems to take twice the space in memory than on disk for some weird reason.<br></div>Any idea why that is?<br></div><div class="gmail_extra"><br><div class="gmail_quote">2016-01-14 12:24 GMT+01:00 Samuel St-Jean <span dir="ltr"><<a href="mailto:stjeansam@gmail.com" target="_blank">stjeansam@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Oh, a simple fix after all, thanks!<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">2016-01-14 12:14 GMT+01:00 Nathaniel Smith <span dir="ltr"><<a href="mailto:njs@pobox.com" target="_blank">njs@pobox.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>On Thu, Jan 14, 2016 at 2:28 AM, Samuel St-Jean <<a href="mailto:stjeansam@gmail.com" target="_blank">stjeansam@gmail.com</a>> wrote:<br>
> Hello,<br>
><br>
> While processing some hcp data, we decided to use directly nifti files<br>
> instead of using gzipped file as they use quite a lot of ram (there are some<br>
> PRs fixing this under the work in nibabel apparently). So when you load a<br>
> regular nifti file, it gets a memmap instead of a proper numpy array, which<br>
> does not support the same feature and sometimes ends up producing really<br>
> weird bugs down the line (<a href="https://github.com/numpy/numpy/issues/6750" rel="noreferrer" target="_blank">https://github.com/numpy/numpy/issues/6750</a>).<br>
><br>
> So, we just ended up casting the memmap to a regular numpy array with<br>
> something like<br>
><br>
> data = np.array(data)<br>
><br>
> While this works, is it memory usage friendly (hcp data is ~4go after all)<br>
> or does it keep a reference in the background? Is there a better way to<br>
> achieve similar results, like for example forcing nibabel to load a numpy<br>
> array directly instead of memmap?<br>
<br>
</span>It costs a few hundred bytes of memory, and otherwise will act<br>
identically except that you lose access to the special mmap methods. I<br>
wouldn't worry about it :-).<br>
<span><font color="#888888"><br>
-n<br>
<br>
--<br>
Nathaniel J. Smith -- <a href="http://vorpus.org" rel="noreferrer" target="_blank">http://vorpus.org</a><br>
_______________________________________________<br>
Neuroimaging mailing list<br>
<a href="mailto:Neuroimaging@python.org" target="_blank">Neuroimaging@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/neuroimaging" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/neuroimaging</a><br>
</font></span></blockquote></div><br></div>
</div></div></blockquote></div><br></div>