예제 #1
0
def xi(Mr=20, Nmock=500): 
    '''
    Plot xi(r) of the fake observations
    '''
    prettyplot() 
    pretty_colors = prettycolors() 

    xir, cii = Data.data_xi(Mr=Mr, Nmock=Nmock)
    rbin = Data.data_xi_bins(Mr=Mr) 
    
    fig = plt.figure(1) 
    sub = fig.add_subplot(111)
    sub.plot(rbin, rbin*xir, c='k', lw=1)
    sub.errorbar(rbin, rbin*xir, yerr = rbin*cii**0.5 , fmt="ok", ms=1, capsize=2, alpha=1.)

    sub.set_xlim([0.1, 15])
    sub.set_ylim([1, 10])
    sub.set_yscale("log")
    sub.set_xscale("log")

    sub.set_xlabel(r'$\mathtt{r}\; (\mathtt{Mpc})$', fontsize=25)
    sub.set_ylabel(r'$\mathtt{r} \xi_{\rm gg}$', fontsize=25)

    fig_file = ''.join([util.fig_dir(),
        'xi.Mr', str(Mr), '.Nmock', str(Nmock), '.png'])
    fig.savefig(fig_file, bbox_inches='tight')
    plt.close()
    return None
예제 #2
0
def plot_posterior_model(observable, abc_theta_file=None, data_dict={'Mr':20, 'b_normal': 0.25, 'Nmock':500},
        clobber=False):
    '''
    Plot 1\sigma and 2\sigma model predictions from ABC-PMC posterior likelihood

    Parameters
    ----------
    observable : string
        One of the following strings ['xi', 'scaledxi', 'gmf']

    '''
    # load the particles
    if abc_theta_file is None:
        raise ValueError("Please specify the theta output file from ABC-PMC run")
    theta = np.loadtxt(abc_theta_file)

    if observable == 'scaledxi':
        obvs_str = 'xi'
    else:
        obvs_str = observable

    obvs_file = ''.join(abc_theta_file.rsplit('.dat')[:-1] + ['.', observable, '.dat'])
    print obvs_file
    if not os.path.isfile(obvs_file) or clobber:
        for i in xrange(len(theta)):
            obv_i  = HODsimulator(
                    theta[i], prior_range=None,
                    observables=[obvs_str], Mr=data_dict['Mr'])
            try:
                model_obv.append(obv_i[0])
            except UnboundLocalError:
                model_obv = [obv_i[0]]
        model_obv = np.array(model_obv)
        np.savetxt(obvs_file, model_obv)
    else:
        model_obv = np.loadtxt(obvs_file)

    if 'xi' in observable:
        r_bin = Data.data_xi_bins(Mr=data_dict['Mr'])
    elif observable == 'gmf':
        r_bin = Data.data_gmf_bins()

    a, b, c, d, e = np.percentile(model_obv, [2.5, 16, 50, 84, 97.5], axis=0)

    # plotting
    fig = plt.figure(1)
    ax = fig.add_subplot(111)

    if observable == 'xi':  # 2PCF
        data_xi, data_xi_cov = Data.data_xi_full_cov(**data_dict) # data

        ax.fill_between(r_bin, a, e, color="k", alpha=0.1, edgecolor="none")
        ax.fill_between(r_bin, b, d, color="k", alpha=0.3, edgecolor="none")
        #ax.plot(r_bin, c, "k", lw=1)
        ax.errorbar(r_bin, data_xi, yerr = np.sqrt(np.diag(data_xi_cov)), fmt=".k",
                    capsize=0)
        ax.set_xlabel(r'$r\;[\mathrm{Mpc}/h]$', fontsize=20)
        ax.set_ylabel(r'$\xi_{\rm gg}$', fontsize=25)
        ax.set_xscale('log')
        ax.set_xlim([0.1, 20.])

    elif observable == 'scaledxi':  # Scaled 2PFC (r * xi)
        data_xi, data_xi_cov = Data.data_xi_full_cov(**data_dict) # data

        ax.fill_between(r_bin, r_bin*a, r_bin*e, color="k", alpha=0.1, edgecolor="none")
        ax.fill_between(r_bin, r_bin*b, r_bin*d, color="k", alpha=0.3, edgecolor="none")
        ax.errorbar(r_bin, r_bin*data_xi, yerr=r_bin*np.sqrt(np.diag(data_xi_cov)), fmt=".k",
                    capsize=0)
        ax.set_xlabel(r'$r\;[\mathrm{Mpc}/h]$', fontsize=20)
        ax.set_ylabel(r'$r \xi_{\rm gg}$', fontsize=25)
        ax.set_xscale('log')
        ax.set_xlim([0.1, 20.])

    elif observable == 'gmf':   # GMF
        data_gmf, data_gmf_sigma = Data.data_gmf(**data_dict)
        ax.fill_between(r_bin, a, e, color="k", alpha=0.1, edgecolor="none")
        ax.fill_between(r_bin, b, d, color="k", alpha=0.3, edgecolor="none")
        ax.errorbar(r_bin, data_gmf, yerr = data_gmf_sigma, fmt=".k",
                    capsize=0)
        ax.set_xlabel(r'Group Richness', fontsize=25)
        ax.set_ylabel(r'GMF $[\mathrm{h}^3\mathrm{Mpc}^{-3}]$', fontsize=25)

        ax.set_yscale('log')
        ax.set_xlim([1., 50.])

    fig.savefig(
            ''.join([util.fig_dir(),
                observable, '.posterior_prediction',
                '.Mr', str(data_dict['Mr']), '_Nmock', str(data_dict['Nmock']),
                '.pdf']),
            bbox_inches='tight')
예제 #3
0
def plot_posterior_model(observable,
                         abc_theta_file=None,
                         data_dict={
                             'Mr': 20,
                             'b_normal': 0.25,
                             'Nmock': 500
                         },
                         clobber=False):
    '''
    Plot 1\sigma and 2\sigma model predictions from ABC-PMC posterior likelihood

    Parameters
    ----------
    observable : string
        One of the following strings ['xi', 'scaledxi', 'gmf']

    '''
    # load the particles
    if abc_theta_file is None:
        raise ValueError(
            "Please specify the theta output file from ABC-PMC run")
    theta = np.loadtxt(abc_theta_file)

    if observable == 'scaledxi':
        obvs_str = 'xi'
    else:
        obvs_str = observable

    obvs_file = ''.join(
        abc_theta_file.rsplit('.dat')[:-1] + ['.', observable, '.dat'])
    print obvs_file
    if not os.path.isfile(obvs_file) or clobber:
        for i in xrange(len(theta)):
            obv_i = HODsimulator(theta[i],
                                 prior_range=None,
                                 observables=[obvs_str],
                                 Mr=data_dict['Mr'])
            try:
                model_obv.append(obv_i[0])
            except UnboundLocalError:
                model_obv = [obv_i[0]]
        model_obv = np.array(model_obv)
        np.savetxt(obvs_file, model_obv)
    else:
        model_obv = np.loadtxt(obvs_file)

    if 'xi' in observable:
        r_bin = Data.data_xi_bins(Mr=data_dict['Mr'])
    elif observable == 'gmf':
        r_bin = Data.data_gmf_bins()

    a, b, c, d, e = np.percentile(model_obv, [2.5, 16, 50, 84, 97.5], axis=0)

    # plotting
    fig = plt.figure(1)
    ax = fig.add_subplot(111)

    if observable == 'xi':  # 2PCF
        data_xi, data_xi_cov = Data.data_xi_full_cov(**data_dict)  # data

        ax.fill_between(r_bin, a, e, color="k", alpha=0.1, edgecolor="none")
        ax.fill_between(r_bin, b, d, color="k", alpha=0.3, edgecolor="none")
        #ax.plot(r_bin, c, "k", lw=1)
        ax.errorbar(r_bin,
                    data_xi,
                    yerr=np.sqrt(np.diag(data_xi_cov)),
                    fmt=".k",
                    capsize=0)
        ax.set_xlabel(r'$r\;[\mathrm{Mpc}/h]$', fontsize=20)
        ax.set_ylabel(r'$\xi_{\rm gg}$', fontsize=25)
        ax.set_xscale('log')
        ax.set_xlim([0.1, 20.])

    elif observable == 'scaledxi':  # Scaled 2PFC (r * xi)
        data_xi, data_xi_cov = Data.data_xi_full_cov(**data_dict)  # data

        ax.fill_between(r_bin,
                        r_bin * a,
                        r_bin * e,
                        color="k",
                        alpha=0.1,
                        edgecolor="none")
        ax.fill_between(r_bin,
                        r_bin * b,
                        r_bin * d,
                        color="k",
                        alpha=0.3,
                        edgecolor="none")
        ax.errorbar(r_bin,
                    r_bin * data_xi,
                    yerr=r_bin * np.sqrt(np.diag(data_xi_cov)),
                    fmt=".k",
                    capsize=0)
        ax.set_xlabel(r'$r\;[\mathrm{Mpc}/h]$', fontsize=20)
        ax.set_ylabel(r'$r \xi_{\rm gg}$', fontsize=25)
        ax.set_xscale('log')
        ax.set_xlim([0.1, 20.])

    elif observable == 'gmf':  # GMF
        data_gmf, data_gmf_sigma = Data.data_gmf(**data_dict)
        ax.fill_between(r_bin, a, e, color="k", alpha=0.1, edgecolor="none")
        ax.fill_between(r_bin, b, d, color="k", alpha=0.3, edgecolor="none")
        ax.errorbar(r_bin, data_gmf, yerr=data_gmf_sigma, fmt=".k", capsize=0)
        ax.set_xlabel(r'Group Richness', fontsize=25)
        ax.set_ylabel(r'GMF $[\mathrm{h}^3\mathrm{Mpc}^{-3}]$', fontsize=25)

        ax.set_yscale('log')
        ax.set_xlim([1., 50.])

    fig.savefig(''.join([
        util.fig_dir(), observable, '.posterior_prediction', '.Mr',
        str(data_dict['Mr']), '_Nmock',
        str(data_dict['Nmock']), '.pdf'
    ]),
                bbox_inches='tight')