Esempio n. 1
0
File: model.py Progetto: nhmc/LAE
def plot_model(pars):    
    """ Plot the observed values and errors, along with the predicted
    model values.
    """
    import matplotlib.pyplot as pl
    from barak.plot import draw_arrows, puttext

    fig = pl.figure(figsize=(6.4, 3.4))
    ax = fig.add_subplot(111)
    ms = 6
    ipot = [get_ionization_energy(t) for t in tr_plot]
    for i,tr in enumerate(tr_plot):
        if use_ipot:
            ind = ipot[i]
        else:
            ind = i
        if tr in obs:
            colour = 'k' if tr in trans else 'w'
            fmt = 'o' + colour
            val, siglo, sighi = obs[tr]
            if siglo == 0:
                draw_arrows(ind, val, direction='up', ax=ax,lw=1)
                ax.plot(ind, val, fmt,ms=ms)
            elif sighi == 0:
                draw_arrows(ind, val, direction='down', ax=ax,lw=1)
                ax.plot(ind, val, fmt,ms=ms)
            else:
                ax.plot([ind, ind], [val-siglo, val+sighi], 'k',lw=1)
                ax.plot(ind, val, fmt,ms=ms)
            ax.text(ind, val + 0.8, tr,
                    fontsize=10, ha='center')
        else:
            puttext(ind, 0.02, tr, ax=ax, xcoord='data',
                    fontsize=10, ha='center')

    puttext(0.9,0.1, 'Model', ax, color='r', ha='right')

    xvals = list(range(len(tr_plot)))
    #print np.asarray(pars).shape
    for par in pars:
        Nmodel = model(par, for_plot=True)
        if use_ipot:
            if len(pars) == 1:
                ax.plot(ipot, Nmodel, 'r.-', lw=1, zorder=0)
            else:
                ax.plot(ipot, Nmodel, 'r-', lw=0.2, zorder=0)
        else:
            if len(pars) == 1:
                ax.plot(xvals, Nmodel, 'r.-', lw=1, zorder=0)
            else:
                ax.plot(xvals, Nmodel, 'r-', lw=0.2, zorder=0)

    if use_ipot:
        ax.set_xlabel('Ionization potential (eV)')
        ax.set_xlim(ipot[0]-1, ipot[-1] + 1)
    else:
        ax.set_xlim(-0.5, xvals[-1] + 0.5)
        ax.set_xticks([])

    ax.set_ylabel(r'$\log_{10}\ N$')
    fig.tight_layout()
    #return fig, ax
    return fig
Esempio n. 2
0
def plot_model(pars):
    """ Plot the observed values and errors, along with the predicted
    model values.
    """
    import matplotlib.pyplot as pl
    from barak.plot import draw_arrows, puttext

    fig = pl.figure(figsize=(6.4, 3.4))
    ax = fig.add_subplot(111)
    ms = 6
    ipot = [get_ionization_energy(t) for t in tr_plot]
    for i, tr in enumerate(tr_plot):
        if use_ipot:
            ind = ipot[i]
        else:
            ind = i
        if tr in obs:
            colour = 'k' if tr in trans else 'w'
            fmt = 'o' + colour
            val, siglo, sighi = obs[tr]
            if siglo == 0:
                draw_arrows(ind, val, direction='up', ax=ax, lw=1)
                ax.plot(ind, val, fmt, ms=ms)
            elif sighi == 0:
                draw_arrows(ind, val, direction='down', ax=ax, lw=1)
                ax.plot(ind, val, fmt, ms=ms)
            else:
                ax.plot([ind, ind], [val - siglo, val + sighi], 'k', lw=1)
                ax.plot(ind, val, fmt, ms=ms)
            ax.text(ind, val + 0.8, tr, fontsize=10, ha='center')
        else:
            puttext(ind,
                    0.02,
                    tr,
                    ax=ax,
                    xcoord='data',
                    fontsize=10,
                    ha='center')

    puttext(0.9, 0.1, 'Model', ax, color='r', ha='right')

    xvals = list(range(len(tr_plot)))
    #print np.asarray(pars).shape
    for par in pars:
        Nmodel = model(par, for_plot=True)
        if use_ipot:
            if len(pars) == 1:
                ax.plot(ipot, Nmodel, 'r.-', lw=1, zorder=0)
            else:
                ax.plot(ipot, Nmodel, 'r-', lw=0.2, zorder=0)
        else:
            if len(pars) == 1:
                ax.plot(xvals, Nmodel, 'r.-', lw=1, zorder=0)
            else:
                ax.plot(xvals, Nmodel, 'r-', lw=0.2, zorder=0)

    if use_ipot:
        ax.set_xlabel('Ionization potential (eV)')
        ax.set_xlim(ipot[0] - 1, ipot[-1] + 1)
    else:
        ax.set_xlim(-0.5, xvals[-1] + 0.5)
        ax.set_xticks([])

    ax.set_ylabel(r'$\log_{10}\ N$')
    fig.tight_layout()
    #return fig, ax
    return fig
Esempio n. 3
0
               )

