Skip to content

Commit

Permalink
pywwt/utils.py: work around reproject bug with BLANK keyword
Browse files Browse the repository at this point in the history
See astropy/reproject#475 . This should of
course be fixed upstream, but in the meantime, we can avoid the issue.
  • Loading branch information
pkgw committed Oct 16, 2024
1 parent 552671d commit 9d1e623
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pywwt/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import pytz
from astropy.io import fits
from astropy.io.fits import CompImageHDU, ImageHDU, PrimaryHDU
from astropy.coordinates import ICRS
from astropy.time import Time
from datetime import datetime
Expand Down Expand Up @@ -49,8 +50,27 @@ def transform_to_wwt_supported_fits(image, output_file, overwrite):
with warnings.catch_warnings():
# Sorry, Astropy, no one cares if you fixed the FITS.
warnings.simplefilter("ignore")

# Inner workaround: as of October 2024, `reproject` will crash with
# integer-valued images that have the "BLANK" keyword set:
# https://github.com/astropy/reproject/issues/475 . This issue should of
# course be fixed upstream, but a fix will take a while to propagate
# through the ecosystem. In the meantime, fiddle with things to avoid
# the issue if it looks like it might be relevant.
do_blank_workaround = (
isinstance(image, PrimaryHDU | ImageHDU | CompImageHDU)
and image.header.get("BLANK") is not None
and hasattr(image, "_data_replaced")
)
if do_blank_workaround:
old_data_replaced = image._data_replaced
image._data_replaced = True

data, wcs = parse_input_data(image)

if do_blank_workaround:
image._data_replaced = old_data_replaced

if wcs.naxis != 2:
if not wcs.has_celestial:
raise Exception(
Expand Down

0 comments on commit 9d1e623

Please sign in to comment.