Skip to content
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

ValueError: cannot reshape array of size 0 into shape () when using system-wide scipy.netcdf #579

Closed
ignatenkobrain opened this issue Nov 12, 2017 · 15 comments
Milestone

Comments

@ignatenkobrain
Copy link

======================================================================
ERROR: autogenerated test from validate_affine
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_api_validators.py", line 23, in meth
    validator(self, imaker, params)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 415, in validate_affine
    img = imaker()
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 451, in <lambda>
    yield lambda: self.loader(img_params['fname']), img_params
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/filebasedimages.py", line 260, in from_filename
    return klass.from_file_map(file_map)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/minc1.py", line 311, in from_file_map
    minc_file = Minc1File(netcdf_file(fobj))
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 266, in __init__
    self._read()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 593, in _read
    self._read_var_array()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 682, in _read_var_array
    data.shape = shape
ValueError: cannot reshape array of size 0 into shape ()
======================================================================
ERROR: autogenerated test from validate_affine_deprecated
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_api_validators.py", line 23, in meth
    validator(self, imaker, params)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 425, in validate_affine_deprecated
    img = imaker()
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 451, in <lambda>
    yield lambda: self.loader(img_params['fname']), img_params
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/filebasedimages.py", line 260, in from_filename
    return klass.from_file_map(file_map)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/minc1.py", line 311, in from_file_map
    minc_file = Minc1File(netcdf_file(fobj))
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 266, in __init__
    self._read()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 593, in _read
    self._read_var_array()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 682, in _read_var_array
    data.shape = shape
ValueError: cannot reshape array of size 0 into shape ()
======================================================================
ERROR: autogenerated test from validate_data_deprecated
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_api_validators.py", line 23, in meth
    validator(self, imaker, params)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 358, in validate_data_deprecated
    img = imaker()
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 451, in <lambda>
    yield lambda: self.loader(img_params['fname']), img_params
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/filebasedimages.py", line 260, in from_filename
    return klass.from_file_map(file_map)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/minc1.py", line 311, in from_file_map
    minc_file = Minc1File(netcdf_file(fobj))
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 266, in __init__
    self._read()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 593, in _read
    self._read_var_array()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 682, in _read_var_array
    data.shape = shape
ValueError: cannot reshape array of size 0 into shape ()
======================================================================
ERROR: autogenerated test from validate_data_interface
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_api_validators.py", line 23, in meth
    validator(self, imaker, params)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 200, in validate_data_interface
    img = imaker()
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 451, in <lambda>
    yield lambda: self.loader(img_params['fname']), img_params
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/filebasedimages.py", line 260, in from_filename
    return klass.from_file_map(file_map)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/minc1.py", line 311, in from_file_map
    minc_file = Minc1File(netcdf_file(fobj))
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 266, in __init__
    self._read()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 593, in _read
    self._read_var_array()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 682, in _read_var_array
    data.shape = shape
ValueError: cannot reshape array of size 0 into shape ()
======================================================================
ERROR: autogenerated test from validate_dtype
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_api_validators.py", line 23, in meth
    validator(self, imaker, params)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 175, in validate_dtype
    img = imaker()
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 451, in <lambda>
    yield lambda: self.loader(img_params['fname']), img_params
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/filebasedimages.py", line 260, in from_filename
    return klass.from_file_map(file_map)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/minc1.py", line 311, in from_file_map
    minc_file = Minc1File(netcdf_file(fobj))
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 266, in __init__
    self._read()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 593, in _read
    self._read_var_array()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 682, in _read_var_array
    data.shape = shape
ValueError: cannot reshape array of size 0 into shape ()
======================================================================
ERROR: autogenerated test from validate_header
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_api_validators.py", line 23, in meth
    validator(self, imaker, params)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 108, in validate_header
    img = imaker()
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 451, in <lambda>
    yield lambda: self.loader(img_params['fname']), img_params
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/filebasedimages.py", line 260, in from_filename
    return klass.from_file_map(file_map)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/minc1.py", line 311, in from_file_map
    minc_file = Minc1File(netcdf_file(fobj))
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 266, in __init__
    self._read()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 593, in _read
    self._read_var_array()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 682, in _read_var_array
    data.shape = shape
