Skip to content

Commit

Permalink
Make Gaussian kernel default for adaptive resampling
Browse files Browse the repository at this point in the history
While this kernel introduces some slight blurring of the output image,
it significantly enhances the anti-aliasing properties that this
algorithm touts.
  • Loading branch information
svank committed May 21, 2022
1 parent 7f20896 commit 4a6f1b8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
16 changes: 8 additions & 8 deletions docs/celestial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ kernel---see below.)

The kernel used for interpolation and averaging can be controlled with a set of
options. The ``kernel`` argument can be set to 'hann' or 'gaussian' to set the
function being used. The Hann window is the default, and the Gaussian window
improves anti-aliasing and photometric accuracy (or flux conservation, when the
flux-conserving mode is enabled) at the cost of blurring the output image by a
few pixels. The ``kernel_width`` argument sets the width of the Gaussian
kernel, in pixels, and is ignored for the Hann window. This width is measured
between the Gaussian's :math:`\pm 1 \sigma` points. The default value is 1.3
for the Gaussian, chosen to minimize blurring without compromising accuracy.
Lower values may introduce photometric errors or leave input pixels
function being used. The Gaussian window is the default, as it provides better
anti-aliasing and photometric accuracy (or flux conservation, when the
flux-conserving mode is enabled), though at the cost of blurring the output
image by a few pixels. The ``kernel_width`` argument sets the width of the
Gaussian kernel, in pixels, and is ignored for the Hann window. This width is
measured between the Gaussian's :math:`\pm 1 \sigma` points. The default value
is 1.3 for the Gaussian, chosen to minimize blurring without compromising
accuracy. Lower values may introduce photometric errors or leave input pixels
under-sampled, while larger values may improve anti-aliasing behavior but will
increase blurring of the output image. Since the Gaussian function has infinite
extent, it must be truncated. This is done by sampling within a region of
Expand Down
Binary file added docs/msx_on_2mass_header.fits
Binary file not shown.
5 changes: 3 additions & 2 deletions reproject/adaptive/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __call__(self, pixel_out):
def _reproject_adaptive_2d(array, wcs_in, wcs_out, shape_out,
return_footprint=True, center_jacobian=False,
roundtrip_coords=True, conserve_flux=False,
kernel='Hann', kernel_width=1.3,
kernel='gaussian', kernel_width=1.3,
sample_region_width=4):
"""
Reproject celestial slices from an n-d array from one WCS to another
Expand Down Expand Up @@ -105,7 +105,8 @@ def _reproject_adaptive_2d(array, wcs_in, wcs_out, shape_out,

transformer = CoordinateTransformer(wcs_in, wcs_out, roundtrip_coords)
map_coordinates(array_in, array_out, transformer, out_of_range_nan=True,
center_jacobian=center_jacobian, conserve_flux=conserve_flux,
center_jacobian=center_jacobian,
conserve_flux=conserve_flux,
kernel=kernel, kernel_width=kernel_width,
sample_region_width=sample_region_width)

Expand Down
4 changes: 2 additions & 2 deletions reproject/adaptive/deforest.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ KERNELS['gaussian'] = 1
def map_coordinates(double[:,:] source, double[:,:] target, Ci, int max_samples_width=-1,
int conserve_flux=False, int progress=False, int singularities_nan=False,
int x_cyclic=False, int y_cyclic=False, int out_of_range_nan=False,
bint center_jacobian=False, str kernel='Hann', double kernel_width=1.3,
double sample_region_width=4):
bint center_jacobian=False, str kernel='gaussian',
double kernel_width=1.3, double sample_region_width=4):
cdef int kernel_flag
try:
kernel_flag = KERNELS[kernel.lower()]
Expand Down
3 changes: 2 additions & 1 deletion reproject/adaptive/high_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
def reproject_adaptive(input_data, output_projection, shape_out=None, hdu_in=0,
return_footprint=True, center_jacobian=False,
roundtrip_coords=True, conserve_flux=False,
kernel='Hann', kernel_width=1.3, sample_region_width=4):
kernel='gaussian', kernel_width=1.3,
sample_region_width=4):
"""
Reproject a 2D array from one WCS to another using the DeForest (2004)
adaptive, anti-aliased resampling algorithm, with optional flux
Expand Down
10 changes: 6 additions & 4 deletions reproject/adaptive/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def test_reproject_adaptive_2d(wcsapi, center_jacobian, roundtrip_coords):
array_out, footprint_out = reproject_adaptive(
(data_in, wcs_in), wcs_out, shape_out=(60, 60),
center_jacobian=center_jacobian,
roundtrip_coords=roundtrip_coords)
roundtrip_coords=roundtrip_coords,
kernel='hann')

# Check that surface brightness is conserved in the unrotated case
assert_allclose(np.nansum(data_in), np.nansum(array_out) * (256 / 60) ** 2, rtol=0.1)
Expand Down Expand Up @@ -92,7 +93,8 @@ def test_reproject_adaptive_2d_rotated(center_jacobian, roundtrip_coords):
array_out, footprint_out = reproject_adaptive(
(data_in, wcs_in), wcs_out, shape_out=(60, 60),
center_jacobian=center_jacobian,
roundtrip_coords=roundtrip_coords)
roundtrip_coords=roundtrip_coords,
kernel='hann')

# ASTROPY_LT_40: astropy v4.0 introduced new default header keywords,
# once we support only astropy 4.0 and later we can update the reference
Expand Down Expand Up @@ -352,7 +354,7 @@ def test_reproject_adaptive_roundtrip(file_format):
data, wcs, target_wcs = prepare_test_data(file_format)

output, footprint = reproject_adaptive((data, wcs), target_wcs, (128, 128),
center_jacobian=True)
center_jacobian=True, kernel='hann')

header_out = target_wcs.to_header()

Expand All @@ -378,7 +380,7 @@ def test_reproject_adaptive_uncentered_jacobian():
data, wcs, target_wcs = prepare_test_data('fits')

output, footprint = reproject_adaptive((data, wcs), target_wcs, (128, 128),
center_jacobian=False)
center_jacobian=False, kernel='hann')

header_out = target_wcs.to_header()

Expand Down

0 comments on commit 4a6f1b8

Please sign in to comment.