Skip to content

Commit

Permalink
bugfix, but leaves open a question: do the min/max first/last make se…
Browse files Browse the repository at this point in the history
…nse with background matching?
  • Loading branch information
keflavich committed Sep 9, 2023
1 parent b2130fb commit 6f1950b
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions reproject/mosaicking/coadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def reproject_and_coadd(

if combine_function in ("mean", "sum"):
if match_background:
# if we're not matching the background, this part has already been done
for array in arrays:
# By default, values outside of the footprint are set to NaN
# but we set these to 0 here to avoid getting NaNs in the
Expand All @@ -329,27 +330,28 @@ def reproject_and_coadd(
output_array /= output_footprint

elif combine_function in ("first", "last", "min", "max"):
for array in arrays:
if combine_function == "first":
mask = output_footprint[array.view_in_original_array] == 0
elif combine_function == "last":
mask = array.footprint > 0
elif combine_function == "min":
mask = (array.footprint > 0) & (
array.array < output_array[array.view_in_original_array]
if match_background:
for array in arrays:
if combine_function == "first":
mask = output_footprint[array.view_in_original_array] == 0
elif combine_function == "last":
mask = array.footprint > 0
elif combine_function == "min":
mask = (array.footprint > 0) & (

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

View check run for this annotation

Codecov / codecov/patch

reproject/mosaicking/coadd.py#L334-L340

Added lines #L334 - L340 were not covered by tests
array.array < output_array[array.view_in_original_array]
)
elif combine_function == "max":
mask = (array.footprint > 0) & (

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

View check run for this annotation

Codecov / codecov/patch

reproject/mosaicking/coadd.py#L343-L344

Added lines #L343 - L344 were not covered by tests
array.array > output_array[array.view_in_original_array]
)

output_footprint[array.view_in_original_array] = np.where(

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

View check run for this annotation

Codecov / codecov/patch

reproject/mosaicking/coadd.py#L348

Added line #L348 was not covered by tests
mask, array.footprint, output_footprint[array.view_in_original_array]
)
elif combine_function == "max":
mask = (array.footprint > 0) & (
array.array > output_array[array.view_in_original_array]
output_array[array.view_in_original_array] = np.where(

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

View check run for this annotation

Codecov / codecov/patch

reproject/mosaicking/coadd.py#L351

Added line #L351 was not covered by tests
mask, array.array, output_array[array.view_in_original_array]
)

output_footprint[array.view_in_original_array] = np.where(
mask, array.footprint, output_footprint[array.view_in_original_array]
)
output_array[array.view_in_original_array] = np.where(
mask, array.array, output_array[array.view_in_original_array]
)

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 6f1950b

Please sign in to comment.