-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsfex_deconvolved.py
59 lines (43 loc) · 1.64 KB
/
psfex_deconvolved.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
59
import os
import numpy as np
import galsim
from galsim.des import DES_PSFEx
class PSFEx_Deconv(object):
"""A wrapper for PSFEx to use with Galsim. Main use is deconvolving pixel scale.
This wrapper just takes in galsim PSFEx and deconvolves it with pixel scale
Parameters
----------
file_name : str
The file with the Psfex psf solution.
"""
_req_params = {'file_name': str}
_opt_params = {}
_single_params = []
_takes_rng = False
def __init__(self, file_name, wcs):
self.file_name = file_name
self.wcs = wcs
self._psfex = DES_PSFEx(os.path.expanduser(os.path.expandvars(file_name)), wcs = wcs)
def getPSFEx(self):
return self._psfex
def getPSF(self, image_pos, wcs=None):
"""Get a deconvolved image of the PSF at the given location.
Parameters
----------
image_pos : galsim.Position
The image position for the PSF.
wcs : galsim.BaseWCS or subclass
The WCS to use to draw the PSF.
Returns
-------
psf : galsim.InterpolatedImage
The PSF at the image position.
"""
x_interpolant='lanczos15'
gsparams=None
psf = self.getPSFEx().getPSF(image_pos) #Get galsim PSF object
wcs = wcs.jacobian(image_pos=image_pos)
pixel = wcs.toWorld(galsim.Pixel(scale=1)) #Get pixel profile in correct wcs
deconvolution_kernel = galsim.Deconvolve(pixel) #Create kernel to deconvolve pixel window
psf = galsim.Convolve([psf, deconvolution_kernel]).withFlux(1.0) #Deconvolve
return psf