added extra files for test_renderer.py
Browse files
test_resampling/galsim_hst_to_hsc_resolution.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6a7a29fac7782b7a9fd19b66cebae724f95c9c4f0bfb477aa2d4f1483dee2149
|
| 3 |
+
size 10128
|
test_resampling/galsim_hst_to_hsc_resolution.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import warnings
|
| 3 |
+
warnings.filterwarnings('ignore')
|
| 4 |
+
|
| 5 |
+
import numpy as np
|
| 6 |
+
import scarlet2
|
| 7 |
+
import galsim
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
import astropy.io.fits as fits
|
| 11 |
+
from astropy.wcs import WCS
|
| 12 |
+
|
| 13 |
+
import jax.numpy as jnp
|
| 14 |
+
|
| 15 |
+
def generate_hst_to hsc_galsim():
|
| 16 |
+
# Load the HSC image data
|
| 17 |
+
obs_hdu = fits.open('../../scarlet/data/test_resampling/Cut_HSC1.fits')
|
| 18 |
+
data_hsc = jnp.array(obs_hdu[0].data.byteswap().newbyteorder(), jnp.float32)
|
| 19 |
+
wcs_hsc = WCS(obs_hdu[0].header)
|
| 20 |
+
channels_hsc = ['g','r','i','z','y']
|
| 21 |
+
|
| 22 |
+
# Load the HSC PSF data
|
| 23 |
+
psf_hsc_data = fits.open('../../scarlet/data/test_resampling/PSF_HSC.fits')[0].data.astype('float32')
|
| 24 |
+
Np1, Np2 = psf_hsc_data[0].shape
|
| 25 |
+
psf_hsc_data = jnp.pad(psf_hsc_data, ((0,0), (1,0), (1,0)))
|
| 26 |
+
psf_hsc = scarlet2.ArrayPSF(psf_hsc_data)
|
| 27 |
+
|
| 28 |
+
# Load the HST image data
|
| 29 |
+
hst_hdu = fits.open('../../scarlet/data/test_resampling/Cut_HST1.fits')
|
| 30 |
+
data_hst = hst_hdu[0].data
|
| 31 |
+
wcs_hst = WCS(hst_hdu[0].header)
|
| 32 |
+
channels_hst = ['F814W']
|
| 33 |
+
|
| 34 |
+
# Load the HST PSF data
|
| 35 |
+
psf_hst = fits.open('../../scarlet/data/test_resampling/PSF_HST.fits')[0].data
|
| 36 |
+
psf_hst = np.array(psf_hst[None,:,:], np.float32)
|
| 37 |
+
psf_hst = jnp.pad(psf_hst, ((0,0), (1,0), (1,0)))
|
| 38 |
+
psf_hst = np.repeat(psf_hst, 5, 0)
|
| 39 |
+
|
| 40 |
+
psf_hst = scarlet2.ArrayPSF(psf_hst)
|
| 41 |
+
|
| 42 |
+
# Scale the HST data
|
| 43 |
+
n1,n2 = np.shape(data_hst)
|
| 44 |
+
data_hst = data_hst.reshape(1, n1, n2).byteswap().newbyteorder()
|
| 45 |
+
data_hst *= data_hsc.max() / data_hst.max()
|
| 46 |
+
|
| 47 |
+
r, N1, N2 = data_hsc.shape
|
| 48 |
+
|
| 49 |
+
# define two observation packages and match to frame
|
| 50 |
+
obs_hst = scarlet2.Observation(data_hst[:1, ...],
|
| 51 |
+
wcs=wcs_hst,
|
| 52 |
+
psf=psf_hst,
|
| 53 |
+
channels=['channel'],
|
| 54 |
+
weights=None)
|
| 55 |
+
|
| 56 |
+
obs_hsc = scarlet2.Observation(data_hsc[:1,...],
|
| 57 |
+
wcs=wcs_hsc,
|
| 58 |
+
psf=psf_hsc,
|
| 59 |
+
channels=['channel'],
|
| 60 |
+
weights=None)
|
| 61 |
+
|
| 62 |
+
# Initialize images
|
| 63 |
+
h_hst = 0.03
|
| 64 |
+
h_hsc = 0.168
|
| 65 |
+
|
| 66 |
+
gi_hst_im = galsim.Image(np.array(data_hst[0]), scale=h_hst)
|
| 67 |
+
|
| 68 |
+
gii_hst_im = galsim.InterpolatedImage(gi_hst_im,
|
| 69 |
+
x_interpolant=galsim.Quintic(),
|
| 70 |
+
k_interpolant=galsim.Quintic()
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
hst_psf = psf_hst()[0]
|
| 74 |
+
|
| 75 |
+
gi_hst_psf = galsim.Image(np.array(hst_psf), scale=h_hst)
|
| 76 |
+
gii_hst_psf = galsim.InterpolatedImage(gi_hst_psf,
|
| 77 |
+
x_interpolant=galsim.Quintic(),
|
| 78 |
+
k_interpolant=galsim.Quintic()
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
hsc_psf = psf_hsc()[0]
|
| 82 |
+
|
| 83 |
+
gi_hsc_psf = galsim.Image(np.array(hsc_psf), scale=h_hsc)
|
| 84 |
+
gii_hsc_psf = galsim.InterpolatedImage(gi_hsc_psf,
|
| 85 |
+
x_interpolant=galsim.Quintic(),
|
| 86 |
+
k_interpolant=galsim.Quintic()
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
# Deconvolution and Reconvolution
|
| 90 |
+
inv_gii_hst_psf = galsim.Deconvolve(gii_hst_psf)
|
| 91 |
+
deconv_hst = galsim.Convolve(inv_gii_hst_psf, gii_hst_im)
|
| 92 |
+
reconv_hsc = galsim.Convolve(gii_hsc_psf, deconv_hst)
|
| 93 |
+
|
| 94 |
+
out_galsim = reconv_hsc.drawImage(nx=N1, ny=N2, scale=0.168, method='no_pixel')
|
| 95 |
+
np.save('./galsim_hst_to_hsc_resolution.npy', out_galsim.array)
|