Skip to content

_ImageBaseHDU._get_scaled_image_data returns a raw data if bzero==0 and bscale==1 even though blank is not None#993

Closed
leejjoon wants to merge 1 commit into
astropy:masterfrom
leejjoon:memmap-blank
Closed

_ImageBaseHDU._get_scaled_image_data returns a raw data if bzero==0 and bscale==1 even though blank is not None#993
leejjoon wants to merge 1 commit into
astropy:masterfrom
leejjoon:memmap-blank

Conversation

@leejjoon
Copy link
Copy Markdown

This PR is to trigger discussion regarding the memmap support.

import astropy.io.fits as pyfits
f = pyfits.open("some.fits", memmap=True,
                do_not_scale_image_data=True)

With the above code, I expected f[0].data returns a memmap'd numpy array, but it does not for files w/ "BLANK" header values. And I think this is something that needed to be fixed.

I think there are a few ways to fix this.

  • As in this PR, just remove a check for the blank value.
  • introduce new keyword argument, e.g., ignore_blank.
  • do nothing, but update the docs so that people expect this behavior.

On the other hand, wouldn't it be good to have a method like get_raw_data (similar to _get_raw_data but with a simpler signature)?

@embray
Copy link
Copy Markdown
Member

embray commented Apr 17, 2013

Thanks for looking into this. This is not a problem just for BLANK, but also for BZERO and/or BSCALE (really, any header keywords that affect how the data should be read). I'm thinking maybe do_no_scale_image_data should include ignoring BLANK because for the most part you would want to ignore blanks replacement for the same reason you'd want to ignore BZERO/BSCALE--faster access to the raw data.

On the other hand, I have had in mind for a while (I think there's a Trac ticket for it somewhere) a special ndarray subclass of FITS images that incorporates all the scaling issues and can do so on a per-element basis (perhaps with optional caching of the results). That would allow this to work a little more transparently, even with mmap.

@mdboom
Copy link
Copy Markdown
Contributor

mdboom commented Apr 11, 2014

Related to #2307.

@embray embray self-assigned this Apr 11, 2014
@astrofrog astrofrog assigned embray and unassigned embray Mar 21, 2015
@embray
Copy link
Copy Markdown
Member

embray commented Aug 31, 2015

Just remembered about this PR. As @mdboom wrote #2307 added the suggested ignore_blank keyword. And #3865 made further significant improvements to how the BLANK keyword is handled (including also excluding it when do_not_scale_image_data=True, and also properly writing blank values on output).

On the other hand, wouldn't it be good to have a method like get_raw_data (similar to _get_raw_data but with a simpler signature)?

I think a .raw_data attribute would be good to have on a per-HDU basis (no messing around with do_not_scale_image_data). As my prior comment wrote the ideal is some kind of container class for FITS data, but in the meantime a .raw_data attribute might be useful. I'll open a separate issue about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants