Skip to content

Commit

Permalink
Implement new combine function to compute the two dimensional maximum…
Browse files Browse the repository at this point in the history
… map over all co-added arrays. This is useful for PSF calculations, for instance.
  • Loading branch information
astrofrog committed Sep 7, 2023
1 parent 661963d commit a2cb8cb
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions reproject/mosaicking/coadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def reproject_and_coadd(
`~astropy.io.fits.HDUList` instance, specifies the HDU to use.
reproject_function : callable
The function to use for the reprojection
combine_function : { 'mean', 'sum', 'median', 'first', 'last' }
combine_function : { 'mean', 'sum', 'median', 'first', 'last', 'max' }
The type of function to use for combining the values into the final
image. For 'first' and 'last', respectively, the reprojected images are
simply overlaid on top of each other. With respect to the order of the
Expand All @@ -97,8 +97,8 @@ def reproject_and_coadd(

# Validate inputs

if combine_function not in ("mean", "sum", "median", "first", "last"):
raise ValueError("combine_function should be one of mean/sum/median/first/last")
if combine_function not in ("mean", "sum", "median", "first", "last", "max"):
raise ValueError("combine_function should be one of mean/sum/median/first/last/max")

Check warning on line 101 in reproject/mosaicking/coadd.py

View check run for this annotation

Codecov / codecov/patch

reproject/mosaicking/coadd.py#L101

Added line #L101 was not covered by tests

if reproject_function is None:
raise ValueError(
Expand Down Expand Up @@ -253,6 +253,16 @@ def reproject_and_coadd(
final_array[array.view_in_original_array] = np.where(
array.footprint > 0, array.array, final_array[array.view_in_original_array]
)
elif combine_function == "max":
for array in arrays:
array.array[array.footprint == 0] = 0

Check warning on line 258 in reproject/mosaicking/coadd.py

View check run for this annotation

Codecov / codecov/patch

reproject/mosaicking/coadd.py#L256-L258

Added lines #L256 - L258 were not covered by tests

old_vals = final_array[array.view_in_original_array]
new_vals = array.array * array.footprint

Check warning on line 261 in reproject/mosaicking/coadd.py

View check run for this annotation

Codecov / codecov/patch

reproject/mosaicking/coadd.py#L260-L261

Added lines #L260 - L261 were not covered by tests

final_array[array.view_in_original_array] = np.maximum(old_vals, new_vals)
final_footprint[array.view_in_original_array] += array.footprint

Check warning on line 264 in reproject/mosaicking/coadd.py

View check run for this annotation

Codecov / codecov/patch

reproject/mosaicking/coadd.py#L263-L264

Added lines #L263 - L264 were not covered by tests

elif combine_function == "median":
# Here we need to operate in chunks since we could otherwise run
# into memory issues
Expand Down

0 comments on commit a2cb8cb

Please sign in to comment.