TukeyWindow#

class photutils.psf_matching.TukeyWindow(alpha)[source]#

Bases: SplitCosineBellWindow

Class to define a 2D Tukey window function.

The Tukey window features a flat inner plateau equal to 1.0, surrounded by a smooth cosine taper that transitions to 0.0 at the edges. This provides an excellent balance between preserving data in the central region and suppressing edge artifacts.

The alpha parameter controls the trade-off. Smaller values preserve more data but create stronger edge effects, while larger values reduce artifacts but taper more of the image.

Compared to HanningWindow, Tukey preserves a larger central region. Compared to TopHatWindow, it provides much better artifact suppression at the cost of tapering the outer regions.

Parameters:
alphafloat

The width of the cosine taper as a fraction of the maximum radius. The maximum radius is the distance in pixels from the array center to the edge, which is (n - 1) / 2 along an axis of size n. For a nonsquare shape, it differs between the two axes, so the window is elliptical. Must be between 0.0 and 1.0, inclusive. When alpha=0, this becomes a TopHatWindow. When alpha=1, this becomes a HanningWindow.

Raises:
ValueError

If alpha is not between 0.0 and 1.0, inclusive.

Notes

Equivalent to SplitCosineBellWindow(alpha=alpha, beta=1.0 - alpha).

Examples

import matplotlib.pyplot as plt
from photutils.psf_matching import TukeyWindow

taper = TukeyWindow(alpha=0.4)
data = taper((101, 101))
fig, ax = plt.subplots()
axim = ax.imshow(data, origin='lower')
fig.colorbar(axim)

(Source code, png, hires.png, pdf, svg)

../_images/photutils-psf_matching-TukeyWindow-1.png

A 1D cut across the image center:

import matplotlib.pyplot as plt
from photutils.psf_matching import TukeyWindow

taper = TukeyWindow(alpha=0.4)
data = taper((101, 101))
fig, ax = plt.subplots()
ax.plot(data[50, :])

(Source code, png, hires.png, pdf, svg)

../_images/photutils-psf_matching-TukeyWindow-2.png

Methods Summary

__call__(shape)

Generate the window function for the given shape.

Methods Documentation

__call__(shape)#

Generate the window function for the given shape.

Parameters:
shapetuple of int

The shape of the output array. It must have two elements. The window radii are defined relative to (n - 1) / 2 along each axis of size n, so the window is elliptical for a nonsquare shape. When the window is applied to a Fourier transform, it then has the same cutoff in spatial frequency along both axes.

Returns:
result2D ndarray

The window function as a 2D array.

Raises:
ValueError

If shape does not have two elements.