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

Cannot allocate memory #299

Merged
merged 2 commits into from May 19, 2016

Conversation

keflavich
Copy link
Contributor

Trying to load a cube, I've encountered the following error:
error: [Errno 12] Cannot allocate memory

Unfortunately, this defeats the purpose of spectral-cube entirely. Any ideas for workarounds? In principle, we might be able to write up an interface that can load only part of the cube, but I don't know how to do that with the FITS io system.

@keflavich
Copy link
Contributor Author

Example traceback:

In [19]: fits.open('full_W51_7m12m_spw0_hires_lines.fits')[0].data.shape
Traceback (most recent call last):
  File "<ipython-input-19-f94477ee2d18>", line 1, in <module>
    fits.open('full_W51_7m12m_spw0_hires_lines.fits')[0].data.shape
  File "/diskb/aginsbur/repos/astropy/astropy/utils/decorators.py", line 498, in __get__
    val = self.fget(obj)
  File "/diskb/aginsbur/repos/astropy/astropy/io/fits/hdu/image.py", line 208, in data
    data = self._get_scaled_image_data(self._data_offset, self.shape)
  File "/diskb/aginsbur/repos/astropy/astropy/io/fits/hdu/image.py", line 621, in _get_scaled_image_data
    raw_data = self._get_raw_data(shape, code, offset)
  File "/diskb/aginsbur/repos/astropy/astropy/io/fits/hdu/base.py", line 568, in _get_raw_data
    return self._file.readarray(offset=offset, dtype=code, shape=shape)
  File "/diskb/aginsbur/repos/astropy/astropy/io/fits/file.py", line 268, in readarray
    dtype=np.uint8)
  File "/home/aginsbur/anaconda/lib/python2.7/site-packages/numpy/core/memmap.py", line 260, in __new__
    mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=start)
error: [Errno 12] Cannot allocate memory

@keflavich
Copy link
Contributor Author

Solution is here: astropy/astropy#1380 (comment)

@keflavich
Copy link
Contributor Author

This has led to a new error:

In [7]: fits.open('full_W51_7m12m_spw1_hires_lines.fits')[0].data.shape
Traceback (most recent call last):
  File "<ipython-input-7-0459cfea92b3>", line 1, in <module>
    fits.open('full_W51_7m12m_spw1_hires_lines.fits')[0].data.shape
  File "/diskb/aginsbur/repos/astropy/astropy/utils/decorators.py", line 498, in __get__
    val = self.fget(obj)
  File "/diskb/aginsbur/repos/astropy/astropy/io/fits/hdu/image.py", line 208, in data
    data = self._get_scaled_image_data(self._data_offset, self.shape)
  File "/diskb/aginsbur/repos/astropy/astropy/io/fits/hdu/image.py", line 621, in _get_scaled_image_data
    raw_data = self._get_raw_data(shape, code, offset)
  File "/diskb/aginsbur/repos/astropy/astropy/io/fits/hdu/base.py", line 568, in _get_raw_data
    return self._file.readarray(offset=offset, dtype=code, shape=shape)
  File "/diskb/aginsbur/repos/astropy/astropy/io/fits/file.py", line 283, in readarray
    buffer=self._mmap)
TypeError: buffer is too small for requested array

In [8]: fits.open('full_W51_7m12m_spw1_hires_lines.fits', mode='denywrite')[0].data.shape
Traceback (most recent call last):
  File "<ipython-input-8-95c009e12b4b>", line 1, in <module>
    fits.open('full_W51_7m12m_spw1_hires_lines.fits', mode='denywrite')[0].data.shape
  File "/diskb/aginsbur/repos/astropy/astropy/utils/decorators.py", line 498, in __get__
    val = self.fget(obj)
  File "/diskb/aginsbur/repos/astropy/astropy/io/fits/hdu/image.py", line 208, in data
    data = self._get_scaled_image_data(self._data_offset, self.shape)
  File "/diskb/aginsbur/repos/astropy/astropy/io/fits/hdu/image.py", line 621, in _get_scaled_image_data
    raw_data = self._get_raw_data(shape, code, offset)
  File "/diskb/aginsbur/repos/astropy/astropy/io/fits/hdu/base.py", line 568, in _get_raw_data
    return self._file.readarray(offset=offset, dtype=code, shape=shape)
  File "/diskb/aginsbur/repos/astropy/astropy/io/fits/file.py", line 283, in readarray
    buffer=self._mmap)
TypeError: buffer is too small for requested array

@keflavich
Copy link
Contributor Author

The change broke the tests because the tests are using direct file modification, which isn't supported. Shouldn't be too hard to fix.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 72.695% when pulling e82b66a on keflavich:huge-file-issue299 into c09ac14 on radio-astro-tools:master.

@@ -44,7 +44,7 @@ def is_fits(input, **kwargs):
return False


def read_data_fits(input, hdu=None, **kwargs):
def read_data_fits(input, hdu=None, mode='denywrite', **kwargs):
Copy link
Contributor

@e-koch e-koch May 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't mode passed through kwargs from SpectralCube.read to here already? I regularly use mode='denywrite' and haven't run into memory issues when dealing with big cubes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. But I think this should be the default, as we don't expect users to be modifying the cube data inplace.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok. Agreed.

@keflavich keflavich merged commit 2c6575f into radio-astro-tools:master May 19, 2016
@keflavich keflavich deleted the huge-file-issue299 branch May 19, 2016 15:44
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

Successfully merging this pull request may close these issues.

None yet

3 participants