Skip to content

Commit ba28206

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

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

reproject/mosaicking/coadd.py

+20-18
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
@@ -339,27 +340,28 @@ def reproject_and_coadd(
339340
output_array[output_footprint == 0] = 0
340341

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

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

0 commit comments

Comments
 (0)