Exemplo n.º 1
0
def create_k_corr_grid(redshift):
    """
    (Edited from original because of error)
    Returns a grid of redshifts and K corrections on the
    LSST Simulations AGN SED that can be used for K correction
    interpolation.
    """
    bp_dict = BandpassDict.loadTotalBandpassesFromFiles()
    bp_i = bp_dict['i']
    sed_dir = os.path.join(getPackageDir('sims_sed_library'), 'agnSED')
    sed_name = os.path.join(sed_dir, 'agn.spec.gz')
    if not os.path.exists(sed_name):
        raise RuntimeError('\n\n%s\n\nndoes not exist\n\n' % sed_name)
    base_sed = Sed()
    base_sed.readSED_flambda(sed_name)
    z_grid = np.arange(0.0, redshift.max(), 0.01)
    k_grid = np.zeros(len(z_grid), dtype=float)
    for i_z, zz in enumerate(z_grid):
        ss = Sed(flambda=base_sed.flambda, wavelen=base_sed.wavelen)
        ss.redshiftSED(zz, dimming=True)
        k = k_correction(ss, bp_i, zz)
        k_grid[i_z] = k
    return z_grid, k_grid
Exemplo n.º 2
0
    def test_k_correction(self):
        """
        Test that the K correction correctly converts absolute magnitude
        to observed magnitude.
        """
        bp_dict = BandpassDict.loadTotalBandpassesFromFiles()
        rng = np.random.RandomState(41321)
        sed_dir = os.path.join(getPackageDir('sims_sed_library'), 'galaxySED')
        list_of_sed_files = os.listdir(sed_dir)
        list_of_sed_files.sort()
        sed_to_check = rng.choice(list_of_sed_files, size=10)
        redshift_arr = rng.random_sample(len(sed_to_check)) * 2.0 + 0.1

        bp = bp_dict['g']
        for sed_name, zz in zip(sed_to_check, redshift_arr):
            full_name = os.path.join(sed_dir, sed_name)
            ss = Sed()
            ss.readSED_flambda(full_name)
            true_rest_mag = ss.calcMag(bp)
            ss.redshiftSED(zz, dimming=True)
            obs_mag = ss.calcMag(bp)
            k_corr = k_correction(ss, bp, zz)
            self.assertLess(np.abs(true_rest_mag - obs_mag + k_corr), 0.001)
    bp_dict = BandpassDict.loadTotalBandpassesFromFiles()
    bp_i = bp_dict['i']
    sed_dir = os.path.join(getPackageDir('sims_sed_library'),
                           'agnSED')
    sed_name = os.path.join(sed_dir, 'agn.spec.gz')
    if not os.path.exists(sed_name):
        raise RuntimeError('\n\n%s\n\nndoes not exist\n\n' % sed_name)
    base_sed = Sed()
    base_sed.readSED_flambda(sed_name)
    z_grid = np.arange(0.0, dc2_data['redshift'].max(), 0.01)
    k_grid = np.zeros(len(z_grid),dtype=float)

    for i_z, zz in enumerate(z_grid):
        ss = Sed(flambda=base_sed.flambda, wavelen=base_sed.wavelen)
        ss.redshiftSED(zz, dimming=True)
        k = k_correction(ss, bp_i, zz)
        k_grid[i_z] = k

    dc2_obs_mag_i = np.zeros(len(dc2_data), dtype=float)
    k_arr = np.interp(dc2_data['redshift'], z_grid, k_grid)
    print('calculating observed mag')
    for i_obj in range(len(dc2_data)):
       local_obs_mag = dc2_abs_mag_i[i_obj] + DM[i_obj] + k_arr[i_obj]
       dc2_obs_mag_i[i_obj] = local_obs_mag

    rng = np.random.RandomState(18231)

    dc2_tau = tau_from_params(dc2_data['redshift'],
                              dc2_abs_mag_i,
                              dc2_data['bhmass'],
                              rng=rng)