Beispiel #1
0
def load_mdpl2_data(drn=MDPL2_DRN, log_ssfr_clip=LOG_SSFR_CLIP):
    """
    """
    mdpl2 = Table(np.load(os.path.join(drn,
                                       "um_histories_dr1_mdpl2_cens.npy")))
    mdpl_t = np.loadtxt(os.path.join(drn, "mdpl2_cosmic_time.txt"))
    mdpl_z = 1 / np.loadtxt(os.path.join(drn, "mdpl2_scale_factors.txt")) - 1

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        log_mah = np.log10(
            np.maximum.accumulate(mdpl2["mpeak_history_main_prog"], axis=1))
        mdpl2["log_mah"] = np.where(np.isfinite(log_mah), log_mah, 0)

    mdpl2.remove_column("mpeak_history_main_prog")

    nh, nt = mdpl2["log_mah"].shape
    tmparr = np.zeros(nh)
    for i, log_mah in enumerate(mdpl2["log_mah"]):
        tmparr[i] = mdpl_t[find_indx_xpeak(log_mah, nt)]
    mdpl2["tmp"] = tmparr

    nh, nt = mdpl2["log_mah"].shape
    dmhdt_matrix = np.zeros((nh, nt))
    for i, log_mah in enumerate(mdpl2["log_mah"]):
        out = np.zeros(nt)
        calculate_dmhdt(mdpl_t, 10**log_mah, out, nt)
        dmhdt_matrix[i, :] = out

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        mdpl2["dmhdt"] = dmhdt_matrix
        mdpl2["log_dmhdt"] = np.where(dmhdt_matrix <= 0, 0,
                                      np.log10(dmhdt_matrix))

    sfrh = mdpl2["sfr_history_main_prog"]
    dtarr = _get_dt_array(mdpl_t)
    smh, log_ssfrh = _get_clipped_sfh_samples(mdpl_t, dtarr, sfrh,
                                              log_ssfr_clip)
    mdpl2["smh"] = smh
    mdpl2["log_ssfrh"] = log_ssfrh

    return mdpl2, mdpl_t, mdpl_z
Beispiel #2
0
def load_bpl_data(drn=BPL_DRN, log_ssfr_clip=LOG_SSFR_CLIP):
    """
    """
    bpl = Table(
        np.load(os.path.join(drn, "um_histories_dr1_bpl_cens_a_1.002310.npy")))
    bpl_t = np.loadtxt(os.path.join(drn, "cosmic_times_bpl.dat"))
    bpl_z = 1 / np.loadtxt(os.path.join(drn, "scale_list_bpl.dat")) - 1

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        log_mah = np.log10(
            np.maximum.accumulate(bpl["mpeak_history_main_prog"], axis=1))
        bpl["log_mah"] = np.where(np.isfinite(log_mah), log_mah, 0)
    bpl.remove_column("mpeak_history_main_prog")

    nh, nt = bpl["log_mah"].shape
    tmparr = np.zeros(nh)
    for i, log_mah in enumerate(bpl["log_mah"]):
        tmparr[i] = bpl_t[find_indx_xpeak(log_mah, nt)]
    bpl["tmp"] = tmparr

    nh, nt = bpl["log_mah"].shape
    dmhdt_matrix = np.zeros((nh, nt))
    for i, log_mah in enumerate(bpl["log_mah"]):
        out = np.zeros(nt)
        calculate_dmhdt(bpl_t, 10**log_mah, out, nt)
        dmhdt_matrix[i, :] = out

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        bpl["dmhdt"] = dmhdt_matrix
        bpl["log_dmhdt"] = np.where(dmhdt_matrix <= 0, -1.0,
                                    np.log10(dmhdt_matrix))

    sfrh = bpl["sfr_history_main_prog"]
    dtarr = _get_dt_array(bpl_t)
    smh, log_ssfrh = _get_clipped_sfh_samples(bpl_t, dtarr, sfrh,
                                              log_ssfr_clip)
    bpl["smh"] = smh
    bpl["log_ssfrh"] = log_ssfrh

    return bpl, bpl_t, bpl_z
