Skip to content

Commit d1319d1

Browse files
committed
bugfix, but leaves open a question: do the min/max first/last make sense with background matching?
1 parent 318763b commit d1319d1

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

reproject/mosaicking/coadd.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ def reproject_and_coadd(
324324

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

340341
elif combine_function in ("first", "last", "min", "max"):
341-
for array in arrays:
342-
if combine_function == "first":
343-
mask = output_footprint[array.view_in_original_array] == 0
344-
elif combine_function == "last":
345-
mask = array.footprint > 0
346-
elif combine_function == "min":
347-
mask = (array.footprint > 0) & (
348-
array.array < output_array[array.view_in_original_array]
342+
if match_background:
343+
for array in arrays:
344+
if combine_function == "first":
345+
mask = output_footprint[array.view_in_original_array] == 0
346+
elif combine_function == "last":
347+
mask = array.footprint > 0
348+
elif combine_function == "min":
349+
mask = (array.footprint > 0) & (
350+
array.array < output_array[array.view_in_original_array]
351+
)
352+
elif combine_function == "max":
353+
mask = (array.footprint > 0) & (
354+
array.array > output_array[array.view_in_original_array]
355+
)
356+
357+
output_footprint[array.view_in_original_array] = np.where(
358+
mask, array.footprint, output_footprint[array.view_in_original_array]
349359
)
350-
elif combine_function == "max":
351-
mask = (array.footprint > 0) & (
352-
array.array > output_array[array.view_in_original_array]
360+
output_array[array.view_in_original_array] = np.where(
361+
mask, array.array, output_array[array.view_in_original_array]
353362
)
354363

355-
output_footprint[array.view_in_original_array] = np.where(
356-
mask, array.footprint, output_footprint[array.view_in_original_array]
357-
)
358-
output_array[array.view_in_original_array] = np.where(
359-
mask, array.array, output_array[array.view_in_original_array]
360-
)
361-
362364
elif combine_function == "median":
363365
# Here we need to operate in chunks since we could otherwise run
364366
# into memory issues

0 commit comments

Comments
 (0)