Ejemplo n.º 1
0
def test_par_io():
    
    bm = BitMask.from_par_file(data_test_file('imagebitmask.par'), 'IMAGEMASK')
    assert list(bm.keys()) == ['BPM', 'COSMIC', 'SATURATED']
    assert list(bm.bits.values()) == [0, 1, 2]

    bm = ImageBitMaskFromPar()
    assert list(bm.keys()) == ['BPM', 'COSMIC', 'SATURATED']
    assert list(bm.bits.values()) == [0, 1, 2]
Ejemplo n.º 2
0
def test_hdr_io():
    
    image_bm = ImageBitMask()
    hdr = fits.Header()
    image_bm.to_header(hdr)

    assert list(hdr.keys()) == ['BIT0', 'BIT1', 'BIT2']
    assert list(hdr.values()) == ['BPM', 'COSMIC', 'SATURATED']

    bm = BitMask.from_header(hdr)
    assert list(bm.bits.keys()) == ['BPM', 'COSMIC', 'SATURATED']
    assert list(bm.bits.values()) == [0, 1, 2]
def mpl8_main_sample(file):
    mpl8 = pd.read_csv(file, comment='#')
    tab = mpl8[(((mpl8.mngtarg1 != 0) | (mpl8.mngtarg3 != 0)) &
                ((mpl8.mngtarg3 & int(2)**int(19) + int(2)**int(20)) == 0))]
    sdssMaskbits = os.path.join(os.environ['IDLUTILS_DIR'], 'data', 'sdss',
                                'sdssMaskbits.par')
    bm = BitMask.from_par_file(sdssMaskbits, 'MANGA_TARGET1')
    main_sample = bm.flagged(
        tab.mngtarg1,
        flag=['PRIMARY_v1_2_0', 'SECONDARY_v1_2_0', 'COLOR_ENHANCED_v1_2_0'])
    # Removing ancillary progs and repeat obs.
    mpl8_main = tab[main_sample]
    mpl8_main = mpl8_main.iloc[np.unique(mpl8_main.mangaid.values,
                                         return_index=True)[1]]
    return mpl8_main
Ejemplo n.º 4
0
 def __init__(self):
     tmp = BitMask.from_par_file(data_test_file('imagebitmask.par'), 'IMAGEMASK')    
     super(ImageBitMaskFromPar, self).__init__(tmp.keys(), descr=tmp.descr)
Ejemplo n.º 5
0
def test_ini_io():
    
    bm = BitMask.from_ini_file(data_test_file('imagebitmask.ini'))
    assert list(bm.bits.keys()) == ['BPM', 'COSMIC', 'SATURATED']
    assert list(bm.bits.values()) == [0, 1, 2]
Ejemplo n.º 6
0
 def __init__(self, sdss_maskbits=None, trgt='MANGA_TARGET1'):
     _sdss_maskbits = defaults.sdss_maskbits_file() if sdss_maskbits is None else sdss_maskbits
     tmp = BitMask.from_par_file(str(_sdss_maskbits), trgt)
     keys, descr = tmp._init_objs()
     super(MaNGATargetBitMask, self).__init__(keys, descr=descr)
Ejemplo n.º 7
0
def channel_bitmask():
    return BitMask(['ERRORS', 'MASKED'])
Ejemplo n.º 8
0
import numpy
from astropy.io import fits
from matplotlib import pyplot

from mangadap.util.bitmask import BitMask
from mangadap.config import defaults

sdssbits_file = defaults.sdss_maskbits_file()

targ1bm = BitMask.from_par_file(sdssbits_file, 'MANGA_TARGET1')
targ2bm = BitMask.from_par_file(sdssbits_file, 'MANGA_TARGET2')
targ3bm = BitMask.from_par_file(sdssbits_file, 'MANGA_TARGET3')

hdu = fits.open('drpall-v3_1_1.fits')

#print(hdu['MANGA'].columns.names)

indx = hdu['MANGA'].data['z'] < 0

mngtarg1 = hdu['MANGA'].data['mngtarg1'][indx]
mngtarg2 = hdu['MANGA'].data['mngtarg2'][indx]
mngtarg3 = hdu['MANGA'].data['mngtarg3'][indx]

print('MANGA_TARGET1')
for b in numpy.unique(mngtarg1):
    print(b, targ1bm.flagged_bits(b))

print('MANGA_TARGET2')
for b in numpy.unique(mngtarg2):
    print(b, targ2bm.flagged_bits(b))
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
from mangadap.util.bitmask import BitMask
import os
from astropy.io import fits
import sys

# ---------------------------------------------------------------------------------------
# defining number of processes to use. since this is local, lets not go crazy.
processes = os.cpu_count()

# ---------------------------------------------------------------------------------------
# Setting up environment of loading in non-critical files.

drpall = fits.open('/Users/cd201/Data/MaNGA/MPL-8-DAP/find_maps/drpall-v2_5_3.fits')[1].data
gal = drpall[(((drpall.mngtarg1 != 0) | (drpall.mngtarg3 != 0)) & ((drpall.mngtarg3 & int(2)**int(19)+int(2)**int(20)) == 0) )]
sdssMaskbits = os.path.join(os.environ['IDLUTILS_DIR'], 'data', 'sdss', 'sdssMaskbits.par')
bm = BitMask.from_par_file(sdssMaskbits, 'MANGA_DRP3QUAL')
critical = bm.flagged(gal.drp3qual, flag='CRITICAL')
data_dir = '/Users/cd201/Data/MaNGA/MPL-8-DAP/VOR10-GAU-MILESHC/'

