Friday, February 26, 2016

Convolve with a Gaussian, and rebin

I wrote a code to "Candelize" the source plane image of a lensed galaxy.  It convolves witha gaussian to the normal PSF of HST, and then rebins to a normal HST pixel scale.  The code I wrote is rebin_image-s1110.py, on my machine.  Here are the key nuggets of what it does:

from astropy.convolution import convolve
from astropy.convolution import Gaussian2DKernel
from astropy.stats import gaussian_fwhm_to_sigma   # a useful constant
from skimage.measure import block_reduce

# Convolve with a 2D Gaussian
 kernel = Gaussian2DKernel(ksize[ii])  #ksize is a stdev, not fwhm
 data_out = convolve(data_in, kernel)

# Rebin to normal HST pixel scale
rebinned = block_reduce(data_out, block_size=(binby,binby), func=np.sum)  # in skimage

# The rest of the code is just bookkeeping.

No comments:

Post a Comment