Ejemplo n.º 1
0
def fig2_compare_allsample(gals, data_dict):
    NGals = len(gals)
    old_Hb__gz = data_dict['old_Hb__gz']
    old_eHb__gz = data_dict['old_eHb__gz']
    old_O3__gz = data_dict['old_O3__gz']
    old_eO3__gz = data_dict['old_eO3__gz']
    old_Ha__gz = data_dict['old_Ha__gz']
    old_eHa__gz = data_dict['old_eHa__gz']
    old_N2__gz = data_dict['old_N2__gz']
    old_eN2__gz = data_dict['old_eN2__gz']
    old_WHa__gz = data_dict['old_WHa__gz']
    new_Hb__gz = data_dict['new_Hb__gz']
    new_eHb__gz = data_dict['new_eHb__gz']
    new_O3__gz = data_dict['new_O3__gz']
    new_eO3__gz = data_dict['new_eO3__gz']
    new_Ha__gz = data_dict['new_Ha__gz']
    new_eHa__gz = data_dict['new_eHa__gz']
    new_N2__gz = data_dict['new_N2__gz']
    new_eN2__gz = data_dict['new_eN2__gz']
    new_WHa__gz = data_dict['new_WHa__gz']
    BPTLines_dict = {
        '4861': dict(old_flux=old_Hb__gz, old_eflux=old_eHb__gz, new_flux=new_Hb__gz, new_eflux=new_eHb__gz),
        '5007': dict(old_flux=old_O3__gz, old_eflux=old_eO3__gz, new_flux=new_O3__gz, new_eflux=new_eO3__gz),
        '6563': dict(old_flux=old_Ha__gz, old_eflux=old_eHa__gz, new_flux=new_Ha__gz, new_eflux=new_eHa__gz),
        '6583': dict(old_flux=old_N2__gz, old_eflux=old_eN2__gz, new_flux=new_N2__gz, new_eflux=new_eN2__gz),
    }
    old_tauVNeb = f_tauVneb(old_Ha__gz, old_Hb__gz)
    new_tauVNeb = f_tauVneb(new_Ha__gz, new_Hb__gz)
    N_cols = 4
    N_rows = 3
    f, axArr = plt.subplots(N_rows, N_cols, dpi=200, figsize=(N_cols * 5, N_rows * 4))
    f.suptitle('%d galaxies' % NGals)
    ((ax1, ax2, ax3, ax4), (ax5, ax6, ax7, ax8), (ax9, ax10, ax11, ax12)) = axArr
    axArr = [ax1, ax2, ax3, ax4, ax5, ax6, ax7, ax8]
    for i_l, l in enumerate(BPTlines):
        old_f = BPTLines_dict[l]['old_flux']
        new_f = BPTLines_dict[l]['new_flux']
        new_snr = new_f/BPTLines_dict[l]['new_eflux']
        sel_f = np.bitwise_and(np.bitwise_and(np.greater(old_f, 0), np.greater(new_f, 0)), np.greater_equal(new_snr, SNRthreshold))
        ax = axArr[i_l]
        x = np.ma.log10(1.+new_snr)
        y = (new_f - old_f)/new_f
        xm, ym = ma_mask_xyz(x, y, mask=~sel_f)
        ini_pos_y = 0.45
        if l[0] == '6':
            ini_pos_y = 0.98
        plot_histo_ax(ax, ym.compressed(), ini_pos_y=ini_pos_y, y_v_space=0.07, first=True, histo=False, stats_txt=True, c='k')
        ax.scatter(xm, ym, **dflt_kw_scatter)
        ax.axhline(y=0, c='k', ls='--')
        ax.set_xlabel(r'$\log$ (1+SN${}_{NEW}$)')
        ax.set_ylabel(r'(F${}_{NEW}$ - F${}_{OLD}$)/F${}_{NEW}$')
        ax.set_title(l)
        ax.set_xlim(logSNRrange)
        ax.xaxis.set_major_locator(MaxNLocator(5))
        ax.xaxis.set_minor_locator(MaxNLocator(25))
        ax.yaxis.set_major_locator(MaxNLocator(5))
        ax.yaxis.set_minor_locator(MaxNLocator(25))
        ax.grid()
    snrHa = new_Ha__gz/new_eHa__gz
    snrHb = new_Hb__gz/new_eHb__gz
    x = np.ma.log10(1.+snrHb)
    y = (new_tauVNeb - old_tauVNeb)
    sel = np.bitwise_and(np.greater_equal(snrHa, SNRthreshold), np.greater_equal(snrHb, SNRthreshold))
    xm, ym = ma_mask_xyz(x, y, mask=~sel)
    ax5.scatter(xm, ym, **dflt_kw_scatter)
    ax5.set_xlabel(r'$\log$ (1+SN${}_{H\beta}$)')
    ax5.set_ylabel(r'($\tau_V^{NEW}$ - $\tau_V^{OLD}$)')
    ax5.axhline(y=0, c='k', ls='--')
    plot_histo_ax(ax5, ym.compressed(), ini_pos_y=0.98, y_v_space=0.07, first=True, histo=False, stats_txt=True, c='k')
    ax5.set_xlim(logSNRrange)
    ax5.xaxis.set_major_locator(MaxNLocator(5))
    ax5.xaxis.set_minor_locator(MaxNLocator(25))
    ax5.yaxis.set_major_locator(MaxNLocator(5))
    ax5.yaxis.set_minor_locator(MaxNLocator(25))
    ax5.grid()
    x = np.ma.log10(new_WHa__gz)
    sel = np.bitwise_and(np.greater_equal(snrHa, SNRthreshold), np.greater_equal(snrHb, SNRthreshold))
    xm, ym = ma_mask_xyz(x, y, mask=~sel)
    ax6.scatter(xm, ym, **dflt_kw_scatter)
    ax6.axhline(y=0, c='k', ls='--')
    ax6.set_xlabel(r'$\log\ W_{H\alpha}$')
    ax6.set_ylabel(r'($\tau_V^{NEW}$ - $\tau_V^{OLD}$)')
    plot_histo_ax(ax6, ym.compressed(), ini_pos_y=0.98, y_v_space=0.07, first=True, histo=False, stats_txt=True, c='k')
    ax6.set_xlim(logWHa_range)
    ax6.xaxis.set_major_locator(MaxNLocator(5))
    ax6.xaxis.set_minor_locator(MaxNLocator(25))
    ax6.yaxis.set_major_locator(MaxNLocator(5))
    ax6.yaxis.set_minor_locator(MaxNLocator(25))
    ax6.grid()
    x = np.ma.log10(old_WHa__gz)
    y = old_tauVNeb
    sel = np.bitwise_and(np.greater_equal(snrHa, SNRthreshold), np.greater_equal(snrHb, SNRthreshold))
    xm, ym = ma_mask_xyz(x, y, mask=~sel)
    ax7.scatter(xm, ym, **dflt_kw_scatter)
    plot_spearmanr_ax(ax=ax7, x=xm.compressed(), y=ym.compressed(), horizontalalignment='right', pos_x=0.99, pos_y=0.99, fontsize=14)
    ax7.axhline(y=0, c='k', ls='--')
    ax7.set_xlabel(r'$\log\ W_{H\alpha}$ OLD')
    ax7.set_ylabel(r'$\tau_V^{neb}$ OLD')
    x_range = logWHa_range
    xbins = np.arange(x_range[0], x_range[1] + 0.2, 0.2)
    yMean, prc, bin_center, npts = stats_med12sigma(xm.compressed(), ym.compressed(), xbins)
    yMedian = prc[2]
    y_12sigma = [prc[0], prc[1], prc[3], prc[4]]
    ax7.plot(bin_center, yMedian, 'k-', lw=2)
    for y_prc in y_12sigma:
        ax7.plot(bin_center, y_prc, 'k--', lw=2)
    # plot_histo_ax(ax7, ym.compressed(), ini_pos_y=0.45, y_v_space=0.07, first=True, histo=False, stats_txt=True, c='k')
    ax7.set_xlim(logWHa_range)
    ax7.xaxis.set_major_locator(MaxNLocator(5))
    ax7.xaxis.set_minor_locator(MaxNLocator(25))
    ax7.yaxis.set_major_locator(MaxNLocator(5))
    ax7.yaxis.set_minor_locator(MaxNLocator(25))
    ax7.grid()
    x = np.ma.log10(new_WHa__gz)
    y = new_tauVNeb
    sel = np.bitwise_and(np.greater_equal(snrHa, SNRthreshold), np.greater_equal(snrHb, SNRthreshold))
    xm, ym = ma_mask_xyz(x, y, mask=~sel)
    ax8.scatter(xm, ym, **dflt_kw_scatter)
    plot_spearmanr_ax(ax=ax8, x=xm.compressed(), y=ym.compressed(), horizontalalignment='right', pos_x=0.99, pos_y=0.99, fontsize=14)
    ax8.axhline(y=0, c='k', ls='--')
    ax8.set_xlabel(r'$\log\ W_{H\alpha}$ NEW')
    ax8.set_ylabel(r'$\tau_V^{neb}$ NEW')
    x_range = logWHa_range
    xbins = np.arange(x_range[0], x_range[1] + 0.2, 0.2)
    yMean, prc, bin_center, npts = stats_med12sigma(xm.compressed(), ym.compressed(), xbins)
    yMedian = prc[2]
    y_12sigma = [prc[0], prc[1], prc[3], prc[4]]
    ax8.plot(bin_center, yMedian, 'k-', lw=2)
    for y_prc in y_12sigma:
        ax8.plot(bin_center, y_prc, 'k--', lw=2)
    # plot_histo_ax(ax8, ym.compressed(), ini_pos_y=0.45, y_v_space=0.07, first=True, histo=False, stats_txt=True, c='k')
    ax8.set_xlim(logWHa_range)
    ax8.xaxis.set_major_locator(MaxNLocator(5))
    ax8.xaxis.set_minor_locator(MaxNLocator(25))
    ax8.yaxis.set_major_locator(MaxNLocator(5))
    ax8.yaxis.set_minor_locator(MaxNLocator(25))
    ax8.grid()
    sel = np.bitwise_and(np.greater_equal(snrHa, SNRthreshold), np.greater_equal(snrHb, SNRthreshold))
    old_tauVNebm, new_tauVNebm = ma_mask_xyz(old_tauVNeb, new_tauVNeb, mask=~sel)
    plot_histo_ax(ax9, old_tauVNebm.compressed(), histo=True, stats=True, first=True, ini_pos_y=0.98, y_v_space=0.07, c='k', kwargs_histo=dict(normed=False, range=[-6, 6]))
    ax9.set_xlabel(r'$\tau_V^{neb}$ OLD')
    plot_histo_ax(ax10, new_tauVNebm.compressed(), histo=True, stats=True, first=True, ini_pos_y=0.98, y_v_space=0.07, c='k', kwargs_histo=dict(normed=False, range=[-6, 6]))
    ax10.set_xlabel(r'$\tau_V^{neb}$ NEW')
    WHamax = 8
    sel = np.bitwise_and(np.greater_equal(snrHa, SNRthreshold), np.greater_equal(snrHb, SNRthreshold))
    sel = np.bitwise_and(sel, np.less(new_WHa__gz, WHamax))
    old_tauVNebm, new_tauVNebm = ma_mask_xyz(old_tauVNeb, new_tauVNeb, mask=~sel)
    plot_histo_ax(ax11, old_tauVNebm.compressed(), histo=True, dataset_names='total', stats=True, first=True, pos_x=0.4, ini_pos_y=0.98, y_v_space=0.07, c='b', kwargs_histo=dict(normed=False, range=[-6, 6]))
    plot_histo_ax(ax12, new_tauVNebm.compressed(), histo=True, dataset_names='total', stats=True, first=True, pos_x=0.4, ini_pos_y=0.98, y_v_space=0.07, c='b', kwargs_histo=dict(normed=False, range=[-6, 6]))
    SNRmax = 3
    sel = np.bitwise_and(np.greater_equal(snrHa, SNRmax), np.greater_equal(snrHb, SNRmax))
    sel = np.bitwise_and(sel, np.less(new_WHa__gz, WHamax))
    old_tauVNebm, new_tauVNebm = ma_mask_xyz(old_tauVNeb, new_tauVNeb, mask=~sel)
    plot_histo_ax(ax11, old_tauVNebm.compressed(), histo=True, dataset_names='SN >= %d' % SNRmax, stats=True, ini_pos_y=0.98, y_v_space=0.07, c='k', kwargs_histo=dict(normed=False, color='k', alpha=0.5, range=[-6, 6]))
    plot_histo_ax(ax12, new_tauVNebm.compressed(), histo=True, dataset_names='SN >= %d' % SNRmax, stats=True, ini_pos_y=0.98, y_v_space=0.07, c='k', kwargs_histo=dict(normed=False, color='k', alpha=0.5, range=[-6, 6]))
    ax11.set_title(r'W${}_{H\alpha}\ <\ %d$' % WHamax)
    ax12.set_title(r'W${}_{H\alpha}\ <\ %d$' % WHamax)
    ax11.set_xlabel(r'$\tau_V^{neb}$ OLD')
    ax12.set_xlabel(r'$\tau_V^{neb}$ NEW')
    f.tight_layout(w_pad=0.8, h_pad=0.8)
    f.savefig('%s_comparelines_allsample.png' % '-'.join(vcompare), dpi=dpi_choice, transparent=transp_choice)
    plt.close(f)
