Skip to content

Commit

Permalink
Add 'first' and 'last' modes for mosaicking
Browse files Browse the repository at this point in the history
  • Loading branch information
svank committed Aug 26, 2023
1 parent 09f2adc commit 9c67c9f
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions reproject/mosaicking/tests/test_coadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from astropy.io import fits
from astropy.io.fits import Header
from astropy.wcs import WCS
from numpy.testing import assert_allclose
from numpy.testing import assert_allclose, assert_equal

from reproject import reproject_exact, reproject_interp
from reproject.mosaicking.coadd import reproject_and_coadd
Expand Down Expand Up @@ -73,7 +73,7 @@ def _overlapping_views(self):

return views

@pytest.mark.parametrize("combine_function", ["mean", "sum"])
@pytest.mark.parametrize("combine_function", ["mean", "sum", "first", "last"])
def test_coadd_no_overlap(self, combine_function, reproject_function):
# Make sure that if all tiles are exactly non-overlapping, and
# we use 'sum' or 'mean', we get the exact input array back.
Expand Down Expand Up @@ -108,6 +108,38 @@ def test_coadd_with_overlap(self, reproject_function):

assert_allclose(array, self.array, atol=ATOL)

@pytest.mark.parametrize("combine_function", ["first", "last"])
def test_coadd_with_overlap_first_last(self, reproject_function, combine_function):
views = self._overlapping_views
input_data = self._get_tiles(views)

# Make each of the overlapping tiles different
for i, (array, wcs) in enumerate(input_data):
input_data[i] = (np.full_like(array, i), wcs)

array, footprint = reproject_and_coadd(
input_data,
self.wcs,
shape_out=self.array.shape,
combine_function=combine_function,
reproject_function=reproject_function,
)

# Test that either the correct tile sets the output value in the overlap regions
test_sequence = list(enumerate(views))
if combine_function == "last":
test_sequence = test_sequence[::-1]
for i, view in test_sequence:
# Each tile in test_sequence should overwrite teh following tiles
# in the overlap regions. We'll use nans to mark pixels in the
# output array that have already been set by a preceeding tile, so
# we'll go through, check that each tile matches the non-nan pixels
# in its region, and then set that whole region to nan.
output_tile = array[view]
output_values = output_tile[np.isfinite(output_tile)]
assert_equal(output_values, i)
array[view] = np.nan

def test_coadd_background_matching(self, reproject_function):
# Test out the background matching

Expand Down

0 comments on commit 9c67c9f

Please sign in to comment.