-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusingpsfex_exx.py
60 lines (43 loc) · 1.72 KB
/
usingpsfex_exx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#Stolen from Barney Rowe.
#
# the psfex object that's the input to this function is loaded with:
# psfex = galsim.des.DES_PSFEx(psf_path)
#
import numpy
import os
import galsim
import galsim.des
import pylab
import pyfits
def getPSFExarray(psfex, x_image, y_image, nsidex=32, nsidey=32, upsampling=1, offset=None):
"""Return an image of the PSFEx model of the PSF as a NumPy array.
Arguments
---------
psfex A galsim.des.PSFEx instance opened using, for example,
`psfex = galsim.des.DES_PSFEx(psfex_file_name)`.
x_image Floating point x position on image [pixels]
y_image Floating point y position on image [pixels]
nsidex Size of PSF image along x [pixels]
nsidey Size of PSF image along y [pixels]
upsampling Upsampling (see Zuntz et al 2013)
Returns a NumPy array with shape (nsidey, nsidex) - note the reversal of y and x to match the
NumPy internal [y, x] style array ordering. This is to ensure that `pyfits.writeto()` using the
ouput array creates FITS-compliant output.
"""
import galsim
image = galsim.ImageD(nsidex, nsidey)
psf = psfex.getPSF(galsim.PositionD(x_image, y_image), pixel_scale=1.)
psf.draw(image, dx=1. / upsampling, offset=offset)
return image.array
############################ Main code
os.system('rm star_from_psfex.fits')
# First gal -- obj #4
x = 1448
y = 15
psfex = galsim.des.DES_PSFEx('decamtemp.psf')
psfatgal = getPSFExarray(psfex, x, y )
pyfits.writeto("star_from_psfex.fits",psfatgal)
# f = pyfits.open("staratxy.fits")
numpy.set_printoptions(threshold='nan')
psfatgal # Display the contents of the fits table file
# pylab.imshow(psfatgal) ; pylab.colorbar() ; pylab.show() # Show the star