示例#1
0
def get_stellar_data(plt, ifu, hdu):
    uniq_bins, uniq_indx, uniq_cnt = map(
        lambda x: x[1:],
        numpy.unique(hdu['BINID'].data[1].ravel(),
                     return_index=True,
                     return_counts=True))
    keep = numpy.logical_not(hdu['BIN_MFLUX_MASK'].data.ravel()[uniq_indx] > 0) \
            | numpy.logical_not(hdu['STELLAR_VEL_MASK'].data.ravel()[uniq_indx] > 0) \
            | numpy.logical_not(hdu['STELLAR_SIGMA_MASK'].data.ravel()[uniq_indx] > 0)
    uniq_bins = uniq_bins[keep]
    uniq_indx = uniq_indx[keep]
    uniq_cnt = uniq_cnt[keep]
    data = StellarDataTable(shape=uniq_bins.shape)

    data['PLATE'] = plt
    data['IFU'] = ifu
    data['Y'], data['X'] = numpy.unravel_index(uniq_indx,
                                               hdu['BINID'].shape[1:])
    data['BINID'] = uniq_bins
    data['NBIN'] = uniq_cnt
    data['R'] = hdu['BIN_LWELLCOO'].data[0].ravel()[uniq_indx]
    data['R_RE'] = hdu['BIN_LWELLCOO'].data[1].ravel()[uniq_indx]
    data['R_KPC'] = hdu['BIN_LWELLCOO'].data[2].ravel()[uniq_indx]
    data['GCNT'] = hdu['BIN_MFLUX'].data.ravel()[uniq_indx]
    data['GSNR'] = hdu['BIN_SNR'].data.ravel()[uniq_indx]
    data['RCHI2'] = hdu['STELLAR_FOM'].data[2].ravel()[uniq_indx]
    data['VEL'] = hdu['STELLAR_VEL'].data.ravel()[uniq_indx]
    data['VEL_ERR'] = numpy.ma.power(
        hdu['STELLAR_VEL_IVAR'].data.ravel()[uniq_indx], -0.5).filled(-1)
    data['SIG'] = hdu['STELLAR_SIGMA'].data.ravel()[uniq_indx]
    data['SIG_ERR'] = numpy.ma.power(
        hdu['STELLAR_SIGMA_IVAR'].data.ravel()[uniq_indx], -0.5).filled(-1)
    data['SIG_CORR'] = hdu['STELLAR_SIGMACORR'].data.ravel()[uniq_indx]

    # Deal with the masking
    # maps_bm = DAPMapsBitMask()
    qual_bm = DAPQualityBitMask()
    data_bm = StellarBitMask()
    if qual_bm.flagged(hdu[0].header['DAPQUAL'], flag='CRITICAL'):
        data['MASK'] = data_bm.turn_on(data['MASK'], 'CRITCUBE')
    indx = hdu['BIN_MFLUX_MASK'].data.ravel()[uniq_indx] > 0
    if numpy.any(indx):
        data['MASK'][indx] = data_bm.turn_on(data['MASK'][indx], 'BADFLUX')
    indx = (hdu['STELLAR_VEL_MASK'].data.ravel()[uniq_indx] > 0) \
            | numpy.logical_not(hdu['STELLAR_VEL_IVAR'].data.ravel()[uniq_indx] > 0)
    if numpy.any(indx):
        data['MASK'][indx] = data_bm.turn_on(data['MASK'][indx], 'BADVEL')
    indx = (hdu['STELLAR_SIGMA_MASK'].data.ravel()[uniq_indx] > 0) \
            | numpy.logical_not(hdu['STELLAR_SIGMA_IVAR'].data.ravel()[uniq_indx] > 0)
    if numpy.any(indx):
        data['MASK'][indx] = data_bm.turn_on(data['MASK'][indx], 'BADSIG')

    return data
示例#2
0
def is_critical(dapver, analysis_path, daptype, plt):

    ifus = [
        1901, 1902, 3701, 3702, 3703, 3704, 6101, 6102, 6103, 6104, 9101, 9102,
        12701, 12702, 12703, 12704, 12705
    ]

    dapqualbm = DAPQualityBitMask()

    critical = numpy.zeros(len(ifus), dtype=bool)

    for i, ifu in enumerate(ifus):
        apath = os.path.join(analysis_path, daptype, str(plt), str(ifu))
        maps_file = os.path.join(
            apath, 'manga-{0}-{1}-MAPS-{2}.fits.gz'.format(plt, ifu, daptype))

        if not os.path.isfile(maps_file):
            continue

        hdu = fits.open(maps_file)
        critical[i] = dapqualbm.flagged(hdu[0].header['dapqual'], 'CRITICAL')

    return ifus, critical
示例#3
0
def ppxf_flag_info(tbl, maps_file):
    qual_bm = DAPQualityBitMask()
    bm = DAPMapsBitMask()
   
#    # Targeting bits
#    sdssMaskbits = defaults.sdss_maskbits_file()
#    mngtarg1_bm = BitMask.from_par_file(sdssMaskbits, 'MANGA_TARGET1')
#    mngtarg3_bm = BitMask.from_par_file(sdssMaskbits, 'MANGA_TARGET3')

    tbl['PLT'], tbl['IFU'] = map(lambda x : int(x), os.path.split(maps_file)[1].split('-')[1:3])

    with fits.open(maps_file) as hdu:

        # Check if the file was CRITICAL
        tbl['CRIT'] = qual_bm.flagged(hdu['PRIMARY'].header['DAPQUAL'], flag='DRPCRIT')
        tbl['MAIN'] = hdu[0].header['MNGTARG1'] > 0

        el = channel_dictionary(hdu, 'EMLINE_GFLUX')

        haflx = numpy.ma.MaskedArray(hdu['EMLINE_GFLUX'].data[el['Ha-6564']],
                                     mask=hdu['EMLINE_GFLUX_MASK'].data[el['Ha-6564']] > 0)
        tbl['HAMEAN'] = numpy.ma.median(haflx)
        tbl['NSPX'] = haflx.size
        tbl['NGOOD'] = numpy.sum(numpy.logical_not(numpy.ma.getmaskarray(haflx)))
        indx = bm.flagged(hdu['EMLINE_GFLUX_MASK'].data[el['Ha-6564']], 'FITFAILED')
        tbl['NFLG'] = numpy.sum(indx)

        if not numpy.any(indx):
            return

        snr = numpy.ma.MaskedArray(hdu['SPX_SNR'].data,
                                   mask=numpy.logical_not(hdu['SPX_SNR'].data > 0))
        tbl['FLGSNR'] = numpy.ma.median(snr[indx])
        srt = numpy.argsort(snr[indx])
        tbl['EXSNR'] = snr[indx][srt][-1]
        tbl['EXBIN'] = hdu['BINID'].data[3][indx][srt][-1]
