Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simpler version of `PSF_GAUSSIAN` in IDL.
"""
Simpler version of `PSF_GAUSSIAN` in IDL.
:Authors: Pey Lian Lim (Python)
:Organization: Space Telescope Science Institute
:History:
* 2010/08/17 PLL converted from IDL to Python.
"""
# External modules
import numpy
#-----------
def GaussPsf2D(npix, fwhm, normalize=True):
"""
Parameters
----------
npix: int
Number of pixels for each dimension.
Just one number to make all sizes equal.
fwhm: float
FWHM (pixels) in each dimension.
Single number to make all the same.
normalize: bool, optional
Normalized so total PSF is 1.
Returns
-------
psf: array_like
Gaussian point spread function.
"""
# Initialize PSF params
cntrd = (npix - 1.0) * 0.5
st_dev = 0.5 * fwhm / numpy.sqrt( 2.0 * numpy.log(2) )
# Make PSF
i = range(npix)
psf = numpy.array( [numpy.exp(-(((cntrd-x)/st_dev)**2+((cntrd-y)/st_dev)**2)/2) for x in i for y in i] )
psf = psf.reshape(npix, npix)
# Normalize
if normalize: psf /= psf.sum()
return psf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.