def cg_other_est(): """Test all HSM shear estimators give same value as REGAUSS (default)""" in_p = cg_fn.LSST_Args() filt = galsim.Bandpass('data/baseline/total_r.dat', wave_type='nm').thin(rel_err=1e-4) in_p.b_SED, in_p.d_SED, in_p.c_SED = cg_fn.get_template_seds(in_p) gal = cg_fn.get_gal_cg(in_p) psf_args = cg_fn.psf_params() meas_args = cg_fn.meas_args(shear_est='KSB') meas_args.bp = filt gcg, gnocg = cg_fn.calc_cg_crg(gal, meas_args, psf_args) # Previously measured value at default galaxy parameters np.testing.assert_array_almost_equal((gcg / gnocg - 1).T[0], [0.00106263, 0.00106594], decimal=5) meas_args.shear_est = 'BJ' gcg, gnocg = cg_fn.calc_cg_crg(gal, meas_args, psf_args) # Previously measured value at default galaxy parameters np.testing.assert_array_almost_equal((gcg / gnocg - 1).T[0], [0.00106263, 0.00106594], decimal=5) meas_args.shear_est = 'LINEAR' gcg, gnocg = cg_fn.calc_cg_crg(gal, meas_args, psf_args) # Previously measured value at default galaxy parameters np.testing.assert_array_almost_equal((gcg / gnocg - 1).T[0], [0.00106263, 0.00106594], decimal=5)
def same_sed(): """bulge and disk have same sed, cg bias must be zero""" in_p = cg_fn.LSST_Args(disk_SED_name='E') filt = galsim.Bandpass('data/baseline/total_r.dat', wave_type='nm').thin(rel_err=1e-4) in_p.b_SED, in_p.d_SED, in_p.c_SED = cg_fn.get_template_seds(in_p) gal = cg_fn.get_gal_cg(in_p) meas_args = cg_fn.meas_args() meas_args.bp = filt psf_args = cg_fn.psf_params() gcg, gnocg = cg_fn.calc_cg_crg(gal, meas_args, psf_args) np.testing.assert_array_almost_equal((gcg / gnocg - 1).T[0], [0, 0], decimal=5)
def achr_psf(): """LSST PSF is chromatic, CG bias must be 0""" in_p = cg_fn.LSST_Args() filt = galsim.Bandpass('data/baseline/total_r.dat', wave_type='nm').thin(rel_err=1e-4) in_p.b_SED, in_p.d_SED, in_p.c_SED = cg_fn.get_template_seds(in_p) gal = cg_fn.get_gal_cg(in_p) meas_args = cg_fn.meas_args() meas_args.bp = filt psf_args = cg_fn.psf_params(alpha=0) gcg, gnocg = cg_fn.calc_cg_crg(gal, meas_args, psf_args) np.testing.assert_array_almost_equal((gcg / gnocg - 1).T[0], [0, 0], decimal=5)
def with_cg(): """Raise error if no cg bias in default setting""" in_p = cg_fn.LSST_Args() filt = galsim.Bandpass('data/baseline/total_r.dat', wave_type='nm').thin(rel_err=1e-4) in_p.b_SED, in_p.d_SED, in_p.c_SED = cg_fn.get_template_seds(in_p) gal = cg_fn.get_gal_cg(in_p) meas_args = cg_fn.meas_args() meas_args.bp = filt psf_args = cg_fn.psf_params() gcg, gnocg = cg_fn.calc_cg_crg(gal, meas_args, psf_args) np.testing.assert_raises(AssertionError, np.testing.assert_array_almost_equal, (gcg / gnocg - 1).T[0], [0, 0], decimal=5) # Previously measured value at default galaxy parameters np.testing.assert_array_almost_equal((gcg / gnocg - 1).T[0], [0.00106263, 0.00106594], decimal=5)
def get_lsst_para(cat): """Create parametric bulge+disk galaxy for input parametrs form catsim. @cat: catsim row containig catsim galaxy parametrs """ # HST scale scale = 0.2 b_r, b_g = a_b2re_e(cat['a_b'], cat['b_b']) d_r, d_g = a_b2re_e(cat['a_d'], cat['b_d']) b_s = galsim.Shear(g=b_g, beta=cat['pa_bulge'] * galsim.degrees) d_s = galsim.Shear(g=d_g, beta=cat['pa_disk'] * galsim.degrees) input_p = cg_fn.LSST_Args(scale=scale, redshift=cat['redshift'], bulge_n=cat['disk_n'], disk_n=cat['bulge_n'], disk_HLR=d_r, bulge_HLR=b_r, bulge_e=[b_s.e1, b_s.e2], disk_e=[d_s.e1, d_s.e2], bulge_frac=0.5) input_p.T_flux = 2 gal, PSF, con = get_gal(input_p, cat) return gal
def with_CRG(): """Raise error if no cg bias in default setting""" in_p = cg_fn.LSST_Args() filt = galsim.Bandpass('data/baseline/total_r.dat', wave_type='nm').thin(rel_err=1e-4) in_p.b_SED, in_p.d_SED, in_p.c_SED = cg_fn.get_template_seds(in_p) gal = cg_fn.get_gal_cg(in_p) meas_args = cg_fn.meas_args() meas_args.bp = filt psf_args = cg_fn.psf_params() CRG1, CRG2 = cg_fn.get_CRG_basic(gal, in_p) gcg1, gnocg1 = cg_fn.calc_cg_crg(CRG1, meas_args, psf_args) gcg2, gnocg2 = cg_fn.calc_cg_crg(CRG2, meas_args, psf_args) # Previously measured value at default galaxy parameters np.testing.assert_array_almost_equal((gcg1 / gnocg1 - 1).T[0], [0.00128506, 0.0012862], decimal=5) np.testing.assert_array_almost_equal((gcg2 / gnocg2 - 1).T[0], [0.00106303, 0.00106446], decimal=5)
def get_lsst_noise(cat, rng, row): """Create CRG for a given input parametrs form catsim. Args: cat: astropy row containig catsim galaxy parametrs """ # HST scale exposure_time = 5520 # 6900 r_zero_point = 43.70 # 44.80 i_zero_point = 32.36 # 33.17 area = 32.4 * 10000 # np.pi * (667 / 2.)**2 scale = 0.2 r_sky_brightness = 21.2 i_sky_brightness = 20.5 # r0 = 6.67 * 100 / 2. psf_sig = 0.297 npix = int(max(cat['BulgeHalfLightRadius'], cat['DiskHalfLightRadius'], 2 * psf_sig) * 8 / scale) print "Number of pixels is ", npix b_r, b_g = a_b2re_e(cat['a_b'], cat['b_b']) d_r, d_g = a_b2re_e(cat['a_d'], cat['b_d']) b_s = galsim.Shear(g=b_g, beta=cat['pa_bulge'] * galsim.degrees) d_s = galsim.Shear(g=d_g, beta=cat['pa_disk'] * galsim.degrees) input_p = cg_fn.LSST_Args(scale=scale, npix=npix, redshift=cat['redshift'], bulge_frac=0.5, disk_n=cat['bulge_n'], bulge_n=cat['disk_n'], disk_HLR=d_r, bulge_HLR=b_r, bulge_e=[b_s.e1, b_s.e2], disk_e=[d_s.e1, d_s.e2]) r = galsim.Bandpass('data/baseline/total_r.dat', wave_type='nm').thin(rel_err=1e-4) input_p.bp = r input_p.T_flux = 2 gal, PSF, con = get_gal(input_p, cat) r = galsim.Bandpass('data/baseline/total_r.dat', zeropoint='AB', wave_type='nm').thin(rel_err=1e-4) i = galsim.Bandpass('data/baseline/total_i.dat', zeropoint='AB', wave_type='nm').thin(rel_err=1e-4) # old throughputs did not have one of the mirrors # get bandpass # r = galsim.Bandpass('data/LSST_r.dat', zeropoint='AB', # wave_type='nm').thin(rel_err=1e-4) # i = galsim.Bandpass('data/LSST_i.dat', zeropoint='AB', # wave_type='nm').thin(rel_err=1e-4) # draw galaxy image gal_im_r = con.drawImage(r, nx=npix, ny=npix, scale=scale, area=area, exptime=exposure_time) gal_im_i = con.drawImage(i, nx=npix, ny=npix, scale=scale, area=area, exptime=exposure_time) flux = np.array([gal_im_r.array.sum(), gal_im_i.array.sum()]) snr_num = np.array([np.sum(gal_im_r.array**2), np.sum(gal_im_i.array**2)]) # correlated noise to add to image r_mean_sky_level = get_flux(r_sky_brightness, exposure_time, r_zero_point) * scale**2 i_mean_sky_level = get_flux(i_sky_brightness, exposure_time, i_zero_point) * scale**2 noise_r = galsim.PoissonNoise(rng=rng, sky_level=r_mean_sky_level) noise_i = galsim.PoissonNoise(rng=rng, sky_level=i_mean_sky_level) # Add noise gal_im_r.addNoise(noise_r) gal_im_i.addNoise(noise_i) var_r = noise_r.getVariance() var_i = noise_i.getVariance() var = np.array([var_r, var_i]) # Compute sn_ellip_gauss try: res_r = galsim.hsm.FindAdaptiveMom(gal_im_r) res_i = galsim.hsm.FindAdaptiveMom(gal_im_i) aperture_noise_r = np.sqrt(var_r * 2 * np.pi * (res_r.moments_sigma**2)) aperture_noise_i = np.sqrt(var_i * 2 * np.pi * (res_i.moments_sigma**2)) sn_ellip_gauss_r = res_r.moments_amp / aperture_noise_r sn_ellip_gauss_i = res_i.moments_amp / aperture_noise_i row['mom_sigma'] = [res_r.moments_sigma, res_i.moments_sigma] except: sn_ellip_gauss_r = -10 sn_ellip_gauss_i = -10 row['LSST_sn_ellip_gauss'] = np.array([sn_ellip_gauss_r, sn_ellip_gauss_i]) row['LSST_noise_var'] = var row['LSST_flux'] = flux print "LSST flux", flux print "LSST noise var ", var row['LSST_SNR'] = np.sqrt(snr_num / var) t_flux_r = get_flux(cat['r_ab'], exposure_time, r_zero_point) t_flux_i = get_flux(cat['i_ab'], exposure_time, i_zero_point) t_fluxs = np.array([t_flux_r, t_flux_i]) row['LSST_target_flux'] = t_fluxs