ValueError: cannot reshape array of size 0 into shape ()
======================================================================
ERROR: autogenerated test from validate_header_deprecated
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_api_validators.py", line 23, in meth
    validator(self, imaker, params)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 115, in validate_header_deprecated
    img = imaker()
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 451, in <lambda>
    yield lambda: self.loader(img_params['fname']), img_params
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/filebasedimages.py", line 260, in from_filename
    return klass.from_file_map(file_map)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/minc1.py", line 311, in from_file_map
    minc_file = Minc1File(netcdf_file(fobj))
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 266, in __init__
    self._read()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 593, in _read
    self._read_var_array()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 682, in _read_var_array
    data.shape = shape
ValueError: cannot reshape array of size 0 into shape ()
======================================================================
ERROR: autogenerated test from validate_header_shape
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_api_validators.py", line 23, in meth
    validator(self, imaker, params)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 397, in validate_header_shape
    img = imaker()
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 451, in <lambda>
    yield lambda: self.loader(img_params['fname']), img_params
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/filebasedimages.py", line 260, in from_filename
    return klass.from_file_map(file_map)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/minc1.py", line 311, in from_file_map
    minc_file = Minc1File(netcdf_file(fobj))
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 266, in __init__
    self._read()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 593, in _read
    self._read_var_array()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 682, in _read_var_array
    data.shape = shape
ValueError: cannot reshape array of size 0 into shape ()
======================================================================
ERROR: autogenerated test from validate_no_slicing
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_api_validators.py", line 23, in meth
    validator(self, imaker, params)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 162, in validate_no_slicing
    img = imaker()
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 451, in <lambda>
    yield lambda: self.loader(img_params['fname']), img_params
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/filebasedimages.py", line 260, in from_filename
    return klass.from_file_map(file_map)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/minc1.py", line 311, in from_file_map
    minc_file = Minc1File(netcdf_file(fobj))
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 266, in __init__
    self._read()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 593, in _read
    self._read_var_array()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 682, in _read_var_array
    data.shape = shape
ValueError: cannot reshape array of size 0 into shape ()
======================================================================
ERROR: autogenerated test from validate_shape
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_api_validators.py", line 23, in meth
    validator(self, imaker, params)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 369, in validate_shape
    img = imaker()
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 451, in <lambda>
    yield lambda: self.loader(img_params['fname']), img_params
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/filebasedimages.py", line 260, in from_filename
    return klass.from_file_map(file_map)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/minc1.py", line 311, in from_file_map
    minc_file = Minc1File(netcdf_file(fobj))
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 266, in __init__
    self._read()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 593, in _read
    self._read_var_array()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 682, in _read_var_array
    data.shape = shape
ValueError: cannot reshape array of size 0 into shape ()
======================================================================
ERROR: autogenerated test from validate_shape_deprecated
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_api_validators.py", line 23, in meth
    validator(self, imaker, params)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 382, in validate_shape_deprecated
    img = imaker()
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_image_api.py", line 451, in <lambda>
    yield lambda: self.loader(img_params['fname']), img_params
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/filebasedimages.py", line 260, in from_filename
    return klass.from_file_map(file_map)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/minc1.py", line 311, in from_file_map
    minc_file = Minc1File(netcdf_file(fobj))
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 266, in __init__
    self._read()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 593, in _read
    self._read_var_array()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 682, in _read_var_array
    data.shape = shape
ValueError: cannot reshape array of size 0 into shape ()
======================================================================
ERROR: nibabel.tests.test_minc1.TestMinc1File.test_array_proxy_slicing
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_minc1.py", line 199, in test_array_proxy_slicing
    img = load(tp['fname'])
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/loadsave.py", line 45, in load
    img = image_klass.from_filename(filename, **kwargs)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/filebasedimages.py", line 260, in from_filename
    return klass.from_file_map(file_map)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/minc1.py", line 311, in from_file_map
    minc_file = Minc1File(netcdf_file(fobj))
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 266, in __init__
    self._read()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 593, in _read
    self._read_var_array()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 682, in _read_var_array
    data.shape = shape
