Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6f1950b

Browse files
committedSep 9, 2023
bugfix, but leaves open a question: do the min/max first/last make sense with background matching?
1 parent b2130fb commit 6f1950b

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
@@ -315,6 +315,7 @@ def reproject_and_coadd(
315315

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

331332
elif combine_function in ("first", "last", "min", "max"):
332-
for array in arrays:
333-
if combine_function == "first":
334-
mask = output_footprint[array.view_in_original_array] == 0
335-
elif combine_function == "last":
336-
mask = array.footprint > 0
337-
elif combine_function == "min":
338-
mask = (array.footprint > 0) & (
339-
array.array < output_array[array.view_in_original_array]
333+
if match_background:
334+
for array in arrays:
335+
if combine_function == "first":
336+
mask = output_footprint[array.view_in_original_array] == 0
337+
elif combine_function == "last":
338+
mask = array.footprint > 0
339+
elif combine_function == "min":
340+
mask = (array.footprint > 0) & (
341+
array.array < output_array[array.view_in_original_array]
342+
)
343+
elif combine_function == "max":
344+
mask = (array.footprint > 0) & (
345+
array.array > output_array[array.view_in_original_array]
346+
)
347+
348+
output_footprint[array.view_in_original_array] = np.where(
349+
mask, array.footprint, output_footprint[array.view_in_original_array]
340350
)
341-
elif combine_function == "max":
342-
mask = (array.footprint > 0) & (
343-
array.array > output_array[array.view_in_original_array]
351+
output_array[array.view_in_original_array] = np.where(
352+
mask, array.array, output_array[array.view_in_original_array]
344353
)
345354

346-
output_footprint[array.view_in_original_array] = np.where(
347-
mask, array.footprint, output_footprint[array.view_in_original_array]
348-
)
349-
output_array[array.view_in_original_array] = np.where(
350-
mask, array.array, output_array[array.view_in_original_array]
351-
)
352-
353355
elif combine_function == "median":
354356
# Here we need to operate in chunks since we could otherwise run
355357
# into memory issues

0 commit comments

Comments
 (0)