reproject icon indicating copy to clipboard operation
reproject copied to clipboard

Blank pixels should be set to ...

Open keflavich opened this issue 1 year ago • 1 comments

Before #413, pixels that were not covered by the footprint were set to nan, and they are now set to zero.

https://github.com/astropy/reproject/commit/31c420533e4c86b0e44b988485f1f87dd7bf8ac5

I have a lot of code that relied on the nan behavior, even though it apparently only affected the mean combination, so this was a major behavior change from my side.

I recommend we make the blank pixel value explicit and user-specifiable. I have a commit that suggests that, but I'm experiencing network issues, so I'll just paste the diff here:

--- a/reproject/mosaicking/coadd.py
+++ b/reproject/mosaicking/coadd.py
@@ -26,6 +26,7 @@ def reproject_and_coadd(
     output_footprint=None,
     block_sizes=None,
     progressbar=False,
+    blank_pixel_value=np.nan,
     **kwargs,
 ):
     """
@@ -337,7 +338,7 @@ def reproject_and_coadd(
         if combine_function == "mean":
             with np.errstate(invalid="ignore"):
                 output_array /= output_footprint
-                output_array[output_footprint == 0] = 0
+                output_array[output_footprint == 0] = blank_pixel_value

     elif combine_function in ("first", "last", "min", "max"):
         if match_background:
@@ -369,7 +370,6 @@ def reproject_and_coadd(
         # this is redundant, but left as a note-to-devs about where such an implementation belongs
         raise NotImplementedError("combine_function='median' is not yet implemented")

-    if combine_function in ("min", "max"):
-        output_array[output_footprint == 0] = 0.0
+    output_array[output_footprint == 0] = blank_pixel_value

keflavich avatar Feb 12 '24 02:02 keflavich

relevant commit: https://github.com/keflavich/python-reprojection/commit/0054941132ae0209e40f1290c8afee46a3c87f2d

keflavich avatar Feb 12 '24 14:02 keflavich

Fixed in https://github.com/astropy/reproject/pull/351

astrofrog avatar Jun 13 '24 10:06 astrofrog