Ejemplo n.º 2
0
def fig1_compare_gal(gals, plot_data=True):
    old_Hb__gz = []
    old_eHb__gz = []
    old_O3__gz = []
    old_eO3__gz = []
    old_Ha__gz = []
    old_eHa__gz = []
    old_N2__gz = []
    old_eN2__gz = []
    old_WHa__gz = []
    old_v0Hb__gz = []
    new_Hb__gz = []
    new_eHb__gz = []
    new_O3__gz = []
    new_eO3__gz = []
    new_Ha__gz = []
    new_eHa__gz = []
    new_N2__gz = []
    new_eN2__gz = []
    new_WHa__gz = []
    new_v0Hb__gz = []
    print gals
    for califaID in gals:
        oldELdir = '/Users/lacerda/RGB/Bgstf6e/%s' % vcompare[0]  # '/Users/lacerda/califa/legacy/q054/EML/Bgstf6e'
        oldELsuf = '_synthesis_eBR_v20_q054.d22a512.ps03.k1.mE.CCM.Bgstf6e.EML.MC100.fits'
        oldEL = EmLinesDataCube('%s/%s%s' % (oldELdir, califaID, oldELsuf))
        oldf__lz = {l: oldEL.flux[oldEL.lines.index(l)] for l in BPTlines}
        oldef__lz = {l: oldEL.eflux[oldEL.lines.index(l)] for l in BPTlines}
        oldW6563__z = oldEL.EW[oldEL.lines.index('6563')]
        oldtauVneb__z = f_tauVneb(oldf__lz['6563'], oldf__lz['4861'])
        newELdir = '/Users/lacerda/RGB/Bgstf6e/%s' % vcompare[1]
        newELsuf = '_synthesis_eBR_v20_q054.d22a512.ps03.k1.mE.CCM.Bgstf6e.EML.MC100.fits'
        newEL = EmLinesDataCube('%s/%s%s' % (newELdir, califaID, newELsuf))
        newf__lz = {l: newEL.flux[newEL.lines.index(l)] for l in BPTlines}
        newef__lz = {l: newEL.eflux[newEL.lines.index(l)] for l in BPTlines}
        newW6563__z = newEL.EW[newEL.lines.index('6563')]
        newtauVneb__z = f_tauVneb(newf__lz['6563'], newf__lz['4861'])
        old_Hb__gz.append(oldf__lz['4861'])
        old_eHb__gz.append(oldef__lz['4861'])
        old_O3__gz.append(oldf__lz['5007'])
        old_eO3__gz.append(oldef__lz['5007'])
        old_Ha__gz.append(oldf__lz['6563'])
        old_eHa__gz.append(oldef__lz['6563'])
        old_N2__gz.append(oldf__lz['6583'])
        old_eN2__gz.append(oldef__lz['6583'])
        old_WHa__gz.append(oldW6563__z)
        new_Hb__gz.append(newf__lz['4861'])
        new_eHb__gz.append(newef__lz['4861'])
        new_O3__gz.append(newf__lz['5007'])
        new_eO3__gz.append(newef__lz['5007'])
        new_Ha__gz.append(newf__lz['6563'])
        new_eHa__gz.append(newef__lz['6563'])
        new_N2__gz.append(newf__lz['6583'])
        new_eN2__gz.append(newef__lz['6583'])
        new_WHa__gz.append(newW6563__z)
        wl0_Hb = 4861.
        old_posHb = oldEL.pos[oldEL.lines.index('4861')]
        old_v0Hb = c * (old_posHb - wl0_Hb)/wl0_Hb
        new_posHb = newEL.pos[newEL.lines.index('4861')]
        new_v0Hb = c * (new_posHb - wl0_Hb)/wl0_Hb
        old_v0Hb__gz.append(old_v0Hb)
        new_v0Hb__gz.append(new_v0Hb)
        if plot_data:
            ###############################################################
            ###############################################################
            ###############################################################
            N_cols = 2
            N_rows = 3
            f, axArr = plt.subplots(N_rows, N_cols, dpi=200, figsize=(N_cols * 5, N_rows * 4))
            f.suptitle('%s' % califaID)
            ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = axArr
            axArr = [ax1, ax2, ax3, ax4, ax5, ax6]
            for i_l, l in enumerate(BPTlines):
                old_f = oldf__lz[l]
                new_f = newf__lz[l]
                new_snr = new_f/newef__lz[l]
                sel_f = np.bitwise_and(np.bitwise_and(np.greater(old_f, 0), np.greater(new_f, 0)), np.greater_equal(new_snr, 1.))
                ax = axArr[i_l]
                x = np.ma.log10(1.+new_snr)
                y = (new_f - old_f)/new_f
                xm, ym = ma_mask_xyz(x, y, mask=~sel_f)
                plot_histo_ax(ax, ym.compressed(), ini_pos_y=0.45, y_v_space=0.07, first=True, histo=False, stats_txt=True, c='k')
                ax.scatter(xm, ym, **dflt_kw_scatter)
                ax.axhline(y=0, c='k', ls='--')
                ax.set_xlabel(r'$\log$ (1+SN${}_{NEW}$)')
                ax.set_ylabel(r'(F${}_{NEW}$ - F${}_{OLD}$)/F${}_{NEW}$')
                ax.set_title(l)
                ax.set_xlim(logSNRrange)
                ax.xaxis.set_major_locator(MaxNLocator(5))
                ax.xaxis.set_minor_locator(MaxNLocator(25))
                ax.yaxis.set_major_locator(MaxNLocator(5))
                ax.yaxis.set_minor_locator(MaxNLocator(25))
            snrHb__z = newf__lz['4861']/newef__lz['4861']
            snrHa__z = newf__lz['6563']/newef__lz['6563']
            x = np.ma.log10(1.+snrHb__z)
            y = (newtauVneb__z - oldtauVneb__z)
            sel = np.bitwise_and(np.greater_equal(snrHa__z, SNRthreshold), np.greater_equal(snrHb__z, SNRthreshold))
            xm, ym = ma_mask_xyz(x, y, mask=~sel)
            ax5.scatter(xm, ym, **dflt_kw_scatter)
            ax5.set_xlabel(r'$\log$ (1+SN${}_{H\beta}$)')
            ax5.set_ylabel(r'($\tau_V^{NEW}$ - $\tau_V^{OLD}$)')
            ax5.axhline(y=0, c='k', ls='--')
            plot_histo_ax(ax5, ym.compressed(), ini_pos_y=0.98, y_v_space=0.07, first=True, histo=False, stats_txt=True, c='k')
            ax5.set_xlim(logSNRrange)
            ax5.xaxis.set_major_locator(MaxNLocator(5))
            ax5.xaxis.set_minor_locator(MaxNLocator(25))
            ax5.yaxis.set_major_locator(MaxNLocator(5))
            ax5.yaxis.set_minor_locator(MaxNLocator(25))
            x = np.ma.log10(newW6563__z)
            xm, ym = ma_mask_xyz(x, y, mask=~np.greater_equal(snrHa__z, SNRthreshold))
            ax6.scatter(xm, ym, **dflt_kw_scatter)
            ax6.axhline(y=0, c='k', ls='--')
            ax6.set_xlabel(r'$\log\ W_{H\alpha}$')
            ax6.set_ylabel(r'($\tau_V^{NEW}$ - $\tau_V^{OLD}$)')
            plot_histo_ax(ax6, ym.compressed(), ini_pos_y=0.98, y_v_space=0.07, first=True, histo=False, stats_txt=True, c='k')
            ax6.set_xlim(logWHa_range)
            ax6.xaxis.set_major_locator(MaxNLocator(5))
            ax6.xaxis.set_minor_locator(MaxNLocator(25))
            ax6.yaxis.set_major_locator(MaxNLocator(5))
            ax6.yaxis.set_minor_locator(MaxNLocator(25))
            f.tight_layout(w_pad=0.8, h_pad=0.8)
            f.savefig('%s_%s_comparelines.png' % ('-'.join(vcompare), califaID), dpi=dpi_choice, transparent=transp_choice)
            plt.close(f)
            ###############################################################
            ###############################################################
            ###############################################################
    ret_dict = dict(
        old_O3__gz=np.ma.hstack(old_O3__gz),
        old_eO3__gz=np.ma.hstack(old_eO3__gz),
        old_Hb__gz=np.ma.hstack(old_Hb__gz),
        old_eHb__gz=np.ma.hstack(old_eHb__gz),
        old_Ha__gz=np.ma.hstack(old_Ha__gz),
        old_eHa__gz=np.ma.hstack(old_eHa__gz),
        old_N2__gz=np.ma.hstack(old_N2__gz),
        old_eN2__gz=np.ma.hstack(old_eN2__gz),
        old_WHa__gz=np.ma.hstack(old_WHa__gz),
        new_O3__gz=np.ma.hstack(new_O3__gz),
        new_eO3__gz=np.ma.hstack(new_eO3__gz),
        new_Hb__gz=np.ma.hstack(new_Hb__gz),
        new_eHb__gz=np.ma.hstack(new_eHb__gz),
        new_Ha__gz=np.ma.hstack(new_Ha__gz),
        new_eHa__gz=np.ma.hstack(new_eHa__gz),
        new_N2__gz=np.ma.hstack(new_N2__gz),
        new_eN2__gz=np.ma.hstack(new_eN2__gz),
        new_WHa__gz=np.ma.hstack(new_WHa__gz),
        old_v0Hb__gz=np.ma.hstack(old_v0Hb__gz),
        new_v0Hb__gz=np.ma.hstack(new_v0Hb__gz),
    )
    return ret_dict