Beispiel #3
0
def generate_halo_history_family(
    logmp_family,
    assembly_family,
    tmp_family,
    cosmic_time,
    dmhdt_x0=DEFAULT_MAH_PARAMS["dmhdt_x0"],
    dmhdt_k=DEFAULT_MAH_PARAMS["dmhdt_k"],
):
    """Generate a family of halo histories

    Parameters
    ----------
    logmp_family : ndarray, shape (n_mpeak, )

    assembly_family : ndarray, shape (n_assem, )

    tmp_family : ndarray, shape (n_tmp, )

    cosmic_time : ndarray, shape (n_times, )

    Returns
    -------
    log_mah : ndarray, shape (n_tmp, n_assem, n_mpeak, n_times)
        Base-10 log of halo mass in units of Msun

    log_dmhdt : ndarray, shape (n_tmp, n_assem, n_mpeak, n_times)
        Base-10 log of halo mass accretion rate in units of Msun/yr

    """
    indx_tmp_family = np.array(
        [np.argmin(np.abs(t - cosmic_time)) for t in tmp_family])
    logt = np.log10(cosmic_time)
    dtarr = _get_dt_array(cosmic_time)
    return _generate_halo_history_family(
        logmp_family,
        assembly_family,
        indx_tmp_family,
        logt,
        dtarr,
        dmhdt_x0,
        dmhdt_k,
    )
Beispiel #4
0
def get_loss_data_fixed_k_x0(
        t_simulation,
        log_mah_simulated_halo,
        log_dmhdt_simulated_halo,
        tmp,
        t_table=np.logspace(-2, 1.15, 500),
        dlogm_cut=2.5,
        t_fit_min=1,
):
    """Compute the loss data for the input halo.
    In this version of the calculation, we hold dmhdt_x0 and dmhdt_k fixed,
    and we allow logmp to vary along with the early and late power-law indices.

    Parameters
    ----------
    t_simulation : ndarray, shape (n_times, )
        Age of the universe in Gyr of the simulation snapshots

    log_mah_simulated_halo : ndarray, shape (n_times, )
        Base-10 log of peak halo mass in Msun

    log_dmhdt_simulated_halo : ndarray, shape (n_times, )
        Base-10 log of halo mass accretion rate in Msun/yr

    tmp : float
        Time the halo first reached its peak halo mass in Gyr

    t_table : ndarray, shape (n_table, ), optional
        Integration table used to calculate cumulative mass from dMh/dt
        Should span the range of t_simulation.

    dlogm_cut : float, optional
        Parameter used to restrict the range of the simulated MAH used in the fit.
        Snapshots for which log_mah_simulated_halo < (logmp - dlogm_cut)
        will be excluded from the fitting data

    t_fit_min : float, optional
        Parameter used to restrict the range of the simulated MAH used in the fit.
        Snapshots with t_simulation < t_fit_min will be excluded from the fitting data.

    Returns
    -------
    loss_data : sequence, as follows:

        logt_table : ndarray, shape (n_table, )
            Base-10 log of the integration table used to calculate
            cumulative mass from dMh/dt

        dt_table : ndarray, shape (n_table, )
            Linear time spacing between elements in the integration table
            used to calculate cumulative mass from dMh/dt

        x0_fixed : float
            Fixed value of the parameter dmhdt_x0

        k_fixed : float
            Fixed value of the parameter dmhdt_k

        indx_tmp : int
            Index where the t_table array is closest to the input halo tmp

        indx_pred : ndarray, shape (n_target, )
            Indices of t_table closest in time to the target predictions

        log_mah_target : ndarray, shape (n_target, )
            Base-10 log of peak halo mass in Msun

        log_dmhdt_target : ndarray, shape (n_target, )
            Base-10 log of halo mass accretion rate in Msun/yr

    p_init : ndarray, shape (n_varied_params, )
        Initial guess at the best-fit value for each parameter varied in the fit

    """
    dt_table = _get_dt_array(t_table)
    logt_table = np.log10(t_table)

    logmp_sim = log_mah_simulated_halo[-1]

    msk = log_mah_simulated_halo > logmp_sim - dlogm_cut
    msk &= t_simulation > t_fit_min
    log_mah_target = log_mah_simulated_halo[msk]
    log_dmhdt_target = log_dmhdt_simulated_halo[msk]
    t_target = t_simulation[msk]
    indx_pred = np.array([np.argmin(np.abs(t_table - t))
                          for t in t_target]).astype("i4")
    indx_tmp = np.argmin(np.abs(t_table - tmp))

    logmp_init = np.copy(logmp_sim)
    early_init = DEFAULT_MAH_PARAMS["dmhdt_early_index"]
    late_init = DEFAULT_MAH_PARAMS["dmhdt_late_index"]
    p_init = np.array((logmp_init, early_init, late_init))

    x0_fixed = DEFAULT_MAH_PARAMS["dmhdt_x0"]
    k_fixed = DEFAULT_MAH_PARAMS["dmhdt_k"]

    loss_data = (
        logt_table,
        dt_table,
        x0_fixed,
        k_fixed,
        indx_tmp,
        indx_pred,
        log_mah_target,
        log_dmhdt_target,
    )
    return loss_data, p_init