ValueError: cannot reshape array of size 0 into shape ()
======================================================================
ERROR: nibabel.tests.test_minc1.TestMinc1File.test_compressed
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_minc1.py", line 221, in test_compressed
    img = self.module.load(fname)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/filebasedimages.py", line 260, in from_filename
    return klass.from_file_map(file_map)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/minc1.py", line 311, in from_file_map
    minc_file = Minc1File(netcdf_file(fobj))
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 266, in __init__
    self._read()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 593, in _read
    self._read_var_array()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 682, in _read_var_array
    data.shape = shape
ValueError: cannot reshape array of size 0 into shape ()
======================================================================
ERROR: nibabel.tests.test_minc1.TestMinc1File.test_load
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_minc1.py", line 186, in test_load
    img = load(tp['fname'])
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/loadsave.py", line 45, in load
    img = image_klass.from_filename(filename, **kwargs)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/filebasedimages.py", line 260, in from_filename
    return klass.from_file_map(file_map)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/minc1.py", line 311, in from_file_map
    minc_file = Minc1File(netcdf_file(fobj))
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 266, in __init__
    self._read()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 593, in _read
    self._read_var_array()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 682, in _read_var_array
    data.shape = shape
ValueError: cannot reshape array of size 0 into shape ()
======================================================================
ERROR: nibabel.tests.test_minc1.TestMinc1File.test_mincfile
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_minc1.py", line 157, in test_mincfile
    mnc_obj = self.opener(tp['fname'], 'r')
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 266, in __init__
    self._read()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 593, in _read
    self._read_var_array()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 677, in _read_var_array
    data.shape = shape
ValueError: cannot reshape array of size 0 into shape ()
======================================================================
ERROR: nibabel.tests.test_minc1.TestMinc1File.test_mincfile_slicing
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/builddir/build/BUILD/nibabel-2.2.0/nibabel/tests/test_minc1.py", line 169, in test_mincfile_slicing
    mnc_obj = self.opener(tp['fname'], 'r')
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 266, in __init__
    self._read()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 593, in _read
    self._read_var_array()
  File "/usr/lib64/python2.7/site-packages/scipy/io/netcdf.py", line 677, in _read_var_array
    data.shape = shape
ValueError: cannot reshape array of size 0 into shape ()
----------------------------------------------------------------------

This happens when I use numpy-1.13.3 and scipy-1.0.0.

I know that nibabel bundles that part of scipy, but I need to unbundle all libraries when packaging in Fedora.

@matthew-brett
Copy link
Member

Ouch - minimal reproducible example:

curl -L https://github.com/nipy/nibabel/blob/master/nibabel/tests/data/minc1-no-att.mnc?raw=true > minc1-no-att.mnc
python -c 'import scipy.io as sio; sio.netcdf_file("minc1-no-att.mnc")'

Would you consider putting in an issue to scipy ? I think this is a clash with netcdf and some recent changes to numpy.

@ignatenkobrain
Copy link
Author

@matthew-brett submitted, see linked issue.

@sanjayankur31
Copy link

The issue still persists in version 2.3.0.

@matthew-brett
Copy link
Member

You agree this is a scipy issue, not a nibabel issue?

@sanjayankur31
Copy link

I'm not entirely sure I'm afraid. There's a comment in the referenced scipy issue that speaks about the netcdf specification, and my knowledge of that is very very limited

@matthew-brett
Copy link
Member

I just mean that nibabel's copy does not raise this error, and I don't think you're suggesting that we should make nibabel do that, so the discussion should all be over at scipy. Or, do you disagree?

@sanjayankur31
Copy link

Yes, sure. If the test doesn't fail in your CI, can you please let us know what version of scipy/numpy it uses. nibabel 2.3.0 and scpiy 1.1.0/numpy 1.14.5 cause this error and these appear to be their latest versions.

@matthew-brett
Copy link
Member

matthew-brett commented Jun 22, 2018 via email

@matthew-brett
Copy link
Member

Sorry - bad typing on the phone. We vendor a copy of netcdf.py and we test against that. Luckily we do not have the fierce constraints that you guys do, in distribution packaging.

@sanjayankur31
Copy link

Ah, that makes sense. Should users also be suggested to use your copy then? I was simply using pip to test it out which uses the standard bits. I've bumped the issue on scipy too. I hope someone will have a few ideas on how to proceed.

@matthew-brett
Copy link
Member

That's odd, that it fails with pip, because we do, by default, use our own copy, and that should not cause the error. I just tried tests locally, they do not fail. Can you give more details about your setup?

