Skip to content

Commit

Permalink
DOC: update docstrings for ignore_blank, writeto()
Browse files Browse the repository at this point in the history
  • Loading branch information
dhomeier committed Jun 29, 2024
1 parent 90fa6c8 commit 28a530b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
8 changes: 4 additions & 4 deletions astropy/io/fits/hdu/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def readfrom(cls, fileobj, checksum=False, ignore_missing_end=False, **kwargs):
def writeto(self, name, output_verify="exception", overwrite=False, checksum=False):
"""
Write the HDU to a new file. This is a convenience method to
provide a user easier output interface if only one HDU needs
provide a user friendly output interface if only one HDU needs
to be written to a file.
Parameters
Expand Down Expand Up @@ -1600,9 +1600,9 @@ def match_header(cls, header):

def writeto(self, name, output_verify="exception", overwrite=False, checksum=False):
"""
Works similarly to the normal writeto(), but prepends a default
`PrimaryHDU` are required by extension HDUs (which cannot stand on
their own).
Works similarly to :func:`_BaseHDU.writeto`, but prepends a default
`PrimaryHDU` as required by extension HDUs (which cannot be written
on their own).
"""
from .hdulist import HDUList
from .image import PrimaryHDU
Expand Down
6 changes: 3 additions & 3 deletions astropy/io/fits/hdu/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,9 +779,9 @@ def _convert_pseudo_integer(self, data):
Handle "pseudo-unsigned" integers, if the user requested it. Returns
the converted data array if so; otherwise returns None.
In this case case, we don't need to handle BLANK to convert it to NAN,
since we can't do NaNs with integers, anyway, i.e. the user is
responsible for managing blanks.
Handling of BLANK is done outside of this function on the converted
uint data, meaning that BLANK needs to be shifted by BZERO as well
before conversion of the corresponding values to NaN.
"""
dtype = self._dtype_for_bitpix()
# bool(dtype) is always False--have to explicitly compare to None; this
Expand Down
8 changes: 4 additions & 4 deletions astropy/io/fits/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ def test_uint_header_keywords_removed_after_bitpix_change(
@pytest.mark.parametrize(("ignore_blank"), (False, True))
def test_blanks(self, ext, ignore_blank):
"""Test image data with blank spots in it (which should show up as
NaNs in the data array, unless 'ignore_blank' is set).
NaNs in the data array, unless ignore_blank is set to True).
"""

arr = np.zeros((10, 10), dtype=np.int32)
Expand All @@ -768,12 +768,12 @@ def test_blanks(self, ext, ignore_blank):
hdu = fits.PrimaryHDU(data=arr)
else:
hdu = fits.ImageHDU(data=arr)
hdu.header["BLANK"] = 999
hdu.header["BLANK"] = 99999
hdu.writeto(self.temp("test_blank.fits"))

with fits.open(self.temp("test_blank.fits"), ignore_blank=ignore_blank) as hdul:
if ignore_blank:
assert hdul[ext].data.dtype == '>i4'
assert hdul[ext].data.dtype == ">i4"
assert (hdul[ext].data[1] == hdu.header["BLANK"]).all()
else:
assert hdul[ext].data.dtype == np.float64
Expand All @@ -783,7 +783,7 @@ def test_blanks(self, ext, ignore_blank):
@pytest.mark.parametrize(("ignore_blank"), (False, True))
def test_uint_blanks(self, ext, ignore_blank):
"""Test uint image data with blank spots in it (should be controlled
by 'ignore_blank' in the same way as for unscaled integers).
by ignore_blank in the same way as for unscaled integers).
"""

arr = np.arange(100, dtype=np.uint16).reshape((10, 10))
Expand Down
4 changes: 4 additions & 0 deletions docs/changes/io.fits/16636.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix handling of ``ignore_blank`` keyword for uncompressed integer data.
Set to True, will keep original integer data with 'BLANK' values,
to False, convert to float with NaNs, for both signed and unsigned
integers, and primary as well as extension HDUs.

0 comments on commit 28a530b

Please sign in to comment.