def test_age_weights_agree_with_analytical_calculation_of_linear_sfr_weights():
    t_obs = 16.0
    log_ages_gyr = (FSPS_LG_AGES - 9)
    lgt_age_bin_edges = _get_lg_age_bin_edges(log_ages_gyr)
    t_age_bin_edges_gyr = (10 ** lgt_age_bin_edges)
    t_births_bin_edges = (t_obs - t_age_bin_edges_gyr)
    mstar_at_age_bins = linear_smh(T_BIRTH_MIN, t_births_bin_edges)
    dmstar_ages = (- np.diff(mstar_at_age_bins))
    correct_weights = (dmstar_ages / dmstar_ages.sum())
    t_table = np.linspace(T_BIRTH_MIN, t_obs, 50000)
    lgt_table = np.log10(t_table)
    logsm_table = np.log10(linear_smh(T_BIRTH_MIN, t_table[1:]))
    lgt_birth_bin_edges = _get_lgt_birth(t_obs, lgt_age_bin_edges)
    dsps_age_weights = _get_age_weights_from_tables(lgt_birth_bin_edges, lgt_table[1:], logsm_table)
    assert np.allclose(dsps_age_weights, correct_weights, atol=0.001)
def test_age_weights_agree_with_analytical_calculation_of_linear_sfr_weights():
    t_obs = 16.0
    log_ages_gyr = (FSPS_LG_AGES - 9)
    lgt_age_bin_edges = _get_lg_age_bin_edges(log_ages_gyr)
    t_age_bin_edges_gyr = (10 ** lgt_age_bin_edges)
    t_births_bin_edges = (t_obs - t_age_bin_edges_gyr)
    mstar_at_age_bins = linear_smh(T_BIRTH_MIN, t_births_bin_edges)
    dmstar_ages = (- np.diff(mstar_at_age_bins))
    correct_weights = (dmstar_ages / dmstar_ages.sum())
    t_table = np.linspace(T_BIRTH_MIN, t_obs, 50000)
    lgt_table = np.log10(t_table)
    logsm_table = np.log10(linear_smh(T_BIRTH_MIN, t_table[1:]))
    lgt_birth_bin_edges = _get_lgt_birth(t_obs, lgt_age_bin_edges)
    dsps_age_weights = _get_age_weights_from_tables(lgt_birth_bin_edges, lgt_table[1:], logsm_table)
    assert np.allclose(dsps_age_weights, correct_weights, atol=0.001)