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)
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)
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))
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, '')