Beispiel #5
0
def get_loss_data_fixed_logmp(
        t_simulation,
        log_mah_simulated_halo,
        log_dmhdt_simulated_halo,
        tmp,
        t_table=np.logspace(-2, 1.15, 500),
        dlogm_cut=2.5,
        t_fit_min=1,
):
    """Compute the loss data for the input halo.
    In this version of the calculation, logmp is held fixed to the value in the sim,
    and all dmhdt_x0, dmhdt_k, dmhdt_early_index, dmhdt_late_index are varied.

    Parameters
    ----------
    t_simulation : ndarray, shape (n_times, )
        Age of the universe in Gyr of the simulation snapshots

    log_mah_simulated_halo : ndarray, shape (n_times, )
        Base-10 log of peak halo mass in Msun

    log_dmhdt_simulated_halo : ndarray, shape (n_times, )
        Base-10 log of halo mass accretion rate in Msun/yr

    tmp : float
        Time the halo first reached its peak halo mass in Gyr

    t_table : ndarray, shape (n_table, ), optional
        Integration table used to calculate cumulative mass from dMh/dt
        Should span the range of t_simulation.

    dlogm_cut : float, optional
        Parameter used to restrict the range of the simulated MAH used in the fit.
        Snapshots for which log_mah_simulated_halo < (logmp - dlogm_cut)
        will be excluded from the fitting data

    t_fit_min : float, optional
        Parameter used to restrict the range of the simulated MAH used in the fit.
        Snapshots with t_simulation < t_fit_min will be excluded from the fitting data.

    Returns
    -------
    loss_data : sequence
        Tuple of data passed to the halo MAH fitter:

        logt_table : ndarray, shape (n_table, )
            Base-10 log of the integration table used to calculate
            cumulative mass from dMh/dt

        dt_table : ndarray, shape (n_table, )
            Linear time spacing between elements in the integration table
            used to calculate cumulative mass from dMh/dt

        logmp : float
            Base-10 log of peak halo mass in Msun

        indx_tmp : int
            Index where the t_table array is closest to the input halo tmp

        indx_pred : ndarray, shape (n_target, )
            Indices of t_table closest in time to the target predictions

        log_mah_target : ndarray, shape (n_target, )
            Base-10 log of peak halo mass in Msun

        log_dmhdt_target : ndarray, shape (n_target, )
            Base-10 log of halo mass accretion rate in Msun/yr

    p_init : ndarray, shape (n_varied_params, )
        Initial guess at the best-fit value for each parameter varied in the fit

    """
    logmp = log_mah_simulated_halo[-1]
    dt_table = _get_dt_array(t_table)
    logt_table = np.log10(t_table)

    msk = log_mah_simulated_halo > logmp - dlogm_cut
    msk &= t_simulation > t_fit_min
    log_mah_target = log_mah_simulated_halo[msk]
    log_dmhdt_target = log_dmhdt_simulated_halo[msk]
    t_target = t_simulation[msk]
    indx_pred = np.array([np.argmin(np.abs(t_table - t))
                          for t in t_target]).astype("i4")
    indx_tmp = np.argmin(np.abs(t_table - tmp))

    p_init = np.array(list(DEFAULT_MAH_PARAMS.values()))
    loss_data = (
        logt_table,
        dt_table,
        logmp,
        indx_tmp,
        indx_pred,
        log_mah_target,
        log_dmhdt_target,
    )
    return loss_data, p_init