# ---------------------------------------------------------------------------------------
# Defining wrapper function for multiprocessing. 

def multiproc_wrapper(gal_str):
    file_name = 'manga-'+gal_str+'-MAPS-VOR10-MILESHC-MILESHC.fits.gz'
    file_path = os.path.join(data_dir, gal_str.split("-")[0], gal_str.split("-")[1],file_name)
    plt.close()
    stellar_pa, halpha_pa  = pa_funcs.pa_wrapper(file_path, plot=True)
    plt.savefig('/Users/cd201/mpl8-kin-mis/plots/pa_fits/'+gal_str+'-PA.pdf', format='pdf', bbox_inches='tight')
    return stellar_pa, halpha_pa

# ---------------------------------------------------------------------------------------
Ejemplo n.º 11
0
def find_repeat_observations(output_file, drpver, redux_path, dapver,
                             analysis_path, directory_path):

    # Get the DRPComplete database
    drpc = DRPComplete(drpver=drpver,
                       redux_path=redux_path,
                       dapver=dapver,
                       analysis_path=analysis_path,
                       directory_path=directory_path,
                       readonly=True)
    try:
        drpc._confirm_access()
    except FileNotFoundError:
        warnings.warn(
            'DRPComplete file must be present to find repeat observations!')
        raise
    except:
        raise

    # Get the maskbits file
    sdssMaskbits = defaults.sdss_maskbits_file()

    # Instantiate the BitMask object
    mngtarg1_bm = BitMask.from_par_file(sdssMaskbits, 'MANGA_TARGET1')
    mngtarg3_bm = BitMask.from_par_file(sdssMaskbits, 'MANGA_TARGET3')

    print('# DRPComplete file: {0}'.format(drpc.file_path()))
    print('# Total number of DRPComplete entries: {0}'.format(drpc.nobs))
    valid_galaxy = ((drpc['MANGA_TARGET1'] > 0) |
                    (drpc['MANGA_TARGET3'] > 0)) & (drpc['VEL'] > 0)
    ngal = numpy.sum(valid_galaxy)
    print('# Number of valid galaxies: {0}'.format(ngal))

    mid = drpc['MANGAID'][valid_galaxy].copy()
    plt = drpc['PLATE'][valid_galaxy].copy()
    ifu = drpc['IFUDESIGN'][valid_galaxy].copy()

    # Find the unique MaNGA IDs
    unid, unid_indx, unid_invs, unid_cnts = numpy.unique(mid,
                                                         return_index=True,
                                                         return_inverse=True,
                                                         return_counts=True)

    with open(output_file, 'w') as f:
        double_print(f,
                     '# Number of DRPComplete entries: {0}'.format(mid.size))
        double_print(f, '# Number of unique MaNGA IDs: {0}'.format(unid.size))
        max_rep = numpy.amax(unid_cnts)
        double_print(
            f,
            '# Maximum number of repeated observations: {0}'.format(max_rep))
        double_print(f, '#')
        double_print(f, '#{0:>9s}'.format('MANGAID'), end='')
        for i in range(max_rep):
            double_print(f,
                         ' {1:>4s}{0} {2:>4s}{0}'.format(i + 1, 'PLT', 'IFU'),
                         end='')
        double_print(f, '')
        for i in range(len(unid)):
            if unid_cnts[i] == 1:
                continue
            indx = numpy.where(mid == unid[i])[0]
            nempty = max_rep - len(indx)

            double_print(f, ' {0:>9s}'.format(unid[i]), end='')
            for j in range(len(indx)):
                double_print(f,
                             ' {0:>5} {1:>5}'.format(plt[indx[j]],
                                                     ifu[indx[j]]),
                             end='')
            if nempty > 0:
                for j in range(nempty):
                    double_print(f, ' {0:>5} {1:>5}'.format(-1, -1), end='')
            double_print(f, '')
Ejemplo n.º 12
0
def radial_coverage_histogram(dapall, plot_file=None):

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

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

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

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

    # 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', nonposy='clip')
    ifu = [ 19, 37, 61, 91, 127 ]
    for i,f in enumerate(ifu):
        indx = (dapall['IFUDESIGN']/100).astype(int) == f
        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', nonposy='clip')
    ax.hist(rore[primaryplus], bins=50, range=rore_rng, alpha=0.5, histtype='stepfilled',
            color='C0', zorder=2)
    ax.hist(rore[primaryplus], bins=50, range=rore_rng, histtype='step',
            color='C0', zorder=3)
    medp = numpy.median(rore[primaryplus])
    ax.plot([medp, medp], nlim, color='C0', zorder=4, linestyle='--')
    ax.hist(rore[secondary], bins=50, range=rore_rng, alpha=0.5, histtype='stepfilled',
            color='C1', zorder=2)
    ax.hist(rore[secondary], bins=50, range=rore_rng, histtype='step',
            color='C1', zorder=3)
    medp = numpy.median(rore[secondary])
    ax.plot([medp, medp], nlim, color='C1', zorder=4, linestyle='--')
    ax.hist(rore[other], bins=50, range=rore_rng, alpha=0.5, histtype='stepfilled',
            color='C2', zorder=2)
    ax.hist(rore[other], bins=50, range=rore_rng, histtype='step',
            color='C2', zorder=3)
    ax.hist(rore[ancillary], bins=50, range=rore_rng, alpha=0.5, histtype='stepfilled',
            color='C3', zorder=2)
    ax.hist(rore[ancillary], 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 plot_file is None:
        pyplot.show()
    else:
        fig.canvas.print_figure(plot_file, bbox_inches='tight')
    fig.clear()
    pyplot.close(fig)