-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Volume shape is not preserved by round-trip conversion to NumPy array using Volume.arraydata() #92
Comments
One problem is that the array returned by both |
Well, |
There was a mistake in a comparison to determine strides order. This is fixed and it partly fixes this issue, but we can discuss if it solves it completely or not. Now the test prints:
thus only the 1st (using So my opinion is that it is solved now. Any comments ? |
Well there is still something not correct:
prints:
so from the Volume point of view it seems OK, but the array returned by |
from __future__ import print_function
import numpy
from soma import aims
def test_numpy_conversion(filename):
vol = aims.read(filename)
arr = vol.arraydata()
test_vol = aims.Volume(arr)
print(vol.header()['volume_dimension'], '-> .arraydata() ->',
'shape', arr.shape, 'strides', arr.strides,
'-> aims.Volume() ->', test_vol.header()['volume_dimension'])
vol = aims.read(filename)
arr = numpy.asarray(vol)
test_vol = aims.Volume(arr)
print(vol.header()['volume_dimension'], '-> numpy.asarray() ->',
'shape', arr.shape, 'strides', arr.strides,
'-> aims.Volume() ->', test_vol.header()['volume_dimension'])
vol = aims.read(filename)
arr = numpy.asfortranarray(vol)
test_vol = aims.Volume(arr)
print(vol.header()['volume_dimension'], '-> numpy.asfortranarray() ->',
'shape', arr.shape, 'strides', arr.strides,
'-> aims.Volume() ->', test_vol.header()['volume_dimension'])
vol = aims.read(filename)
arr = numpy.ascontiguousarray(vol)
test_vol = aims.Volume(arr)
print(vol.header()['volume_dimension'], '-> numpy.ascontiguousarray() ->',
'shape', arr.shape, 'strides', arr.strides,
'-> aims.Volume() ->', test_vol.header()['volume_dimension'])
vol = aims.Volume(1, 2, 3, 4)
aims.write(vol, "test.nii.gz")
test_numpy_conversion("test.nii.gz") $ /i2bm/brainvisa/brainvisa-cea-5.0.4/bin/bv python min.py
[1, 2, 3, 4] -> .arraydata() -> shape (4, 3, 2, 1) strides (24, 8, 4, 4) -> aims.Volume() -> [1, 2, 3, 4]
[1, 2, 3, 4] -> numpy.asarray() -> shape (1, 2, 3, 4) strides (4, 4, 8, 24) -> aims.Volume() -> [1, 2, 3, 4]
[1, 2, 3, 4] -> numpy.asfortranarray() -> shape (1, 2, 3, 4) strides (4, 4, 8, 24) -> aims.Volume() -> [1, 2, 3, 4]
[1, 2, 3, 4] -> numpy.ascontiguousarray() -> shape (1, 2, 3, 4) strides (96, 48, 16, 4) -> aims.Volume() -> [4, 3, 2, 1] $ /i2bm/brainvisa/brainvisa-cea-5.1.0/bin/bv python min.py
[1, 2, 3, 4] -> .arraydata() -> shape (4, 3, 2, 1) strides (24, 8, 4, 4) -> aims.Volume() -> [4, 3, 2, 1]
[1, 2, 3, 4] -> numpy.asarray() -> shape (1, 2, 3, 4) strides (4, 4, 8, 24) -> aims.Volume() -> [1, 2, 3, 4]
[1, 2, 3, 4] -> numpy.asfortranarray() -> shape (1, 2, 3, 4) strides (4, 4, 8, 24) -> aims.Volume() -> [1, 2, 3, 4]
[1, 2, 3, 4] -> numpy.ascontiguousarray() -> shape (1, 2, 3, 4) strides (96, 48, 16, 4) -> aims.Volume() -> [1, 2, 3, 4] Actually, when we load the volumes from scratch to set aside the cache issue, it seems that the only issue is with convesion of array to Volume following |
This is fixed by a294104. |
I am compiling your fix to test its behaviour with my Python script |
I am in the process if integrating your test function (slightly modified) in test scripts. |
Okay so after your changes, my test script outputs:
… which is exactly the same as BrainVISA 5.1.0, or am I missing something? My understanding is that:
|
If you are using your second, modified test code, which reallocates the volume between tests. And in my opinion, this is what is expected. My fixes are about the array cache in the volume (which primary goal is to avoid deleting the volume which owns the data block while the array is still living), thus fix your first test. |
I just had another user run into the exact same issue because they have I would propose to drop support for We also need to fix the code that we distribute: I counted 501 uses of $ ack -ch --python --ignore-dir=master '.arraydata'
501 |
OK I agree to make |
This issue is essentially solved (as a WONTFIX) so I propose to track the deprecation of |
Describe the bug
The shape on a
Volume
is changed when it is simply converted to a NumPy array, and converted back to aVolume
. This looks like a serious regression in BrainVISA 5.1.0.To Reproduce
Steps to reproduce the behavior:
numpy.ascontiguousarray
:Expected behavior
Under BrainVISA 5.0.4 the output was correct with the “natural”
.arraydata
andnumpy.asarray
converters:Environment:
The text was updated successfully, but these errors were encountered: