コード例 #1
0
ファイル: NX01_bayesutils.py プロジェクト: stasbabak/NX01
def TF_OSupperLimit(psr,
                    fqs,
                    Tspan,
                    F,
                    GCGnoiseInv,
                    ORF,
                    OSsmbhb,
                    ul_list=None,
                    far=None,
                    drlist=None,
                    tex=True,
                    nlims=70):
    if tex == True:
        plt.rcParams['text.usetex'] = True

    gam_bkgrd = np.linspace(0.01, 6.99, nlims)
    optStatList = []
    ct = 0
    for indx in gam_bkgrd:
        optStatList.append(
            utils.TFoptStat(psr, fqs, Tspan, F, GCGnoiseInv, ORF,
                            gam_gwb=indx)[:3])
        ct += 1
        print "Finished {0}% of optimal-statistic upper-limit calculations...".format(
            100.0 * ct / (1.0 * nlims))

    optStatList = np.array(optStatList)

    fig, ax = plt.subplots()
    stylelist = ['solid', 'dashed', 'dotted']
    if ul_list is not None:
        for ii in range(len(ul_list)):
            ax.plot(
                gam_bkgrd,
                np.sqrt(optStatList[:, 0] + optStatList[:, 1] * np.sqrt(2.0) *
                        (ss.erfcinv(2.0 * (1. - ul_list[ii])))),
                linestyle=stylelist[ii],
                color='black',
                linewidth=3.0,
                label='{0}$\%$ upper-limit'.format(ul_list[ii] * 100))
            plt.hlines(y=np.sqrt(OSsmbhb[0] + OSsmbhb[1] * np.sqrt(2.0) *
                                 (ss.erfcinv(2.0 * (1. - ul_list[ii])))),
                       xmin=gam_bkgrd.min(),
                       xmax=13. / 3.,
                       linewidth=3.0,
                       linestyle='solid',
                       color='red')
            plt.vlines(x=13. / 3.,
                       ymin=0.0,
                       ymax=np.sqrt(OSsmbhb[0] + OSsmbhb[1] * np.sqrt(2.0) *
                                    (ss.erfcinv(2.0 * (1. - ul_list[ii])))),
                       linewidth=3.0,
                       linestyle='solid',
                       color='red')
    else:
        for ii in range(len(drlist)):
            ax.plot(
                gam_bkgrd,
                np.sqrt(
                    optStatList[:, 1] * np.sqrt(2.0) *
                    (ss.erfcinv(2.0 * far) - ss.erfcinv(2.0 * drlist[ii]))),
                linestyle=stylelist[ii],
                color='black',
                linewidth=3.0,
                label='$A$ ({0}$\%$ FAR, {1}$\%$ DR)'.format(
                    far * 100, drlist[ii] * 100))
            plt.hlines(y=np.sqrt(
                OSsmbhb * np.sqrt(2.0) *
                (ss.erfcinv(2.0 * far) - ss.erfcinv(2.0 * drlist[ii]))),
                       xmin=gam_bkgrd.min(),
                       xmax=13. / 3.,
                       linewidth=3.0,
                       linestyle='solid',
                       color='red')
            plt.vlines(
                x=13. / 3.,
                ymin=0.0,
                ymax=np.sqrt(
                    OSsmbhb * np.sqrt(2.0) *
                    (ss.erfcinv(2.0 * far) - ss.erfcinv(2.0 * drlist[ii]))),
                linewidth=3.0,
                linestyle='solid',
                color='red')

    ax.set_yscale('log')
    ax.set_xlabel(r'$\gamma\equiv 3-2\alpha$', fontsize=20)
    ax.set_ylabel(r'$A$', fontsize=20)
    ax.minorticks_on()
    plt.tick_params(labelsize=18)
    plt.grid(which='major')
    plt.grid(which='minor')
    plt.title('Optimal-statistic bounds')
    plt.legend(loc='lower left', shadow=True, frameon=True, prop={'size': 15})
    plt.show()