示例#4
0
def redshift_distribution(dapall, daptype, ofile=None):

    indx = (dapall['DAPDONE'] == 1) & (dapall['DAPTYPE'] == daptype)
    ns_indx = indx & (dapall['NSA_Z'] > -999) & (dapall['STELLAR_Z'] > -999)
    gs_indx = indx & (dapall['HA_Z'] > -999) & (dapall['STELLAR_Z'] > -999)

    is_critical = DAPQualityBitMask().flagged(dapall['DAPQUAL'], 'CRITICAL')

    ns_bd = ns_indx & is_critical
    gs_bd = gs_indx & is_critical

    ns_gd = ns_indx & numpy.invert(is_critical)
    gs_gd = gs_indx & numpy.invert(is_critical)

    font = {'size': 14}
    rc('font', **font)

    w, h = pyplot.figaspect(1)
    fig = pyplot.figure(figsize=(1.5 * w, 1.5 * h))

    offset_lim = [-90, 90]
    ax = init_ax(fig, [0.17, 0.10, 0.56, 0.3])
    ax.set_xlim([-0.01, 0.16])
    ax.set_ylim(offset_lim)
    ax.grid(True, which='major', color='0.8', zorder=0, linestyle='-')

    dcz = astropy.constants.c.to('km/s').value * (dapall['STELLAR_Z'] -
                                                  dapall['NSA_Z'])

    ax.scatter(dapall['NSA_Z'][ns_gd],
               dcz[ns_gd],
               marker='.',
               s=20,
               lw=0,
               color='k',
               zorder=3)
    ax.scatter(dapall['NSA_Z'][ns_bd],
               dcz[ns_bd],
               marker='.',
               s=20,
               lw=0,
               color='C3',
               zorder=3)
    ax.text(0.5,
            -0.2,
            r'$z_{\rm NSA}$',
            horizontalalignment='center',
            verticalalignment='center',
            transform=ax.transAxes)
    ax.text(-0.18,
            0.5,
            r'$c (z_\ast - z_{\rm NSA})$ [km/s]',
            horizontalalignment='center',
            verticalalignment='center',
            transform=ax.transAxes,
            rotation='vertical')

    ax = init_ax(fig, [0.73, 0.10, 0.1, 0.3])
    ax.set_ylim(offset_lim)
    ax.tick_params(which='both', direction='in', bottom=False)
    ax.yaxis.set_major_formatter(ticker.NullFormatter())
    ax.xaxis.set_major_formatter(ticker.NullFormatter())
    ax.grid(True,
            which='major',
            axis='y',
            color='0.8',
            zorder=0,
            linestyle='-')
    ax.hist(dcz[ns_gd],
            range=offset_lim,
            bins=100,
            alpha=0.7,
            color='0.4',
            histtype='stepfilled',
            orientation='horizontal',
            zorder=3)
    ax.hist(dcz[ns_gd],
            range=offset_lim,
            bins=100,
            alpha=0.7,
            color='k',
            histtype='step',
            lw=0.5,
            orientation='horizontal',
            zorder=4)

    ax = init_ax(fig, [0.22, 0.50, 0.56, 0.3])
    ax.set_xlim(offset_lim)
    ax.tick_params(which='both', left=False)
    ax.yaxis.set_major_formatter(ticker.NullFormatter())
    ax.grid(True,
            which='major',
            axis='x',
            color='0.8',
            zorder=0,
            linestyle='-')

    dcz = astropy.constants.c.to('km/s').value * (dapall['STELLAR_Z'] -
                                                  dapall['HA_Z'])

    ax.hist(dcz[gs_gd],
            range=offset_lim,
            bins=100,
            alpha=0.7,
            color='0.4',
            histtype='stepfilled',
            zorder=3)
    ax.hist(dcz[gs_gd],
            range=offset_lim,
            bins=100,
            alpha=0.7,
            color='k',
            histtype='step',
            lw=0.5,
            zorder=4)
    ax.text(0.5,
            -0.2,
            r'$c (z_\ast - z_{\rm gas})$ [km/s]',
            horizontalalignment='center',
            verticalalignment='center',
            transform=ax.transAxes)

    if ofile is None:
        pyplot.show()
    else:
        print('Writing: {0}'.format(ofile))
        fig.canvas.print_figure(ofile, bbox_inches='tight')
    fig.clear()
    pyplot.close(fig)
示例#5
0
def ew_d4000(drpall, dapall, daptype, eml, spi, ofile=None):

    indx = (dapall['DAPDONE'] == 1) & (dapall['DAPTYPE'] == daptype)
    indx &= (drpall['nsa_sersic_mass'][dapall['DRPALLINDX']] > 0)

    ha_indx = indx & (dapall['EMLINE_GEW_1RE'][:,eml['Ha-6564']] > -999) \
                    & (dapall['SPECINDEX_1RE'][:,spi['Dn4000']] > -999)
    hd_indx = indx & (dapall['SPECINDEX_1RE'][:,spi['HDeltaA']] > -999) \
                    & (dapall['SPECINDEX_1RE'][:,spi['Dn4000']] > -999)

    is_critical = DAPQualityBitMask().flagged(dapall['DAPQUAL'], 'CRITICAL')

    ha_bd = ha_indx & is_critical
    hd_bd = hd_indx & is_critical

    ha_gd = ha_indx & numpy.invert(is_critical)
    hd_gd = hd_indx & numpy.invert(is_critical)

    mass_lim = [1e9, 7e11]
    d4_lim = [0.9, 2.3]
    ha_lim = [2e-2, 400]
    hd_lim = [-4, 9]

    font = {'size': 12}
    rc('font', **font)

    w, h = pyplot.figaspect(1)
    fig = pyplot.figure(figsize=(1.5 * w, 1.5 * h))

    ax = init_ax(fig, [0.3, 0.56, 0.4, 0.4])
    ax.set_xlim(d4_lim)
    ax.set_ylim(ha_lim)
    ax.tick_params(axis='x', which='both', direction='in')
    ax.set_yscale('log')
    ax.xaxis.set_major_formatter(ticker.NullFormatter())

    sc = ax.scatter(dapall['SPECINDEX_1RE'][ha_gd, spi['Dn4000']],
                    dapall['EMLINE_GEW_1RE'][ha_gd, eml['Ha-6564']],
                    lw=0,
                    marker='.',
                    s=20,
                    zorder=3,
                    c=drpall['nsa_sersic_mass'][dapall['DRPALLINDX'][ha_gd]],
                    norm=colors.LogNorm(vmin=mass_lim[0], vmax=mass_lim[1]),
                    cmap='viridis')

    ax.scatter(dapall['SPECINDEX_1RE'][ha_bd, spi['Dn4000']],
               dapall['EMLINE_GEW_1RE'][ha_bd, eml['Ha-6564']],
               lw=0,
               marker='x',
               s=10,
               zorder=2,
               c=drpall['nsa_sersic_mass'][dapall['DRPALLINDX'][ha_bd]],
               norm=colors.LogNorm(vmin=mass_lim[0], vmax=mass_lim[1]),
               cmap='viridis')

    ax.text(
        -0.25,
        0.5,
        r'$\langle {\rm EW}_{{\rm H}\alpha}\rangle_e$ [$\AA$, in emission]',
        horizontalalignment='center',
        verticalalignment='center',
        transform=ax.transAxes,
        rotation='vertical')

    ax = init_ax(fig, [0.3, 0.15, 0.4, 0.4])
    ax.set_xlim(d4_lim)
    ax.set_ylim(hd_lim)

    sc = ax.scatter(dapall['SPECINDEX_1RE'][hd_gd, spi['Dn4000']],
                    dapall['SPECINDEX_1RE'][hd_gd, spi['HDeltaA']],
                    lw=0,
                    marker='.',
                    s=20,
                    zorder=3,
                    c=drpall['nsa_sersic_mass'][dapall['DRPALLINDX'][hd_gd]],
                    norm=colors.LogNorm(vmin=mass_lim[0], vmax=mass_lim[1]),
                    cmap='viridis')

    ax.scatter(dapall['SPECINDEX_1RE'][hd_bd, spi['Dn4000']],
               dapall['SPECINDEX_1RE'][hd_bd, spi['HDeltaA']],
               lw=0,
               marker='x',
               s=10,
               zorder=2,
               c=drpall['nsa_sersic_mass'][dapall['DRPALLINDX'][hd_bd]],
               norm=colors.LogNorm(vmin=mass_lim[0], vmax=mass_lim[1]),
               cmap='viridis')

    cax = fig.add_axes([0.51, 0.48, 0.15, 0.01])
    cb = pyplot.colorbar(sc,
                         cax=cax,
                         orientation='horizontal',
                         ticks=[1e9, 1e10, 1e11])
    #, ticks=[0.1,1], format=ticker.ScalarFormatter())
    cax.text(0.5,
             2.8,
             r'$\mathcal{M}_\ast$ [$h^{-2} \mathcal{M}_\odot$]',
             ha='center',
             va='center',
             transform=cax.transAxes)  #, fontsize=10)

    ax.text(-0.25,
            0.5,
            r'$\langle {\rm H}\delta_{\rm A}\rangle_e$ [$\AA$, in absorption]',
            horizontalalignment='center',
            verticalalignment='center',
            transform=ax.transAxes,
            rotation='vertical')

    ax.text(0.5,
            -0.18,
            r'$\langle {\rm Dn4000}\rangle_e$',
            horizontalalignment='center',
            verticalalignment='center',
            transform=ax.transAxes)

    if ofile is None:
        pyplot.show()
    else:
        print('Writing: {0}'.format(ofile))
        fig.canvas.print_figure(ofile, bbox_inches='tight', dpi=100)
    fig.clear()
    pyplot.close(fig)
示例#6
0
def radial_coverage_histogram(dapall, daptype, ofile=None):

    # Must have finished, be of the correct daptype, and *not* be
    # critical
    indx = (dapall['DAPDONE'] == 1) & (dapall['DAPTYPE'] == daptype) \
                & numpy.invert(DAPQualityBitMask().flagged(dapall['DAPQUAL'], 'CRITICAL'))

    # Get the range
    arcsec_rng = growth_lim(dapall['RCOV90'][indx], 0.99, fac=1.1)
    rore = numpy.ma.divide(dapall['RCOV90'][indx],
                           dapall['NSA_ELPETRO_TH50_R'][indx])
    rore[dapall['NSA_ELPETRO_TH50_R'][indx] < 0] = numpy.ma.masked
    rore_rng = growth_lim(rore, 0.99, fac=1.1)

    # Determine the sample
    sdssMaskbits = defaults.sdss_maskbits_file()
    targ1bm = BitMask.from_par_file(sdssMaskbits, 'MANGA_TARGET1')

    ancillary = dapall['MNGTARG3'][indx] > 0
    primaryplus = targ1bm.flagged(
        dapall['MNGTARG1'][indx],
        flag=['PRIMARY_v1_2_0', 'COLOR_ENHANCED_v1_2_0'])
    secondary = targ1bm.flagged(dapall['MNGTARG1'][indx],
                                flag='SECONDARY_v1_2_0')
    other = numpy.invert(ancillary) & numpy.invert(primaryplus) & numpy.invert(
        secondary)

    print('Num. of observations with 90% coverage <1 arcsec: {0}'.format(
        numpy.sum(dapall['RCOV90'][indx] < 1)))

    font = {'size': 10}
    rc('font', **font)

    # Instantiate the figure
    w, h = pyplot.figaspect(1)
    fig = pyplot.figure(figsize=(1.5 * w, 1.5 * h))

    nlim = [0.8, 1000]

    # Show RCOV90 in terms of arcseconds for each IFU
    ax = init_ax(fig, [0.1, 0.58, 0.8, 0.4])
    ax.set_ylim(nlim)
    ax.set_yscale('log', nonpositive='clip')
    ifu = [19, 37, 61, 91, 127]
    for i, f in enumerate(ifu):
        _indx = indx & ((dapall['IFUDESIGN'] / 100).astype(int) == f)
        if not numpy.any(_indx):
            continue
        ax.hist(dapall['RCOV90'][_indx],
                bins=50,
                range=arcsec_rng,
                alpha=0.5,
                histtype='stepfilled',
                color='C{0}'.format(i),
                zorder=2)
        ax.hist(dapall['RCOV90'][_indx],
                bins=50,
                range=arcsec_rng,
                histtype='step',
                color='C{0}'.format(i),
                zorder=3)
        medp = numpy.median(dapall['RCOV90'][_indx])
        ax.plot([medp, medp],
                nlim,
                color='C{0}'.format(i),
                zorder=4,
                linestyle='--')
    ax.text(-0.1,
            0.5,
            'N',
            ha='center',
            va='center',
            transform=ax.transAxes,
            rotation='vertical')
    ax.text(0.5,
            -0.13,
            r'$R_{90}$ (arcsec)',
            ha='center',
            va='center',
            transform=ax.transAxes)
    ax.text(0.05,
            0.95,
            '19-fiber',
            color='C0',
            ha='left',
            va='center',
            transform=ax.transAxes)
    ax.text(0.05,
            0.90,
            '37-fiber',
            color='C1',
            ha='left',
            va='center',
            transform=ax.transAxes)
    ax.text(0.05,
            0.85,
            '61-fiber',
            color='C2',
            ha='left',
            va='center',
            transform=ax.transAxes)
    ax.text(0.05,
            0.80,
            '91-fiber',
            color='C3',
            ha='left',
            va='center',
            transform=ax.transAxes)
    ax.text(0.05,
            0.75,
            '127-fiber',
            color='C4',
            ha='left',
            va='center',
            transform=ax.transAxes)

    # Show RCOV90 in terms of Re for each sample
    ax = init_ax(fig, [0.1, 0.08, 0.8, 0.4])
    ax.set_ylim(nlim)
    ax.set_yscale('log', nonpositive='clip')

    if numpy.any(primaryplus):
        _rore = (rore[primaryplus]).compressed()
        ax.hist(_rore,
                bins=50,
                range=rore_rng,
                alpha=0.5,
                histtype='stepfilled',
                color='C0',
                zorder=2)
        ax.hist(_rore,
                bins=50,
                range=rore_rng,
                histtype='step',
                color='C0',
                zorder=3)
        medp = numpy.median(_rore)
        ax.plot([medp, medp], nlim, color='C0', zorder=4, linestyle='--')

    if numpy.any(secondary):
        _rore = (rore[secondary]).compressed()
        ax.hist(_rore,
                bins=50,
                range=rore_rng,
                alpha=0.5,
                histtype='stepfilled',
                color='C1',
                zorder=2)
        ax.hist(_rore,
                bins=50,
                range=rore_rng,
                histtype='step',
                color='C1',
                zorder=3)
        medp = numpy.median(_rore)
        ax.plot([medp, medp], nlim, color='C1', zorder=4, linestyle='--')

    if numpy.any(other):
        _rore = (rore[other]).compressed()
        ax.hist(_rore,
                bins=50,
                range=rore_rng,
                alpha=0.5,
                histtype='stepfilled',
                color='C2',
                zorder=2)
        ax.hist(_rore,
                bins=50,
                range=rore_rng,
                histtype='step',
                color='C2',
                zorder=3)

    if numpy.any(ancillary):
        _rore = (rore[ancillary]).compressed()
        ax.hist(_rore,
                bins=50,
                range=rore_rng,
                alpha=0.5,
                histtype='stepfilled',
                color='C3',
                zorder=2)
        ax.hist(_rore,
                bins=50,
                range=rore_rng,
                histtype='step',
                color='C3',
                zorder=3)

    ax.text(-0.1,
            0.5,
            'N',
            ha='center',
            va='center',
            transform=ax.transAxes,
            rotation='vertical')
    ax.text(0.5,
            -0.12,
            r'$R_{90}/R_{eff}$',
            ha='center',
            va='center',
            transform=ax.transAxes)
    ax.text(0.05,
            0.95,
            'Primary+',
            color='C0',
            ha='left',
            va='center',
            transform=ax.transAxes)
    ax.text(0.05,
            0.90,
            'Secondary',
            color='C1',
            ha='left',
            va='center',
            transform=ax.transAxes)
    ax.text(0.05,
            0.85,
            'Other',
            color='C2',
            ha='left',
            va='center',
            transform=ax.transAxes)
    ax.text(0.05,
            0.80,
            'Ancillary',
            color='C3',
            ha='left',
            va='center',
            transform=ax.transAxes)

    if ofile is None:
        pyplot.show()
    else:
        print('Writing: {0}'.format(ofile))
        fig.canvas.print_figure(ofile, bbox_inches='tight')
    fig.clear()
    pyplot.close(fig)
示例#7
0
def mgfe_hbeta(drpall, dapall, daptype, spi, ofile=None):
    indx = (dapall['DAPDONE'] == 1) & (dapall['DAPTYPE'] == daptype)
    indx &= (drpall['nsa_sersic_mass'][dapall['DRPALLINDX']] > 0)

    indx &= (dapall['SPECINDEX_1RE'][:, spi['Mgb']] > -999)
    indx &= (dapall['SPECINDEX_1RE'][:, spi['Fe5270']] > -999)
    indx &= (dapall['SPECINDEX_1RE'][:, spi['Fe5335']] > -999)
    indx &= (dapall['SPECINDEX_1RE'][:, spi['Hb']] > -999)

    is_critical = DAPQualityBitMask().flagged(dapall['DAPQUAL'], 'CRITICAL')
    bd = indx & is_critical
    gd = indx & numpy.invert(is_critical)

    mgfe = numpy.ma.sqrt(dapall['SPECINDEX_1RE'][:, spi['Mgb']] *
                         (0.72 * dapall['SPECINDEX_1RE'][:, spi['Fe5270']] +
                          0.28 * dapall['SPECINDEX_1RE'][:, spi['Fe5335']]))

    mass_lim = [1e9, 7e11]
    mgfe_lim = [0, 4.5]
    hb_lim = [0.5, 5.9]

    font = {'size': 16}
    rc('font', **font)

    w, h = pyplot.figaspect(1)
    fig = pyplot.figure(figsize=(1.5 * w, 1.5 * h))

    ax = init_ax(fig, [0.2, 0.2, 0.6, 0.6])
    ax.set_xlim(mgfe_lim)
    ax.set_ylim(hb_lim)
    ax.tick_params(axis='x', which='both', direction='in')

    sc = ax.scatter(mgfe[gd],
                    dapall['SPECINDEX_1RE'][gd, spi['Hb']],
                    marker='.',
                    s=30,
                    lw=0,
                    zorder=2,
                    c=drpall['nsa_sersic_mass'][dapall['DRPALLINDX'][gd]],
                    norm=colors.LogNorm(vmin=mass_lim[0], vmax=mass_lim[1]),
                    cmap='viridis')
    ax.scatter(mgfe[bd],
               dapall['SPECINDEX_1RE'][bd, spi['Hb']],
               marker='x',
               s=15,
               lw=0,
               zorder=2,
               c=drpall['nsa_sersic_mass'][dapall['DRPALLINDX'][bd]],
               norm=colors.LogNorm(vmin=mass_lim[0], vmax=mass_lim[1]),
               cmap='viridis')

    ax.text(-0.15,
            0.5,
            r'$\langle {\rm H}\beta\rangle_e$ [$\AA$, in absorption]',
            horizontalalignment='center',
            verticalalignment='center',
            transform=ax.transAxes,
            rotation='vertical')

    ax.text(
        0.5,
        -0.12,
        r'[$\langle$Mgb$\rangle_e\cdot$(0.72 $\langle$Fe5270$\rangle_e$ + 0.28 $\langle$Fe5335$\rangle_e$)]$^{1/2}$',
        horizontalalignment='center',
        verticalalignment='center',
        transform=ax.transAxes)
    ax.text(0.5,
            -0.19,
            r'[$\AA$, in absorption]',
            horizontalalignment='center',
            verticalalignment='center',
            transform=ax.transAxes)

    cax = fig.add_axes([0.58, 0.71, 0.20, 0.01])
    cb = pyplot.colorbar(sc,
                         cax=cax,
                         orientation='horizontal',
                         ticks=[1e9, 1e10, 1e11])
    cax.text(0.5,
             3.0,
             r'$\mathcal{M}_\ast$ [$h^{-2} \mathcal{M}_\odot$]',
             ha='center',
             va='center',
             transform=cax.transAxes)  #, fontsize=10)

    if ofile is None:
        pyplot.show()
    else:
        print('Writing: {0}'.format(ofile))
        fig.canvas.print_figure(ofile, bbox_inches='tight', dpi=100)
    fig.clear()
    pyplot.close(fig)
示例#8
0
def velocity_gradient(drpall, dapall, daptype, eml, ofile=None):

    indx = (dapall['DAPDONE'] == 1) & (dapall['DAPTYPE'] == daptype)
    indx &= (drpall['nsa_elpetro_ba'][dapall['DRPALLINDX']] > 0)

    ha_indx = indx & (dapall['HA_GVEL_LO_CLIP'] >
                      -999) & (dapall['HA_GVEL_HI_CLIP'] > -999)

    ha_vdiff = dapall['HA_GVEL_HI_CLIP'] - dapall['HA_GVEL_LO_CLIP']
    ha_sini = numpy.ma.sqrt(
        1 - numpy.square(drpall['nsa_elpetro_ba'][dapall['DRPALLINDX']]))

    st_indx = indx & (dapall['STELLAR_VEL_LO_CLIP'] >
                      -999) & (dapall['STELLAR_VEL_HI_CLIP'] > -999)

    st_vdiff = dapall['STELLAR_VEL_HI_CLIP'] - dapall['STELLAR_VEL_LO_CLIP']
    st_sini = numpy.ma.sqrt(
        1 - numpy.square(drpall['nsa_elpetro_ba'][dapall['DRPALLINDX']]))

    is_critical = DAPQualityBitMask().flagged(dapall['DAPQUAL'], 'CRITICAL')

    ha_bd = ha_indx & is_critical
    st_bd = st_indx & is_critical

    ha_gd = ha_indx & numpy.invert(is_critical)
    st_gd = st_indx & numpy.invert(is_critical)

    mass_lim = [2e8, 5e11]
    velw_lim = [30, 4000]

    ha_sb_lim = [0.02, 8]
    st_sb_lim = [0.03, 1]

    font = {'size': 14}
    rc('font', **font)

    w, h = pyplot.figaspect(1)
    fig = pyplot.figure(figsize=(1.5 * w, 1.5 * h))

    ax = init_ax(fig, [0.3, 0.56, 0.4, 0.4])
    ax.set_xlim(mass_lim)
    ax.set_ylim(velw_lim)
    ax.tick_params(axis='x', which='both', direction='in')
    ax.set_xscale('log')
    ax.set_yscale('log')
    ax.xaxis.set_major_formatter(ticker.NullFormatter())

    x = numpy.linspace(6, 14, 100)
    y = x / 4
    ax.plot(numpy.power(10, x),
            numpy.power(10, y - 0.75),
            color='0.8',
            zorder=0)
    ax.plot(numpy.power(10, x), numpy.power(10, y), color='0.8', zorder=0)
    ax.plot(numpy.power(10, x),
            numpy.power(10, y + 0.75),
            color='0.8',
            zorder=0)

    sc = ax.scatter(drpall['nsa_sersic_mass'][dapall['DRPALLINDX'][ha_gd]],
                    numpy.ma.divide(ha_vdiff[ha_gd], ha_sini[ha_gd]),
                    c=dapall['EMLINE_GSB_1RE'][ha_gd, eml['Ha-6564']],
                    lw=0,
                    marker='.',
                    s=20,
                    zorder=2,
                    norm=colors.LogNorm(vmin=ha_sb_lim[0], vmax=ha_sb_lim[1]),
                    cmap='inferno_r')
    ax.scatter(drpall['nsa_sersic_mass'][dapall['DRPALLINDX'][ha_bd]],
               numpy.ma.divide(ha_vdiff[ha_bd], ha_sini[ha_bd]),
               c=dapall['EMLINE_GSB_1RE'][ha_bd, eml['Ha-6564']],
               lw=0,
               marker='x',
               s=10,
               zorder=2,
               norm=colors.LogNorm(vmin=ha_sb_lim[0], vmax=ha_sb_lim[1]),
               cmap='inferno_r')

    cax = fig.add_axes([0.54, 0.60, 0.15, 0.01])
    cb = pyplot.colorbar(sc,
                         cax=cax,
                         orientation='horizontal',
                         ticks=[0.1, 1],
                         format=ticker.ScalarFormatter())
    pyplot.setp(cb.ax.xaxis.get_ticklabels(), fontsize=10)
    cax.text(0.8,
             2.5,
             r'$\langle I_{{\rm H}\alpha}\rangle_e$',
             ha='center',
             va='center',
             transform=cax.transAxes,
             fontsize=10)

    ax.text(-0.22,
            0.5,
            r'$\Delta V_{\rm gas}$ [km/s]',
            horizontalalignment='center',
            verticalalignment='center',
            transform=ax.transAxes,
            rotation='vertical')

    ax = init_ax(fig, [0.3, 0.15, 0.4, 0.4])
    ax.set_xlim(mass_lim)
    ax.set_ylim(velw_lim)
    ax.set_xscale('log')
    ax.set_yscale('log')

    x = numpy.linspace(6, 14, 100)
    y = x / 4
    ax.plot(numpy.power(10, x),
            numpy.power(10, y - 0.75),
            color='0.8',
            zorder=0)
    ax.plot(numpy.power(10, x), numpy.power(10, y), color='0.8', zorder=0)
    ax.plot(numpy.power(10, x),
            numpy.power(10, y + 0.75),
            color='0.8',
            zorder=0)

    sc = ax.scatter(drpall['nsa_sersic_mass'][dapall['DRPALLINDX'][st_gd]],
                    numpy.ma.divide(st_vdiff[st_gd], st_sini[st_gd]),
                    c=dapall['SB_1RE'][st_gd],
                    lw=0,
                    marker='.',
                    s=20,
                    zorder=2,
                    norm=colors.LogNorm(vmin=st_sb_lim[0], vmax=st_sb_lim[1]),
                    cmap='inferno_r')
    ax.scatter(drpall['nsa_sersic_mass'][dapall['DRPALLINDX'][st_bd]],
               numpy.ma.divide(st_vdiff[st_bd], st_sini[st_bd]),
               c=dapall['SB_1RE'][st_bd],
               lw=0,
               marker='x',
               s=10,
               zorder=2,
               norm=colors.LogNorm(vmin=st_sb_lim[0], vmax=st_sb_lim[1]),
               cmap='inferno_r')

    cax = fig.add_axes([0.31, 0.50, 0.11, 0.01])
    cb = pyplot.colorbar(sc,
                         cax=cax,
                         orientation='horizontal',
                         ticks=[0.1, 1],
                         format=ticker.ScalarFormatter())
    pyplot.setp(cb.ax.xaxis.get_ticklabels(), fontsize=10)
    cax.text(0.5,
             2.5,
             r'$\langle I_g\rangle_e$',
             ha='center',
             va='center',
             transform=cax.transAxes,
             fontsize=10)

    ax.text(0.5,
            -0.18,
            r'$\mathcal{M}_\ast$ [$h^{-2} \mathcal{M}_\odot$]',
            horizontalalignment='center',
            verticalalignment='center',
            transform=ax.transAxes)
    ax.text(-0.22,
            0.5,
            r'$\Delta V_\ast$ [km/s]',
            horizontalalignment='center',
            verticalalignment='center',
            transform=ax.transAxes,
            rotation='vertical')
    ax.text(0.55,
            0.89,
            r'$\mathcal{M}_\ast\propto\ \Delta V^4$',
            horizontalalignment='center',
            verticalalignment='center',
            transform=ax.transAxes,
            rotation=20,
            zorder=4)

    if ofile is None:
        pyplot.show()
    else:
        print('Writing: {0}'.format(ofile))
        fig.canvas.print_figure(ofile, bbox_inches='tight', dpi=100)
    fig.clear()
    pyplot.close(fig)
示例#9
0
def mass_sigma(drpall, dapall, daptype, ofile=None):

    indx = (dapall['DAPDONE'] == 1) & (dapall['DAPTYPE'] == daptype)
    indx &= (dapall['STELLAR_SIGMA_1RE'] > 0)
    indx &= (dapall['NSA_ELPETRO_TH50_R'] > 0)
    indx &= (dapall['ADIST_Z'] > 0)

    is_critical = DAPQualityBitMask().flagged(dapall['DAPQUAL'], 'CRITICAL')
    bd = indx & is_critical
    gd = indx & numpy.invert(is_critical)

    rekpc = dapall['NSA_ELPETRO_TH50_R'] * numpy.radians(
        1 / 3600) * 1e3 * dapall['ADIST_Z']

    font = {'size': 18}
    rc('font', **font)

    w, h = pyplot.figaspect(1)
    fig = pyplot.figure(figsize=(1.5 * w, 1.5 * h))

    mass_lim = [7e7, 3e12]
    sigm_lim = [10, 800]

    inst = numpy.array([[mass_lim[0], 70], [mass_lim[1], 70],
                        [mass_lim[1], sigm_lim[0]], [mass_lim[0],
                                                     sigm_lim[0]]])

    ax = init_ax(fig, [0.2, 0.20, 0.6, 0.6])
    ax.set_xlim(mass_lim)
    ax.set_ylim(sigm_lim)
    ax.set_xscale('log')
    ax.set_yscale('log')

    x = numpy.linspace(6, 14, 100)
    y = x / 2 - 2.6
    ax.plot(numpy.power(10, x), numpy.power(10, y - 2), color='0.8', zorder=0)
    ax.plot(numpy.power(10, x), numpy.power(10, y - 1), color='0.8', zorder=0)
    ax.plot(numpy.power(10, x), numpy.power(10, y), color='0.8', zorder=0)
    ax.plot(numpy.power(10, x), numpy.power(10, y + 1), color='0.8', zorder=0)

    ax.fill(inst[:, 0], inst[:, 1], color='0.1', alpha=0.1, zorder=1)

    sc = ax.scatter(drpall['nsa_sersic_mass'][dapall['DRPALLINDX'][gd]],
                    dapall['STELLAR_SIGMA_1RE'][gd],
                    lw=0,
                    marker='.',
                    s=20,
                    zorder=3,
                    c=rekpc[gd],
                    norm=colors.LogNorm(vmin=1, vmax=30),
                    cmap='inferno')

    ax.scatter(drpall['nsa_sersic_mass'][dapall['DRPALLINDX'][bd]],
               dapall['STELLAR_SIGMA_1RE'][bd],
               lw=0,
               marker='x',
               s=10,
               zorder=3,
               c=rekpc[bd],
               norm=colors.LogNorm(vmin=1, vmax=30),
               cmap='inferno')

    cax = fig.add_axes([0.63, 0.26, 0.15, 0.01])
    cb = pyplot.colorbar(sc,
                         cax=cax,
                         orientation='horizontal',
                         ticks=[1, 10],
                         format=ticker.ScalarFormatter())
    cax.text(0.5,
             3.0,
             r'$R_e$ [kpc]',
             ha='center',
             va='center',
             transform=cax.transAxes)

    ax.text(0.5,
            -0.15,
            r'$\mathcal{M}_\ast$ [$h^{-2} \mathcal{M}_\odot$]',
            horizontalalignment='center',
            verticalalignment='center',
            transform=ax.transAxes)
    ax.text(-0.2,
            0.5,
            r'$\sigma_{\ast,e}$ [km/s]',
            horizontalalignment='center',
            verticalalignment='center',
            transform=ax.transAxes,
            rotation='vertical')
    ax.text(0.51,
            0.85,
            r'$\mathcal{M}_\ast\propto\ \sigma^2_{\ast,e}$',
            horizontalalignment='center',
            verticalalignment='center',
            transform=ax.transAxes,
            rotation=53,
            zorder=4)
    ax.text(0.99,
            0.37,
            r'$\sigma_{\ast,e}\ \lesssim\ \sigma_{\rm inst}$',
            horizontalalignment='right',
            verticalalignment='center',
            transform=ax.transAxes,
            zorder=4)

    if ofile is None:
        pyplot.show()
    else:
        print('Writing: {0}'.format(ofile))
        fig.canvas.print_figure(ofile, bbox_inches='tight', dpi=100)
    fig.clear()
    pyplot.close(fig)
示例#10
0
def mass_lha(drpall, dapall, daptype, eml, ofile=None):

    indx = (dapall['DAPDONE'] == 1) & (dapall['DAPTYPE'] == daptype)
    indx &= (drpall['nsa_sersic_mass'][dapall['DRPALLINDX']] > 0)

    indx &= (dapall['EMLINE_GSB_1RE'][:, eml['Hb-4862']] > -999)
    indx &= (dapall['EMLINE_GSB_1RE'][:, eml['Ha-6564']] > -999)
    indx &= (dapall['SFR_1RE'] > -999)

    decrement = numpy.ma.divide(dapall['EMLINE_GSB_1RE'][:, eml['Ha-6564']],
                                dapall['EMLINE_GSB_1RE'][:, eml['Hb-4862']])

    loew_indx =  indx & (dapall['EMLINE_GEW_1RE'][:,eml['Ha-6564']] > -999)\
                        & (dapall['EMLINE_GEW_1RE'][:,eml['Ha-6564']] < 2)
    hiew_indx = indx & (dapall['EMLINE_GEW_1RE'][:, eml['Ha-6564']] > 2)

    is_critical = DAPQualityBitMask().flagged(dapall['DAPQUAL'], 'CRITICAL')

    loew_bd = loew_indx & is_critical
    hiew_bd = hiew_indx & is_critical

    loew_gd = loew_indx & numpy.invert(is_critical)
    hiew_gd = hiew_indx & numpy.invert(is_critical)

    mass_lim = [1e8, 1e12]
    lha_lim = [36.5, 42.5]

    font = {'size': 16}
    rc('font', **font)

    w, h = pyplot.figaspect(1)
    fig = pyplot.figure(figsize=(1.5 * w, 1.5 * h))

    ax = init_ax(fig, [0.2, 0.2, 0.6, 0.6])
    ax.set_xlim(mass_lim)
    ax.set_ylim(lha_lim)
    ax.set_xscale('log')

    ax.scatter(drpall['nsa_sersic_mass'][dapall['DRPALLINDX'][loew_gd]],
               numpy.ma.log10(dapall['SFR_1RE'][loew_gd]) + 41.27,
               color='0.5',
               marker='.',
               s=20,
               lw=0,
               zorder=3,
               alpha=0.3)

    sc = ax.scatter(drpall['nsa_sersic_mass'][dapall['DRPALLINDX'][hiew_gd]],
                    numpy.ma.log10(dapall['SFR_1RE'][hiew_gd]) + 41.27,
                    c=decrement[hiew_gd],
                    vmin=2.8,
                    vmax=7,
                    marker='.',
                    s=20,
                    lw=0,
                    zorder=4,
                    cmap='inferno')

    ax.scatter(drpall['nsa_sersic_mass'][dapall['DRPALLINDX'][loew_bd]],
               numpy.ma.log10(dapall['SFR_1RE'][loew_bd]) + 41.27,
               color='0.5',
               marker='x',
               s=10,
               lw=0,
               zorder=3,
               alpha=0.3)

    ax.scatter(drpall['nsa_sersic_mass'][dapall['DRPALLINDX'][hiew_bd]],
               numpy.ma.log10(dapall['SFR_1RE'][hiew_bd]) + 41.27,
               c=decrement[hiew_bd],
               vmin=2.8,
               vmax=7,
               marker='x',
               s=10,
               lw=0,
               zorder=4,
               cmap='inferno')

    ax.text(-0.15,
            0.5,
            r'$\log\ \langle L_{{\rm H}\alpha}\rangle_e$ [erg/s]',
            horizontalalignment='center',
            verticalalignment='center',
            transform=ax.transAxes,
            rotation='vertical')

    ax.text(0.5,
            -0.12,
            r'$\mathcal{M}_\ast$ [$h^{-2} \mathcal{M}_\odot$]',
            horizontalalignment='center',
            verticalalignment='center',
            transform=ax.transAxes)

    cax = fig.add_axes([0.58, 0.25, 0.20, 0.01])
    cb = pyplot.colorbar(sc,
                         cax=cax,
                         orientation='horizontal',
                         ticks=[3, 4, 5, 6, 7])
    cax.text(0.5,
             3.0,
             r'$L_{{\rm H}\alpha}/L_{{\rm H}\beta}$',
             ha='center',
             va='center',
             transform=cax.transAxes)  #, fontsize=10)

    if ofile is None:
        pyplot.show()
    else:
        print('Writing: {0}'.format(ofile))
        fig.canvas.print_figure(ofile, bbox_inches='tight', dpi=100)
    fig.clear()
    pyplot.close(fig)
示例#11
0
def get_halpha_data(plt, ifu, hdu):
    el = channel_dictionary(hdu, 'EMLINE_GFLUX')
    uniq_bins, uniq_indx, uniq_cnt = map(
        lambda x: x[1:],
        numpy.unique(hdu['BINID'].data[3].ravel(),
                     return_index=True,
                     return_counts=True))
    keep = numpy.logical_not(hdu['EMLINE_GFLUX_MASK'].data.ravel()[uniq_indx] > 0) \
            | numpy.logical_not(hdu['EMLINE_GEW_MASK'].data.ravel()[uniq_indx] > 0) \
            | numpy.logical_not(hdu['EMLINE_GVEL_MASK'].data.ravel()[uniq_indx] > 0) \
            | numpy.logical_not(hdu['EMLINE_GSIGMA_MASK'].data.ravel()[uniq_indx] > 0)
    uniq_bins = uniq_bins[keep]
    uniq_indx = uniq_indx[keep]
    uniq_cnt = uniq_cnt[keep]
    data = HalphaDataTable(shape=uniq_bins.shape)

    data['PLATE'] = plt
    data['IFU'] = ifu
    data['Y'], data['X'] = numpy.unravel_index(uniq_indx,
                                               hdu['BINID'].shape[1:])
    data['BINID'] = uniq_bins
    data['R'] = hdu['SPX_ELLCOO'].data[0].ravel()[uniq_indx]
    data['R_RE'] = hdu['SPX_ELLCOO'].data[1].ravel()[uniq_indx]
    data['R_KPC'] = hdu['SPX_ELLCOO'].data[2].ravel()[uniq_indx]
    data['GCNT'] = hdu['SPX_MFLUX'].data.ravel()[uniq_indx]
    data['GSNR'] = hdu['SPX_SNR'].data.ravel()[uniq_indx]
    data['FLUX'] = hdu['EMLINE_GFLUX'].data[el['Ha-6564']].ravel()[uniq_indx]
    data['FLUX_ERR'] = numpy.ma.power(
        hdu['EMLINE_GFLUX_IVAR'].data[el['Ha-6564']].ravel()[uniq_indx],
        -0.5).filled(-1)
    data['AMP'] = hdu['EMLINE_GA'].data[el['Ha-6564']].ravel()[uniq_indx]
    data['ANR'] = hdu['EMLINE_GANR'].data[el['Ha-6564']].ravel()[uniq_indx]
    data['RCHI2'] = hdu['EMLINE_LFOM'].data[el['Ha-6564']].ravel()[uniq_indx]
    data['CNT'] = hdu['EMLINE_GEW_CNT'].data[el['Ha-6564']].ravel()[uniq_indx]
    data['EW'] = hdu['EMLINE_GEW'].data[el['Ha-6564']].ravel()[uniq_indx]
    data['EW_ERR'] = numpy.ma.power(
        hdu['EMLINE_GEW_IVAR'].data[el['Ha-6564']].ravel()[uniq_indx],
        -0.5).filled(-1)
    data['VEL'] = hdu['EMLINE_GVEL'].data[el['Ha-6564']].ravel()[uniq_indx]
    data['VEL_ERR'] = numpy.ma.power(
        hdu['EMLINE_GVEL_IVAR'].data[el['Ha-6564']].ravel()[uniq_indx],
        -0.5).filled(-1)
    data['SIG'] = hdu['EMLINE_GSIGMA'].data[el['Ha-6564']].ravel()[uniq_indx]
    data['SIG_ERR'] = numpy.ma.power(
        hdu['EMLINE_GSIGMA_IVAR'].data[el['Ha-6564']].ravel()[uniq_indx],
        -0.5).filled(-1)
    data['SIG_INST'] = hdu['EMLINE_INSTSIGMA'].data[
        el['Ha-6564']].ravel()[uniq_indx]

    # Deal with the masking
    qual_bm = DAPQualityBitMask()
    data_bm = HalphaBitMask()
    if qual_bm.flagged(hdu[0].header['DAPQUAL'], flag='CRITICAL'):
        data['MASK'] = data_bm.turn_on(data['MASK'], 'CRITCUBE')
    indx = hdu['EMLINE_GFLUX_MASK'].data[el['Ha-6564']].ravel()[uniq_indx] > 0
    if numpy.any(indx):
        data['MASK'][indx] = data_bm.turn_on(data['MASK'][indx], 'BADFLUX')
    indx = hdu['EMLINE_GEW_MASK'].data[el['Ha-6564']].ravel()[uniq_indx] > 0
    if numpy.any(indx):
        data['MASK'][indx] = data_bm.turn_on(data['MASK'][indx], 'BADEW')
    indx = (hdu['EMLINE_GVEL_MASK'].data.ravel()[uniq_indx] > 0) \
            | numpy.logical_not(hdu['EMLINE_GVEL_IVAR'].data.ravel()[uniq_indx] > 0)
    if numpy.any(indx):
        data['MASK'][indx] = data_bm.turn_on(data['MASK'][indx], 'BADVEL')
    indx = (hdu['EMLINE_GSIGMA_MASK'].data.ravel()[uniq_indx] > 0) \
            | numpy.logical_not(hdu['EMLINE_GSIGMA_IVAR'].data.ravel()[uniq_indx] > 0)
    if numpy.any(indx):
        data['MASK'][indx] = data_bm.turn_on(data['MASK'][indx], 'BADSIG')

    return data
示例#12
0
def d4000_sigma_haew_snr_dist(fits_file, n, d4000_lim, sigma_lim, haew_lim,
                              snr_lim):

    # Channels with the H-alpha data and the D4000 data
    hac = 18
    d4c = 43

    # Set the method and get the root directory
    method = 'SPX-GAU-MILESHC'
    odir = default_dap_method_path(method)
    print('Output directory: {0}'.format(odir))

    # Find the intermediate files with the stellar-continuum models
    srchstr = os.path.join(odir, '*', '*',
                           'manga-*-MAPS-{0}.fits.gz'.format(method))
    print('Search string: {0}'.format(srchstr))
    maps_files = glob.glob(srchstr)
    nfiles = len(maps_files)
    print('Found {0} MAPS files.'.format(nfiles))

    d4000_bins = numpy.linspace(*d4000_lim, n + 1)
    sigma_bins = numpy.logspace(*numpy.log10(sigma_lim), n + 1)
    haew_bins = numpy.logspace(*numpy.log10(haew_lim), n + 1)
    snr_bins = numpy.logspace(*numpy.log10(snr_lim), n + 1)

    dl = d4000_bins[0]
    dd = d4000_bins[1] - d4000_bins[0]
    sl = numpy.log10(sigma_bins[0])
    ds = numpy.mean(numpy.diff(numpy.log10(sigma_bins)))
    hl = numpy.log10(haew_bins[0])
    dh = numpy.mean(numpy.diff(numpy.log10(haew_bins)))
    nl = numpy.log10(snr_bins[0])
    dn = numpy.mean(numpy.diff(numpy.log10(snr_bins)))

    d4000_vs, vs_sigma = numpy.meshgrid(
        d4000_bins[:-1] + dd / 2,
        sigma_bins[:-1] + ds * sigma_bins[:-1] * numpy.log(10) / 2)
    d4000_vs, vs_haew = numpy.meshgrid(
        d4000_bins[:-1] + dd / 2,
        haew_bins[:-1] + dh * haew_bins[:-1] * numpy.log(10) / 2)
    d4000_vs, vs_snr = numpy.meshgrid(
        d4000_bins[:-1] + dd / 2,
        snr_bins[:-1] + dn * snr_bins[:-1] * numpy.log(10) / 2)
    sigma_vs, vs_haew = numpy.meshgrid(
        sigma_bins[:-1] + ds * sigma_bins[:-1] * numpy.log(10) / 2,
        haew_bins[:-1] + ds * haew_bins[:-1] * numpy.log(10) / 2)
    sigma_vs, vs_snr = numpy.meshgrid(
        sigma_bins[:-1] + ds * sigma_bins[:-1] * numpy.log(10) / 2,
        snr_bins[:-1] + dn * snr_bins[:-1] * numpy.log(10) / 2)
    haew_vs, vs_snr = numpy.meshgrid(
        haew_bins[:-1] + dh * haew_bins[:-1] * numpy.log(10) / 2,
        snr_bins[:-1] + dn * snr_bins[:-1] * numpy.log(10) / 2)

    bin_d4000_vs_sigma = numpy.zeros((n, n), dtype=int)
    bin_d4000_vs_haew = numpy.zeros((n, n), dtype=int)
    bin_d4000_vs_snr = numpy.zeros((n, n), dtype=int)
    bin_sigma_vs_haew = numpy.zeros((n, n), dtype=int)
    bin_sigma_vs_snr = numpy.zeros((n, n), dtype=int)
    bin_haew_vs_snr = numpy.zeros((n, n), dtype=int)

    qual_bm = DAPQualityBitMask()
    maps_bm = DAPMapsBitMask()

    for fi in range(nfiles):
        #    for fi in range(20):
        print('{0}/{1}'.format(fi + 1, nfiles), end='\r')
        maps_file = maps_files[fi]
        print(maps_file)

        # Get the bin IDs, mapped to the correct spaxels
        hdu = fits.open(maps_file)

        # Check if the file was CRITICAL
        if qual_bm.flagged(hdu['PRIMARY'].header['DAPQUAL'], flag='DRPCRIT'):
            print('DRPCRIT')
            print(maps_file)
            hdu.close()
            del hdu
            continue

        plt, ifu = tuple(
            [int(x) for x in hdu[0].header['PLATEIFU'].split('-')])
        nsa_z = hdu['PRIMARY'].header['SCINPVEL'] / astropy.constants.c.to(
            'km/s').value
        binid_map = hdu['BINID'].data[0, :, :].copy()

        spatial_shape = binid_map.shape
        binid, bin_indx = numpy.unique(binid_map.ravel(), return_index=True)
        binid = binid[1:]
        bin_indx = bin_indx[1:]

        # Get the D4000, H-alpha EW, and sigma values
        #        snr = hdu['SPX_SNR'].data.ravel()[bin_indx]
        #        snr_indx = snr > 1
        #        good_snr = snr[snr_indx]
        #        binid_snr = binid[snr_indx]

        mask = (hdu['EMLINE_GEW'].data[hac,:,:].ravel()[bin_indx] > 0) \
               & (hdu['SPECINDEX'].data[d4c,:,:].ravel()[bin_indx] > 0) \
               & (hdu['STELLAR_SIGMA'].data.ravel()[bin_indx] > 0) \
               & (hdu['SPX_SNR'].data.ravel()[bin_indx] > 0)

        haew = hdu['EMLINE_GEW'].data[hac, :, :].ravel()[bin_indx][mask]
        d4000 = hdu['SPECINDEX'].data[d4c, :, :].ravel()[bin_indx][mask]
        sigma = hdu['STELLAR_SIGMA'].data.ravel()[bin_indx][mask]
        snr = hdu['SPX_SNR'].data.ravel()[bin_indx][mask]

        hdu.close()
        del hdu

        bin_d4000_vs_sigma += twod_bin(d4000, numpy.log10(sigma), dl, dd, n,
                                       sl, ds, n)
        bin_d4000_vs_haew += twod_bin(d4000, numpy.log10(haew), dl, dd, n, hl,
                                      dh, n)
        bin_d4000_vs_snr += twod_bin(d4000, numpy.log10(snr), dl, dd, n, nl,
                                     dn, n)
        bin_sigma_vs_haew += twod_bin(numpy.log10(sigma), numpy.log10(haew),
                                      sl, ds, n, hl, dh, n)
        bin_sigma_vs_snr += twod_bin(numpy.log10(sigma), numpy.log10(snr), sl,
                                     ds, n, nl, dn, n)
        bin_haew_vs_snr += twod_bin(numpy.log10(haew), numpy.log10(snr), hl,
                                    dh, n, nl, dn, n)

    fits.HDUList([
        fits.PrimaryHDU(),
        fits.ImageHDU(data=bin_d4000_vs_sigma, name='D4000SIGMA'),
        fits.ImageHDU(data=bin_d4000_vs_haew, name='D4000HAEW'),
        fits.ImageHDU(data=bin_d4000_vs_snr, name='D4000SNR'),
        fits.ImageHDU(data=bin_sigma_vs_haew, name='SIGMAHAEW'),
        fits.ImageHDU(data=bin_sigma_vs_snr, name='SIGMASNR'),
        fits.ImageHDU(data=bin_haew_vs_snr, name='HAEWSNR')
    ]).writeto(fits_file, overwrite=True)
示例#13
0
def include_maps_data(tbl, maps_file, exclude_ancillary=False):
    qual_bm = DAPQualityBitMask()
    bm = DAPMapsBitMask()

    #    # Targeting bits
    #    sdssMaskbits = defaults.sdss_maskbits_file()
    #    mngtarg1_bm = BitMask.from_par_file(sdssMaskbits, 'MANGA_TARGET1')
    #    mngtarg3_bm = BitMask.from_par_file(sdssMaskbits, 'MANGA_TARGET3')

    with fits.open(maps_file) as hdu:
        # Check if the file was CRITICAL
        if qual_bm.flagged(hdu['PRIMARY'].header['DAPQUAL'], flag='DRPCRIT'):
            return 1
        if exclude_ancillary and hdu[0].header['MNGTARG1'] == 0:
            return 1

        d4000_bins = numpy.unique(tbl['D4000BIN'])
        sigma_bins = numpy.unique(tbl['SIGMABIN'])
        haew_bins = numpy.unique(tbl['HAEWBIN'])
        snr_bins = numpy.unique(tbl['SNRBIN'])
        nsigma = len(sigma_bins) - 1
        nd4000 = len(d4000_bins) - 1
        nhaew = len(haew_bins) - 1
        nsnr = len(snr_bins) - 1

        el = channel_dictionary(hdu, 'EMLINE_GFLUX')
        si = channel_dictionary(hdu, 'SPECINDEX')

        plt, ifu = map(lambda x: int(x),
                       os.path.split(maps_file)[1].split('-')[1:3])

        # Input redshift
        z = hdu['PRIMARY'].header['SCINPVEL'] / astropy.constants.c.to(
            'km/s').value

        # Stellar-kinematics binning map
        binid, bin_indx = map(
            lambda x: x[1:],
            numpy.unique(hdu['BINID'].data[1, :, :].ravel(),
                         return_index=True))

        # Get the D4000, H-alpha EW, and sigma values with S/N greater
        # than one and unmasked
        good_snr = hdu['SPX_SNR'].data.ravel() > 1
        good_haew = numpy.logical_not(
            bm.flagged(hdu['EMLINE_GEW_MASK'].data[el['Ha-6564']].ravel(),
                       flag='DONOTUSE'))
        good_d4000 = numpy.logical_not(
            bm.flagged(hdu['SPECINDEX_MASK'].data[si['D4000']].ravel(),
                       flag='DONOTUSE'))
        good_sigma = numpy.logical_not(
            bm.flagged(hdu['STELLAR_SIGMA_MASK'].data.ravel(),
                       flag='DONOTUSE'))

        indx = (good_snr & good_haew & good_d4000 & good_sigma)[bin_indx]
        snr = hdu['SPX_SNR'].data.ravel()[bin_indx][indx]
        stvel = hdu['STELLAR_VEL'].data.ravel()[bin_indx][indx]
        sigma = hdu['STELLAR_SIGMA'].data.ravel()[bin_indx][indx]
        haanr = hdu['EMLINE_GANR'].data[el['Ha-6564']].ravel()[bin_indx][indx]
        havel = hdu['EMLINE_GVEL'].data[el['Ha-6564']].ravel()[bin_indx][indx]
        hasig = hdu['EMLINE_GSIGMA'].data[
            el['Ha-6564']].ravel()[bin_indx][indx]
        haew = hdu['EMLINE_GEW'].data[el['Ha-6564']].ravel()[bin_indx][indx]
        d4000 = hdu['SPECINDEX'].data[si['D4000']].ravel()[bin_indx][indx]
        binid = binid[indx]

        d4000_i = numpy.digitize(d4000, d4000_bins[1:-1])
        sigma_j = numpy.digitize(sigma, sigma_bins[1:-1])
        haew_k = numpy.digitize(haew, haew_bins[1:-1])
        snr_l = numpy.digitize(snr, snr_bins[1:-1])

        for i in range(nd4000):
            dindx = d4000_i == i
            for j in range(nsigma):
                sindx = sigma_j == j
                for k in range(nhaew):
                    hindx = haew_k == k
                    for l in range(nsnr):
                        nindx = snr_l == l

                        indx = dindx & sindx & hindx & nindx

                        nbin = numpy.sum(indx)
                        if nbin == 0:
                            continue

                        ii = i * nsigma * nhaew * nsnr + j * nhaew * nsnr + k * nsnr + l
                        tbl['NBIN'][ii] += nbin

                        _snr = snr[indx]
                        # Still find the highest S/N spectrum in each
                        # bin
                        m = numpy.argsort(_snr)[-1]
                        if _snr[m] < tbl['SNR'][ii]:
                            continue

                        tbl['PLT'][ii] = plt
                        tbl['IFU'][ii] = ifu
                        tbl['BIN'][ii] = binid[indx][m]
                        tbl['MNGTARG1'][ii] = int(hdu[0].header['MNGTARG1'])
                        tbl['MNGTARG3'][ii] = int(hdu[0].header['MNGTARG3'])
                        tbl['Z'][ii] = z
                        tbl['SNR'][ii] = snr[indx][m]
                        tbl['STZ'][ii] \
                            = stvel[indx][m]*(1+z)/astropy.constants.c.to('km/s').value + z
                        tbl['SIGMA'][ii] = sigma[indx][m]
                        tbl['HAANR'][ii] = haanr[indx][m]
                        tbl['HAZ'][ii] \
                            = havel[indx][m]*(1+z)/astropy.constants.c.to('km/s').value + z
                        tbl['HASIGMA'][ii] = hasig[indx][m]
                        tbl['HAEW'][ii] = haew[indx][m]
                        tbl['D4000'][ii] = d4000[indx][m]

    return 0