Exemple #1
0
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)
Exemple #2
0
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
Exemple #3
0
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)
Exemple #4
0
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)
Exemple #5
0
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)
Exemple #6
0
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 main(Args):
    """Creates galaxy and psf images with different parametrs
     and measures cg bias. Varying LSST  PSF size"""
    # Set disk SED name
    e_s = [0.3, 0.3]
    filt = Args.filter
    g = np.linspace(0.005, 0.01, 2)
    rt_g = np.array([g, g]).T
    npix = 360
    SNRs = get_rand_SNR(int(Args.size))
    num = int(Args.size)
    rng = galsim.BaseDeviate(int(Args.file_num))
    index_table = get_table(num)
    indexs = range(int(Args.file_num) * num, (int(Args.file_num) + 1) * num)
    col = Column(np.ones(num) * -10, name='psf_sigma')
    index_table.add_column(col)
    dSED = Args.disk_SED_name
    for n in range(num):
        print "Computing for noise realization {0} in {1} band".format(n, filt)
        index_table['NUMBER'][n] = indexs[n]
        input_p = cg_fn.Eu_Args(scale=0.03,
                                disk_SED_name=dSED,
                                bulge_e=e_s,
                                disk_e=e_s,
                                psf_sig_o=0.071,
                                psf_w_o=806)
        index_table['redshift'][n] = input_p.redshift
        CRG1 = get_CRG(input_p, SNRs[n], index_table[n], rng)
        # Compute CG bias
        meas_args = cg_fn.meas_args(rt_g=rt_g, npix=npix)
        meas_args.bp = galsim.Bandpass('data/baseline/total_%s.dat' % filt,
                                       wave_type='nm').thin(rel_err=1e-4)
        psf_args = cg_fn.psf_params()
        meas_cg_bias(CRG1, index_table[n], meas_args, psf_args, 'CRG')
    path = 'results/'
    # path = "/nfs/slac/g/ki/ki19/deuce/AEGIS/cg_results/ref_gal_results/with_aeg_noise_all/"
    op_file = path + 'ref_gal_cg_bias_{0}_band_var_noise_{1}.fits'.format(
        filt, Args.file_num)
    index_table.write(op_file, format='fits', overwrite=True)
    print "Saving output at", op_file