Ejemplo n.º 3
0
def histograms_HaHb_Dt(ALL):
    # WHa DIG-COMP-HII decomposition
    sel_WHa_DIG__z = (ALL.W6563__z < DIG_WHa_threshold).filled(False)
    sel_WHa_COMP__z = np.bitwise_and(
        (ALL.W6563__z >= DIG_WHa_threshold).filled(False),
        (ALL.W6563__z < HII_WHa_threshold).filled(False))
    sel_WHa_HII__z = (ALL.W6563__z >= HII_WHa_threshold).filled(False)
    sel_WHa_DIG__yx = (ALL.W6563__yx < DIG_WHa_threshold).filled(False)
    sel_WHa_COMP__yx = np.bitwise_and(
        (ALL.W6563__yx >= DIG_WHa_threshold).filled(False),
        (ALL.W6563__yx < HII_WHa_threshold).filled(False))
    sel_WHa_HII__yx = (ALL.W6563__yx >= HII_WHa_threshold).filled(False)

    # SBHa-Zhang DIG-COMP-HII decomposition
    sel_Zhang_DIG__z = (ALL.SB6563__z < DIG_Zhang_threshold).filled(False)
    sel_Zhang_COMP__z = np.bitwise_and(
        (ALL.SB6563__z >= DIG_Zhang_threshold).filled(False),
        (ALL.SB6563__z < HII_Zhang_threshold).filled(False))
    sel_Zhang_HII__z = (ALL.SB6563__z >= HII_Zhang_threshold).filled(False)
    sel_Zhang_DIG__yx = (ALL.SB6563__yx < DIG_Zhang_threshold).filled(False)
    sel_Zhang_COMP__yx = np.bitwise_and(
        (ALL.SB6563__yx >= DIG_Zhang_threshold).filled(False),
        (ALL.SB6563__yx < HII_Zhang_threshold).filled(False))
    sel_Zhang_HII__yx = (ALL.SB6563__yx >= HII_Zhang_threshold).filled(False)

    tau_V_neb__z = ALL.tau_V_neb__z
    tau_V_neb__yx = ALL.tau_V_neb__yx

    N_cols = 2
    N_rows = 2
    f, axArr = plt.subplots(N_rows, N_cols, dpi=100, figsize=(15, 10))
    ((ax1, ax2), (ax3, ax4)) = axArr
    x = np.ma.log10(ALL.f6563__z / ALL.f4861__z)
    range = logHaHb_range
    xDs = [
        x[sel_WHa_DIG__z].compressed(), x[sel_WHa_COMP__z].compressed(),
        x[sel_WHa_HII__z].compressed()
    ]
    ax1.set_title('zones')
    print 'ax1'
    plot_histo_ax(ax1,
                  x.compressed(),
                  histo=False,
                  y_v_space=0.06,
                  ha='left',
                  pos_x=0.02,
                  c='k',
                  first=True)
    plot_histo_ax(ax1,
                  xDs,
                  y_v_space=0.06,
                  first=False,
                  c=['r', 'g', 'b'],
                  kwargs_histo=dict(histtype='barstacked',
                                    color=['r', 'g', 'b'],
                                    normed=False,
                                    range=range))
    ax1.set_xlabel(r'$\log\ H\alpha/H\beta$')
    x = tau_V_neb__z - ALL.tau_V__z
    xDs = [
        x[sel_WHa_DIG__z].compressed(), x[sel_WHa_COMP__z].compressed(),
        x[sel_WHa_HII__z].compressed()
    ]
    range = DtauV_range
    ax2.set_title('zones')
    print 'ax2'
    plot_histo_ax(ax2,
                  x.compressed(),
                  histo=False,
                  y_v_space=0.06,
                  ha='left',
                  pos_x=0.02,
                  c='k',
                  first=True)
    plot_histo_ax(ax2,
                  xDs,
                  y_v_space=0.06,
                  first=False,
                  c=['r', 'g', 'b'],
                  kwargs_histo=dict(histtype='barstacked',
                                    color=['r', 'g', 'b'],
                                    normed=False,
                                    range=range))
    ax2.set_xlabel(r'$\mathcal{D}_\tau\ =\ \tau_V^{neb}\ -\ \tau_V^\star$')
    x = np.ma.log10(ALL.SB6563__yx / ALL.SB4861__yx)
    xDs = [
        x[sel_WHa_DIG__yx].compressed(), x[sel_WHa_COMP__yx].compressed(),
        x[sel_WHa_HII__yx].compressed()
    ]
    range = logHaHb_range
    ax3.set_title('pixels')
    print 'ax3'
    plot_histo_ax(ax3,
                  x.compressed(),
                  histo=False,
                  y_v_space=0.06,
                  ha='left',
                  pos_x=0.02,
                  c='k',
                  first=True)
    plot_histo_ax(ax3,
                  xDs,
                  y_v_space=0.06,
                  first=False,
                  c=['r', 'g', 'b'],
                  kwargs_histo=dict(histtype='barstacked',
                                    color=['r', 'g', 'b'],
                                    normed=False,
                                    range=range))
    ax3.set_xlabel(r'$\log\ H\alpha/H\beta$')
    x = tau_V_neb__yx - ALL.tau_V__yx
    xDs = [
        x[sel_WHa_DIG__yx].compressed(), x[sel_WHa_COMP__yx].compressed(),
        x[sel_WHa_HII__yx].compressed()
    ]
    range = DtauV_range
    ax4.set_title('pixels')
    print 'ax4'
    plot_histo_ax(ax4,
                  x.compressed(),
                  histo=False,
                  y_v_space=0.06,
                  ha='left',
                  pos_x=0.02,
                  c='k',
                  first=True)
    plot_histo_ax(ax4,
                  xDs,
                  y_v_space=0.06,
                  first=False,
                  c=['r', 'g', 'b'],
                  kwargs_histo=dict(histtype='barstacked',
                                    color=['r', 'g', 'b'],
                                    normed=False,
                                    range=range))
    ax4.set_xlabel(r'$\mathcal{D}_\tau\ =\ \tau_V^{neb}\ -\ \tau_V^\star$')
    f.tight_layout()
    f.savefig('dig-sample-histo-logHaHb_Dt_colorsWHa.png')

    N_cols = 2
    N_rows = 2
    f, axArr = plt.subplots(N_rows, N_cols, dpi=100, figsize=(15, 10))
    ((ax1, ax2), (ax3, ax4)) = axArr
    x = np.ma.log10(ALL.f6563__z / ALL.f4861__z)
    range = logHaHb_range
    xDs = [
        x[sel_Zhang_DIG__z].compressed(), x[sel_Zhang_COMP__z].compressed(),
        x[sel_Zhang_HII__z].compressed()
    ]
    ax1.set_title('zones')
    plot_histo_ax(ax1,
                  x.compressed(),
                  histo=False,
                  y_v_space=0.06,
                  ha='left',
                  pos_x=0.02,
                  c='k',
                  first=True)
    plot_histo_ax(ax1,
                  xDs,
                  y_v_space=0.06,
                  first=False,
                  c=['r', 'g', 'b'],
                  kwargs_histo=dict(histtype='barstacked',
                                    color=['r', 'g', 'b'],
                                    normed=False,
                                    range=range))
    ax1.set_xlabel(r'$\log\ H\alpha/H\beta$')
    x = tau_V_neb__z - ALL.tau_V__z
    xDs = [
        x[sel_Zhang_DIG__z].compressed(), x[sel_Zhang_COMP__z].compressed(),
        x[sel_Zhang_HII__z].compressed()
    ]
    range = DtauV_range
    ax2.set_title('zones')
    plot_histo_ax(ax2,
                  x.compressed(),
                  histo=False,
                  y_v_space=0.06,
                  ha='left',
                  pos_x=0.02,
                  c='k',
                  first=True)
    plot_histo_ax(ax2,
                  xDs,
                  y_v_space=0.06,
                  first=False,
                  c=['r', 'g', 'b'],
                  kwargs_histo=dict(histtype='barstacked',
                                    color=['r', 'g', 'b'],
                                    normed=False,
                                    range=range))
    ax2.set_xlabel(r'$\mathcal{D}_\tau\ =\ \tau_V^{neb}\ -\ \tau_V^\star$')
    x = np.ma.log10(ALL.SB6563__yx / ALL.SB4861__yx)
    xDs = [
        x[sel_Zhang_DIG__yx].compressed(), x[sel_Zhang_COMP__yx].compressed(),
        x[sel_Zhang_HII__yx].compressed()
    ]
    range = logHaHb_range
    ax3.set_title('pixels')
    plot_histo_ax(ax3,
                  x.compressed(),
                  histo=False,
                  y_v_space=0.06,
                  ha='left',
                  pos_x=0.02,
                  c='k',
                  first=True)
    plot_histo_ax(ax3,
                  xDs,
                  y_v_space=0.06,
                  first=False,
                  c=['r', 'g', 'b'],
                  kwargs_histo=dict(histtype='barstacked',
                                    color=['r', 'g', 'b'],
                                    normed=False,
                                    range=range))
    ax3.set_xlabel(r'$\log\ H\alpha/H\beta$')
    x = tau_V_neb__yx - ALL.tau_V__yx
    xDs = [
        x[sel_Zhang_DIG__yx].compressed(), x[sel_Zhang_COMP__yx].compressed(),
        x[sel_Zhang_HII__yx].compressed()
    ]
    range = DtauV_range
    ax4.set_title('pixels')
    plot_histo_ax(ax4,
                  x.compressed(),
                  histo=False,
                  y_v_space=0.06,
                  ha='left',
                  pos_x=0.02,
                  c='k',
                  first=True)
    plot_histo_ax(ax4,
                  xDs,
                  y_v_space=0.06,
                  first=False,
                  c=['r', 'g', 'b'],
                  kwargs_histo=dict(histtype='barstacked',
                                    color=['r', 'g', 'b'],
                                    normed=False,
                                    range=range))
    ax4.set_xlabel(r'$\mathcal{D}_\tau\ =\ \tau_V^{neb}\ -\ \tau_V^\star$')
    f.tight_layout()
    f.savefig('dig-sample-histo-logHaHb_Dt_colorsZhang.png')
