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 meas_cg_bias(gal, row, f_name, rt_g, f_type, npix=360): """Computes bias due to color gradient on sahpe measuremnt. For an input chromatic galaxy with cg, gal an equilvalent galaxy with no cg is created and the shear recovered from each (with ring test) is measured. @gal input galaxy with cg. @row astropy table row to save measured shear. @rt_g shaer applied to the galaxy. @type string to identify the column of row to save measured shear. """ print " Measuring CG bias" filt = galsim.Bandpass('data/baseline/total_%s.dat'%f_name, wave_type='nm').thin(rel_err=1e-4) meas_args = cg_fn.meas_args(rt_g=rt_g, npix=npix) meas_args.bp = filt psf_args = cg_fn.psf_params() gcg, gnocg = cg_fn.calc_cg_crg(gal, meas_args, psf_args) print " Measured CG bias" if (gcg == "Fail") or (gnocg == "Fail"): print "HSM FAILED" g_f = np.ones([2, len(rt_g)]) * -10 gcg, gnocg = g_f, g_f row[f_type + '_g_cg'] = gcg.T row[f_type + '_g_no_cg'] = gnocg.T
def meas_cg_bias(gal, row, meas_args, psf_args, f_type): """Computes bias due to color gradient on sahpe measuremnt. For an input chromatic galaxy with cg, gal an equilvalent galaxy with no cg is created and the shear recovered from each (with ring test) is measured. @gal input galaxy with cg. @row astropy table row to save measured shear. @f_name name of filter to measure cg bias in @rt_g shaer applied to the galaxy. @type string to identify the column of row to save measured shear. """ gcg, gnocg = cg_fn.calc_cg_crg(gal, meas_args, psf_args) print "Computing CG bias" if (gcg == "Fail") or (gnocg == "Fail"): print "HSM FAILED" return row[f_type + '_g_cg'] = gcg.T row[f_type + '_g_no_cg'] = gnocg.T gtrue = meas_args.rt_g m, c = cg_fn.get_bias(gcg[0], gnocg[0], gtrue.T[0]) row[f_type + '_m1'] = m row[f_type + '_c1'] = c m, c = cg_fn.get_bias(gcg[1], gnocg[1], gtrue.T[1]) row[f_type + '_m2'] = m row[f_type + '_c2'] = c
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 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)