Created
October 25, 2011 00:40
-
-
Save jiffyclub/1310958 to your computer and use it in GitHub Desktop.
Simpler version of `PSF_GAUSSIAN` in IDL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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