Ejemplo n.º 4
0
    x = np.ma.log10(SB6563__yx)
    im = ax_mapSBHa.imshow(x, **dflt_kw_imshow)
    the_divider = make_axes_locatable(ax_mapSBHa)
    color_axis = the_divider.append_axes('right', size='5%', pad=0)
    cb = plt.colorbar(im, cax=color_axis)
    cb.set_label(r'$\log\ \Sigma_{H\alpha}^{obs}$')
    DrawHLRCircle(ax_mapSBHa,
                  K,
                  color='k',
                  lw=1,
                  bins=[0.5, 1, 1.5, 2, 2.5, 3])
    ax_mapSBHa.set_title(r'SB $H\alpha$')
    plot_histo_ax(ax_histSBHa,
                  x.compressed(),
                  y_v_space=0.06,
                  c='k',
                  first=True,
                  kwargs_histo=dict(color='b', normed=False))

    range = [1, 2.5]
    x = logne__yx
    im = ax_mapS2S2.imshow(x, vmin=range[0], vmax=range[1], **dflt_kw_imshow)
    the_divider = make_axes_locatable(ax_mapS2S2)
    color_axis = the_divider.append_axes('right', size='5%', pad=0)
    cb = plt.colorbar(im, cax=color_axis)
    cb.set_label(r'$\log\ n_e\ [cm^{-3}]$')
    # cb.set_label(r'$6731/6717$')
    DrawHLRCircle(ax_mapS2S2,
                  K,
                  color='k',
                  lw=1,
Ejemplo n.º 5
0
    SNHa = Ha_obs__g / tbl_zones.cols.eF_obs_Ha[:]
    SNN2 = N2_obs__g / tbl_zones.cols.eF_obs_N2[:]

    f = plt.figure()
    NRows = 2
    NCols = 2
    page_size_inches = [NCols * 4, NRows * 4]
    f.set_size_inches(page_size_inches)
    f.set_dpi(100)
    grid_shape = (NRows, NCols)
    plot_order = [r'SN(H${}_{\beta}$)', r'SN(H${}_{\alpha}$)', r'SN(O[III])', r'SN(N[II])']
    plot_dict = {r'SN(H${}_{\beta}$)': SNHb, r'SN(H${}_{\alpha}$)': SNHa, r'SN(O[III])': SNO3, r'SN(N[II])': SNN2}
    row, col = 0, 0
    for k in plot_order:
        ax = plt.subplot2grid(grid_shape, loc=(row, col))
        SN = plot_dict[k]
        m = np.bitwise_or(np.isinf(SN), np.isnan(SN))
        m = np.bitwise_or(m, np.greater(SN, 1e4))
        SNm = np.ma.masked_array(SN, mask=m)
        x = SNm.compressed()
        ax.set_title(r'N = %d ($\geq$ 3: %d)' % (len(x), (x >= 3).astype('int').sum()))
        ax.set_xlabel(k)
        ax.set_ylabel(r'frac')
        kwh = {'bins': 20, 'range': [0, 20], 'normed': True}
        ax = plot_histo_ax(ax, x, first=True, fs=10, kwargs_histo=kwh)
        ax.axvline(x=3, ls='--', c='k')
        row, col = next_row_col(row, col, NRows, NCols)
    f.subplots_adjust(hspace=0.35, wspace=0.4, left=0.1, right=0.95, top=0.95)
    f.savefig('teste%s' % fpref)
    h5file.close()
Ejemplo n.º 6
0
def plot_bad_frac_histogram(gals, stdata__g):
    ALL_DIG_bad_ratio__lR = np.hstack(
        [d.bad_ratio__clR['DIG'] for d in stdata__g])
    ALL_COMP_bad_ratio__lR = np.hstack(
        [d.bad_ratio__clR['COMP'] for d in stdata__g])
    ALL_SF_bad_ratio__lR = np.hstack(
        [d.bad_ratio__clR['SF'] for d in stdata__g])
    wl = stdata__g[0].l_obs
    sel_Hb = ((wl > 4820) & (wl < 4900))
    sel_O3 = ((wl > 4967) & (wl < 5040))
    sel_N2Ha = ((wl > 6000) & (wl < 6700))
    sel = sel_Hb | sel_O3 | sel_N2Ha
    N_cols = 1
    N_rows = 3
    f, axArr = plt.subplots(N_rows, N_cols, figsize=(N_cols * 5, N_rows * 4.8))
    ax1, ax2, ax3 = axArr

    x = ALL_DIG_bad_ratio__lR[sel, :].flatten()
    range = [0, 0.5]
    plot_histo_ax(ax1,
                  x,
                  dataset_names='DIG',
                  y_v_space=0.06,
                  c='k',
                  first=True,
                  kwargs_histo=dict(histtype='bar',
                                    range=range,
                                    log=True,
                                    color=colors_DIG_COMP_SF[0],
                                    bins=100))
    plot_histo_ax(ax1,
                  x,
                  stats_txt=False,
                  dataset_names='DIG',
                  y_v_space=0.06,
                  c='k',
                  first=True,
                  kwargs_histo=dict(histtype='step',
                                    range=range,
                                    log=True,
                                    color='k',
                                    bins=100))
    ax1.xaxis.set_minor_locator(AutoMinorLocator(5))
    plt.setp(ax1.xaxis.get_majorticklabels(), visible=False)
    x = ALL_COMP_bad_ratio__lR[sel, :].flatten()
    plot_histo_ax(ax2,
                  x,
                  dataset_names='COMP',
                  y_v_space=0.06,
                  c='k',
                  first=True,
                  kwargs_histo=dict(histtype='bar',
                                    range=range,
                                    log=True,
                                    color=colors_DIG_COMP_SF[1],
                                    bins=100))
    plot_histo_ax(ax2,
                  x,
                  stats_txt=False,
                  dataset_names='DIG',
                  y_v_space=0.06,
                  c='k',
                  first=True,
                  kwargs_histo=dict(histtype='step',
                                    range=range,
                                    log=True,
                                    color='k',
                                    bins=100))
    ax2.xaxis.set_minor_locator(AutoMinorLocator(5))
    plt.setp(ax2.xaxis.get_majorticklabels(), visible=False)
    x = ALL_SF_bad_ratio__lR[sel, :].flatten()
    plot_histo_ax(ax3,
                  x,
                  dataset_names='SF',
                  y_v_space=0.06,
                  c='k',
                  first=True,
                  kwargs_histo=dict(histtype='bar',
                                    range=range,
                                    log=True,
                                    color=colors_DIG_COMP_SF[2],
                                    bins=100))
    plot_histo_ax(ax3,
                  x,
                  stats_txt=False,
                  dataset_names='DIG',
                  y_v_space=0.06,
                  c='k',
                  first=True,
                  kwargs_histo=dict(histtype='step',
                                    range=range,
                                    log=True,
                                    color='k',
                                    bins=100))
    ax3.xaxis.set_minor_locator(AutoMinorLocator(5))
    ax3.set_xlabel(r'$N_{BAD}/N_{TOTAL}$ (around BPT lines  )')
    # plot_text_ax(ax3, 'b)', 0.02, 0.98, 16, 'top', 'left', 'k')
    f.tight_layout(h_pad=0.0)
    ax1.grid()
    ax2.grid()
    ax3.grid()
    f.savefig('bad_frac_histogram.png',
              dpi=dpi_choice,
              transparent=transp_choice)
Ejemplo n.º 7
0
def plot_spectra(args, wl, O_bin, M_bin, err_bin, b_bin, rbin, K, sel_zones, class_key, N_zones, O_zones=None):
    from pytu.plots import plot_histo_ax
    import matplotlib.gridspec as gridspec
    from CALIFAUtils.plots import DrawHLRCircle
    from matplotlib.ticker import MultipleLocator
    from mpl_toolkits.axes_grid1 import make_axes_locatable
    califaID = K.califaID
    line_window_edges = 25
    N2Ha_window = np.bitwise_and(np.greater(wl, 6563-(2.*line_window_edges)), np.less(wl, 6563+(2.*line_window_edges)))
    Hb_window = np.bitwise_and(np.greater(wl, 4861-line_window_edges), np.less(wl, 4861+line_window_edges))
    O3_window = np.bitwise_and(np.greater(wl, 5007-line_window_edges), np.less(wl, 5007+line_window_edges))
    N_cols, N_rows = 5, 2
    f = plt.figure(figsize=(N_cols * 5, N_rows * 5))
    gs = gridspec.GridSpec(N_rows, N_cols)
    gs1 = gridspec.GridSpecFromSubplotSpec(2, 1, subplot_spec=gs[0, :], height_ratios=[4, 1], hspace=0.001, wspace=0.001)
    ax_spectra = plt.subplot(gs1[0])
    ax_b = plt.subplot(gs1[1])
    ax_map_v_0 = plt.subplot(gs[1, 0])
    ax_hist_v_0 = plt.subplot(gs[1, 1])
    ax_Hb = plt.subplot(gs[1, 2])
    ax_O3 = plt.subplot(gs[1, 3])
    ax_N2Ha = plt.subplot(gs[1, 4])
    Resid_bin = O_bin - M_bin
    ax_spectra.plot(wl, O_bin, '-k', lw=1)
    ax_spectra.plot(wl, M_bin, '-y', lw=1)
    ax_spectra.plot(wl, Resid_bin, '-r', lw=1)
    ax_b.bar(wl, b_bin, color='b')
    ax_Hb.plot(wl[Hb_window], O_bin[Hb_window], '-k', lw=1)
    ax_Hb.plot(wl[Hb_window], M_bin[Hb_window], '-y', lw=1)
    ax_Hb.plot(wl[Hb_window], Resid_bin[Hb_window], '-r', lw=1)
    ax_O3.plot(wl[O3_window], O_bin[O3_window], '-k', lw=1)
    ax_O3.plot(wl[O3_window], M_bin[O3_window], '-y', lw=1)
    ax_O3.plot(wl[O3_window], Resid_bin[O3_window], '-r', lw=1)
    ax_N2Ha.plot(wl[N2Ha_window], O_bin[N2Ha_window], '-k', lw=1)
    ax_N2Ha.plot(wl[N2Ha_window], M_bin[N2Ha_window], '-y', lw=1)
    ax_N2Ha.plot(wl[N2Ha_window], Resid_bin[N2Ha_window], '-r', lw=1)
    if O_zones is not None:
        ax_spectra.plot(wl, O_zones, '-c', alpha=0.3, lw=0.3)
        ax_Hb.plot(wl[Hb_window], O_zones[Hb_window, :], '-c', alpha=0.3, lw=0.3)
        ax_O3.plot(wl[O3_window], O_zones[O3_window, :], '-c', alpha=0.3, lw=0.3)
        ax_N2Ha.plot(wl[N2Ha_window], O_zones[N2Ha_window, :], '-c', alpha=0.3, lw=0.3)
    ax_spectra.xaxis.set_major_locator(MultipleLocator(250))
    ax_spectra.xaxis.set_minor_locator(MultipleLocator(50))
    ax_b.xaxis.set_major_locator(MultipleLocator(250))
    ax_b.xaxis.set_minor_locator(MultipleLocator(50))
    ax_b.yaxis.set_major_locator(MultipleLocator(100))
    ax_Hb.set_title(r'H$\beta$', y=1.1)
    ax_O3.set_title(r'[OIII]', y=1.1)
    ax_N2Ha.set_title(r'[NII] and H$\alpha$', y=1.1)
    ax_Hb.xaxis.set_major_locator(MultipleLocator(25))
    ax_Hb.xaxis.set_minor_locator(MultipleLocator(5))
    ax_O3.xaxis.set_major_locator(MultipleLocator(25))
    ax_O3.xaxis.set_minor_locator(MultipleLocator(5))
    ax_N2Ha.xaxis.set_major_locator(MultipleLocator(50))
    ax_N2Ha.xaxis.set_minor_locator(MultipleLocator(10))
    ax_spectra.get_xaxis().set_visible(False)
    ax_spectra.grid()
    ax_b.grid()
    ax_Hb.grid(which='both')
    ax_O3.grid(which='both')
    ax_N2Ha.grid(which='both')
    # v_0 map & histogram
    v_0_range = [K.v_0.min(), K.v_0.max()]
    plot_histo_ax(ax_hist_v_0, K.v_0[sel_zones], y_v_space=0.06, c='k', first=True, kwargs_histo=dict(normed=False, range=v_0_range))
    v_0__yx = K.zoneToYX(np.ma.masked_array(K.v_0, mask=~sel_zones), extensive=False)
    im = ax_map_v_0.imshow(v_0__yx, vmin=v_0_range[0], vmax=v_0_range[1], cmap='RdBu', **dflt_kw_imshow)
    the_divider = make_axes_locatable(ax_map_v_0)
    color_axis = the_divider.append_axes('right', size='5%', pad=0)
    cb = plt.colorbar(im, cax=color_axis)
    cb.set_label(r'v${}_0$ [km/s]')
    DrawHLRCircle(ax_map_v_0, a=K.HLR_pix, pa=K.pa, ba=K.ba, x0=K.x0, y0=K.y0, color='k', lw=1, bins=[0.5, 1, 1.5, 2, 2.5, 3])
    ax_map_v_0.set_title(r'v${}_0$ map')
    f.tight_layout(rect=[0, 0.03, 1, 0.95])
    f.suptitle(r'%s - %s - R bin center: %.2f ($\pm$ %.2f) HLR - %d zones' % (califaID, class_key, rbin, args.rbinstep/2., N_zones))
    f.savefig('%s_%s_spectra_%.2fHLR.png' % (califaID, class_key, rbin), dpi=dpi_choice, transparent=transp_choice)
    plt.close(f)