@sanjayankur31
Copy link

That was me being dense. It does work in a fresh virtual env. I'll bisect scipy to see if I can narrow down when this regression was introduced. Thanks for the help. I reckon you can close the issue here if you want, or leave it open as a tracker while things get sorted out at the scipy end.

@sanjayankur31
Copy link

I reached out to the netcdf folks for help here. Quoting the relevant bits from the most recent post:

The file is corrupted. I ran it against ncvalidator and got the following 
errors.

% ncvalidator  minc1-no-att.mnc
Error - variable begin offset orders:
        var "rootvariable" begin offset (2840) is less than previous variable 
"study" end offset (6876)
File "minc1-no-att.mnc" fails to conform with classic CDF file format 
specifications

Running it against ncoffsets shows starting file offsets of all variables below.
% ncoffsets minc1-no-att.mnc 
netcdf minc1-no-att.mnc {
// file format: CDF-1

file header:
        size   = 2836 bytes
        extent = 6872 bytes

dimensions:
        zspace = 10
        yspace = 20
        xspace = 20

fixed-size variables:
        int    study:
               start file offset =        6872
               end   file offset =        6876
        int    rootvariable:
               start file offset =        2840
               end   file offset =        2844
        int    zspace:
               start file offset =        2844
               end   file offset =        2848
        int    yspace:
               start file offset =        2848
               end   file offset =        2852
        int    xspace:
               start file offset =        2852
               end   file offset =        2856
        double image-max:
               start file offset =        2856
               end   file offset =        2864
        double image-min:
               start file offset =        2864
               end   file offset =        2872
        byte   image(zspace, yspace, xspace):
               start file offset =        2872
               end   file offset =        6872
}


ncvalidator and ncoffsets are two utility programs available from PnetCDF 
package.
It can be compiled independently from PnetCDF with just gcc command.

I expect the nibabel netcdf code handles this situation, while the scipy.io version does not. Looking at the code now. I'm not sure what the right way of handling this is: should one flag the file as corrupt and not parse it, or should one parse it and assume that the offending variable has a size of 0 (or something similar?). I'll also ask the netcdf folks for suggestions on the thread once I've looked at the code etc.

@sanjayankur31
Copy link

I dropped a comment on the scipy ticket. I thought I'd drop one here too for others that may run into this later to see.

The MNIC files do not seem to be standard netcdf (or they extend netcdf?), they cannot be read by the latest standard netcdf tools (as the netcdf folks found when they tried to investigate the issue). Nibable includes custom tweaks to read them properly (this PR I reckon), but currently scipy does not include these. I think it'll be OK to include them in scipy too if these tweaks do not affect how standard netcdf files are read in anyway.

Thanks for the help. I expect we'll be able to tweak the Fedora package one way or another to get it to build properly depending on how the discussion on scipy goes.

@Dave-Allured
Copy link

Hello from netcdf-land. This issue got my attention. The file minc1-no-att.mnc in the nibabel test suite contains a netcdf-3 format violation, as described above. Therefore it is simply an invalid netcdf-3 file and does not belong in the test suite, unless you are testing for error detection, which is not the case here.

The netcdf-C library was upgraded some time recently to perform more consistency checks on internal file pointers. This is probably the source of these recent nibabel test failures.

I used netcdf low-level utilities to "repair" the internal pointer problem. I used a simple ncdump 4.4.1.1/ncgen sequence to preserve the original data contents. The repaired version is here. Note that only three bytes changed.

The scalar integer variable study was the target of the single invalid pointer. Therefore its intended data contents were ambiguous. I chose to retain the original binary file contents at the presumed "correct" offset in the original file. This happened to be a single integer of value "netcdf 32-bit default fill value". If needed, this choice could easily be revised.

Please replace the broken file version in your test suite with this repaired version, and see if this cleans up the test failures.

I suspect the message "cannot reshape array of size 0 into shape ()" is the result of the format violation causing a breakdown within the netcdf-python driver code, thus it should not be taken literally.

I do not otherwise suspect anything wrong with nibabel test code or scipy. Software should not be extended or tweaked to attempt to read files like this with format violations. Such attempts may be dangerous and result in hidden data corruption.

The other three MINC1 files within nibabel-master/nibabel/tests/data all seem to be valid netcdf-3 format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants