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

FITS objects created with fromstring have problems? #2710

Merged
merged 1 commit into from Sep 17, 2014

Conversation

embray
Copy link
Member

@embray embray commented Sep 16, 2014

I have some FITS objects being created from strings. I can't access their data attribute. I think it has to do with _orig_bitpix being negative, possibly, but I'm not sure. @embray any thoughts? I can provide an example if needed.

In [32]: blah._orig_bitpix
Out[32]: -32

In [33]: blah.data
Traceback (most recent call last):
  File "<ipython-input-33-dd8ff7218a27>", line 1, in <module>
    blah.data
  File "/Users/adam/repos/astropy/astropy/utils/misc.py", line 286, in __get__
    val = self._fget(obj)
  File "/Users/adam/repos/astropy/astropy/io/fits/hdu/image.py", line 218, in data
    data = self._get_scaled_image_data(self._data_offset, self.shape)
  File "/Users/adam/repos/astropy/astropy/io/fits/hdu/image.py", line 594, in _get_scaled_image_data
    if self._file.memmap:
AttributeError: 'NoneType' object has no attribute 'memmap'

> /Users/adam/repos/astropy/astropy/io/fits/hdu/image.py(594)_get_scaled_image_data()
    593             else:  # floating point cases
--> 594                 if self._file.memmap:
    595                     data = raw_data.copy()

@embray embray added this to the v0.4.1 milestone Jul 9, 2014
@embray
Copy link
Member

embray commented Jul 9, 2014

That's likely--it looks like it's going down a code path there which doesn't properly support the case of FITS files read from memory buffers (as is the case for fromstring). Should be an easy fix.

@embray embray added the easy label Jul 9, 2014
embray added a commit to embray/astropy that referenced this pull request Sep 16, 2014
@embray
Copy link
Member

embray commented Sep 16, 2014

Attached a PR that should fix this.

if self._file is not None and self._file.memmap:
data = raw_data.copy()
elif not raw_data.flags.writeable:
# create a writeable copy of needed
Copy link
Contributor

Choose a reason for hiding this comment

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

Should that be 'if needed' ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, but I'm not going to push another commit just to fix a one letter typo in a comment :) It'll be fixed elsewhen.

embray added a commit that referenced this pull request Sep 17, 2014
FITS objects created with `fromstring` have problems?
@embray embray merged commit 70891e4 into astropy:master Sep 17, 2014
@embray embray deleted the fits/issue-2710 branch September 17, 2014 13:47
embray added a commit that referenced this pull request Sep 18, 2014
FITS objects created with `fromstring` have problems?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants