# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""
Tools for matching PSFs using Fourier methods.
"""
from __future__ import division
import numpy as np
from numpy.fft import fft2, ifft2, fftshift, ifftshift


__all__ = ['create_matching_kernel']


def create_matching_kernel(source_psf, target_psf, window=None):
    """
    Create a kernel to match 2D point spread functions (PSF) using the
    ratio of Fourier transforms.

    Parameters
    ----------
    source_psf : 2D `~numpy.ndarray`
        The source PSF.  The source PSF should have higher resolution
        (i.e. narrower) than the target PSF.

    target_psf : 2D `~numpy.ndarray`
        The target PSF.  The target PSF should have lower resolution
        (i.e. broader) than the source PSF.

    window : callable, optional
        The window (or taper) function or callable class instance used
        to remove high frequency noise from the PSF matching kernel.
        Some examples include:

        * `~photutils.HanningWindow`
        * `~photutils.TukeyWindow`
        * `~photutils.CosineBellWindow`
        * `~photutils.SplitCosineBellWindow`

    Returns
    -------
    kernel : 2D `~numpy.ndarray`
        The matching kernel to go from ``source_psf`` to ``target_psf``.
    """

    source_otf = fftshift(fft2(source_psf))
    target_otf = fftshift(fft2(target_psf))
    ratio = target_otf / source_otf

    # apply a window function in frequency space
    if window is not None:
        ratio *= window(target_psf.shape)

    kernel = np.real(fftshift((ifft2(ifftshift(ratio)))))
    return kernel / kernel.sum()

@@ -231,16 +231,30 @@
 ll__ = %5B
+'resize_psf', 
 'create_
@@ -273,16 +273,882 @@
 nel'%5D%0A%0A%0A
+def resize_psf(psf, input_pixel_scale, output_pixel_scale, order=3):%0A    %22%22%22%0A    Resize a PSF using spline interpolation of the requested order.%0A%0A    Parameters%0A    ----------%0A    psf : 2D %60~numpy.ndarray%60%0A        The 2D data array of the PSF.%0A%0A    input_pixel_scale : float%0A        The pixel scale of the input %60%60psf%60%60.  The units must%0A        match %60%60output_pixel_scale%60%60.%0A%0A    output_pixel_scale : float%0A        The pixel scale of the output %60%60psf%60%60.  The units must%0A        match %60%60input_pixel_scale%60%60.%0A%0A    order : float, optional%0A        The order of the spline interpolation (0-5).  The default is 3.%0A%0A    Returns%0A    -------%0A    result : 2D %60~numpy.ndarray%60%0A        The resampled/interpolated 2D data array.%0A    %22%22%22%0A%0A    from scipy.ndimage import zoom%0A%0A    ratio = input_pixel_scale / output_pixel_scale%0A    return zoom(psf, ratio, order=order) / ratio**2%0A%0A%0A
 def crea
@@ -1494,24 +1494,109 @@
  target PSF.
+  %60%60source_psf%60%60 and%0A        %60%60target_psf%60%60 must have the same shape and pixel scale.
 %0A%0A    target
@@ -1730,24 +1730,109 @@
  source PSF.
+  %60%60source_psf%60%60 and%0A        %60%60target_psf%60%60 must have the same shape and pixel scale.
 %0A%0A    window
@@ -2318,24 +2318,419 @@
 %60.%0A    %22%22%22%0A%0A
+    source_psf = np.asanyarray(source_psf)%0A    target_psf = np.asanyarray(target_psf)%0A%0A    if source_psf.shape != target_psf.shape:%0A        raise ValueError('source_psf and target_psf must have the same shape '%0A                         '(i.e. registered with the same pixel scale).')%0A%0A    # ensure input PSFs are normalized%0A    source_psf /= source_psf.sum()%0A    target_psf /= target_psf.sum()%0A%0A
     source_o

Add resize_psf function