names =  ('nH', 'aUV','T','NH','D','Pk')
for i in range(6):
    ax = fig.add_subplot(12,1,i+7)
    k = names[i]
    v = V[k]
    c0 = v['limit'] == 'none'
    v1 = v[c0]
    errplot(dv[c0], v1['val'], (v1['val']-v1['erlo'],
                                v1['val']+v1['erhi']), c='k',
            ax=ax, lw=0.5, ms=6)
    c0 =  v['limit'] == 'upper'
    if c0.any():
        v1 = v[c0]
        draw_arrows(dv[c0], v1['val'], ax=ax, direction='down', c='k',lw=0.5)
        errplot(dv[c0], v1['val'], 0, ax=ax, lw=0.5, ms=6, c='k')
    c0 =  v['limit'] == 'lower'
    if c0.any():
        v1 = v[c0]
        if k in ('D', 'NH'):
            # tweak so lower limit arrow still shows
            draw_arrows(dv[c0], v1['val']+0.55, ax=ax,direction='up',c='k',
                        ms=0.6,capsize=4,lw=0.5)
        else:
            draw_arrows(dv[c0], v1['val'], ax=ax,direction='up',c='k',
                        ms=0.6,capsize=4,lw=0.5)
            errplot(dv[c0], v1['val'], 0, ax=ax, lw=0.5, ms=6, c='k')
    c0 = v['strong_prior']
    v1 = v[c0]
    errplot(dv[c0], v1['val'], (v1['val']-v1['erlo'],v1['val']+v1['erhi']),
Esempio n. 4
0
    fig = pl.figure(figsize=(4.3, 6))
    fig.subplots_adjust(right=0.97, top=0.92,bottom=0.09)
    ax = pl.subplot(111)

    plot_trans_vs_U(iZ, iNHI, M, trans1, ax)
    ax.set_ylim(11.1, 16.3)

    # observed values
    val,sig = obs['MgII'][:2]
    ax.plot(nHbest, val, 'o', mec=COLORS['Mg'], mew=2, mfc='w', ms=6)
    val,sig = obs['MgI'][:2]
    ax.plot(nHbest, val, 'o', color=COLORS['Mg'], ms=9, mew=2, mec='w')
    val,sig = obs['NI'][:2]
    ax.plot(nHbest, val, 'o', color=COLORS['N'], ms=9, mew=2, mec='w')
    draw_arrows(nHbest, val, ax=ax, c=COLORS['N'],ms=1.5,capsize=5,
                lw=2, direction='down', zorder=6)
    val,sig = obs['NII'][:2]
    ax.plot(nHbest, val, 'o',mec=COLORS['N'], mew=2, mfc='w', ms=6)
    val,siglo,sighi = obs['OI']
    ax.plot(nHbest, val, 'o', color=COLORS['O'], ms=9, mew=2, mec='w')
    val,sig = obs['FeII'][:2]
    ax.plot(nHbest-0.2, val, 'o', color=COLORS['Fe'], ms=9, mew=2, mec='w')
    #pl.savefig('cloudy1.pdf')
    #pl.savefig('cloudy1.png')

if 0:
    trans2 = ('HIII CaII SiII SiIII SiIV CI CII CIII').split()
    fig = pl.figure(figsize=(4.3, 6))
    fig.subplots_adjust(right=0.97, top=0.92,bottom=0.09)
    ax = pl.subplot(111)
Esempio n. 5
0
        # ax.plot(x, y, '-k',zorder=1)
        # x = 2 * [np.log10(10**c6_NHI + 2*10**c6_NH2)]
        # y = [np.log10(2*10**c6_NH2lo / (10**c6_NHI + 2*10**c6_NH2lo)),
        #      np.log10(2*10**c6_NH2hi / (10**c6_NHI + 2*10**c6_NH2hi))]
        # ax.plot(x, y, '-k',zorder=1)

    else:
        ax.plot(F.MWplane[0], np.log10(F.MWplane[1]), 'cv', ms=5,  label='$\mathrm{In MW plane}$')
        ax.plot(F.IVC[0],     np.log10(F.IVC[1]    ), 'b^', ms=5, label= '$\mathrm{IVC}$')
        ax.plot(F.s01[0],     np.log10(F.s01[1]    ), 'mp', ms=7)
        ax.plot(F.r01[0],     np.log10(F.r01[1]    ), 'mp', ms=7)
        ax.plot(F.r99[0],     np.log10(F.r99[1]    ), 'mp', ms=7,   label='$\mathrm{HVC}$')
        ax.plot(F.SMC[0],     np.log10(F.SMC[1]    ), 'rD', ms=4.5, label='$\mathrm{SMC}$')
        ax.plot(F.LMC[0],     np.log10(F.LMC[1]    ), 'gs', ms=5,   label='$\mathrm{LMC}$')
        ax.plot(F.DLA[0],     np.log10(F.DLA[1]    ), 'ok', ms=6, mfc='none', label='\mathrm{z>1.5 DLA}$')
        draw_arrows(F.p02[0],     np.log10(F.p02[1]), ax, ms=1.5, capsize=4)
        ax.plot(F.p02[0],     np.log10(F.p02[1]    ), 'ok', ms=6, mfc='w')
        ax.plot(F.C5[0],      np.log10(F.C5[1]     ), '*k', ms=12)
        ax.plot(F.C6[0],      np.log10(F.C6[1]     ), '*k', ms=12,label='$\mathrm{z=0.56 sub-DLA}$')
        #col = ax.scatter(F.Clo[0],   np.log10(F.Clo[1]     ), marker='o', c='w',s=40, 
        #           label='z=0.56 sub-DLA (lower limit)')
        #col.set_linestyles([(0, (2, 1))])

    if 0:#xaxis != 'NH2':
        bins = np.arange(-9.1, 2.01, 0.6)
        y,_ = np.histogram(np.log10(np.concatenate(
            [np.atleast_1d(F[k][1]) for k in F])), bins)
        b = np.repeat(bins, 2)
        Y = np.concatenate([[0], np.repeat(y,2), [0]])
        Y = 0.2 * Y / Y.max()
        import matplotlib.transforms as mtransforms