def test_draw_hires(self): """ Draw a partial healpix map with very large nside """ nside = 4096 * 2**5 ra, dec = 45, -45 radius = 0.05 pixels = skymap.healpix.ang2disc(nside, ra, dec, radius) values = pixels plt.figure() # Use the Cassini projection (because we can) m = Skymap(projection='cass', lon_0=ra, lat_0=dec, celestial=False, llcrnrlon=ra + 2 * radius, urcrnrlon=ra - 2 * radius, llcrnrlat=dec - 2 * radius, urcrnrlat=dec + 2 * radius) m.draw_hpxmap(values, pixels, nside=nside, xsize=400) m.draw_parallels(np.linspace(dec - 2 * radius, dec + 2 * radius, 5), labelstyle='+/-', labels=[1, 0, 0, 0]) m.draw_meridians(np.linspace(ra - 2 * radius, ra + 2 * radius, 5), labelstyle='+/-', labels=[0, 0, 0, 1]) plt.title('HEALPix Zoom (nside=%i)' % nside)
overwrite=True, nest=True, fits_IDL=False, partial=True) #Make plot of the healpix map upix, uval = [], [] for jj, vv in enumerate(hp_aux): if vv != hp.UNSEEN: upix.append(jj) uval.append(vv) upix = np.array(upix) uval = np.array(uval) k = hp.nest2ring(4096, upix) m = Skymap(projection='cass', lon_0=67., lat_0=-60., celestial=False, llcrnrlon=56.68, urcrnrlon=77.46, llcrnrlat=-64.2, urcrnrlat=-55.40, parallels=False, meridians=False) m.draw_hpxmap(uval, k, nside=4096, xsize=1000) plt.savefig('healpix_imageLow.png')
paint = np.array(paint) pix = np.array(pix) m = Skymap(projection='cass', lon_0=67., lat_0=-60., celestial=False, llcrnrlon=56.68, urcrnrlon=77.46, llcrnrlat=-64.2, urcrnrlat=-55.40, parallels=False, meridians=False) da = m.draw_hpxmap(paint, pix, nside=512, xsize=1000) plt.colorbar() plt.savefig('healpix_dra.png') plt.close() paintRA = paint.copy() #New Dra pix = [] paint = [] for j, val in enumerate(draN): if val != hp.UNSEEN: pix.append(j) paint.append(val)
def main(survey, plot=True, write=True): print("Creating mask with NSIDE={} and NEST={}...".format(NSIDE, NEST)) # Initiate_mask if args.load is not None: healpix_mask = ugali.utils.healpix.read_map(args.load, nest=NEST) else: healpix_mask = np.tile(0, hp.nside2npix(NSIDE)) infile_dust = 'ebv_sfd98_fullres_nside_4096_nest_equatorial.fits.gz' ebv_map = ugali.utils.healpix.read_map(infile_dust, nest=True) cut_ebv = (ebv_map > 0.2) healpix_mask[cut_ebv] |= 0b00001 """ McConnachie15: Half-light radius along major axis. Could incorporate ellipticity info Harris96: Half-light radius Corwen04: No radius data Nilson73: Major axis (no ellipticity info) Webbink85: 10**log(radius) Kharchenko13: Radius of the central part Bica08: Major axis. Could incorporate ellipticity info WEBDA: Diameter/2 ExtraDwarfs: Half-light radius ExtraClusters: Half-light radius Vizier data on: Nilson73, Webbink85 (should check log or ln), Kharchenko13 (3 radii, used middle), Bica08 ugali data on: McConnachi15, Harris96, WEBDA14 """ external_cat_list = [ 'Harris96', 'Corwen04', 'Nilson73', 'Webbink85', 'Kharchenko13', 'Bica08', 'WEBDA14', 'ExtraClusters', 'ExtraStructures' ] for external_cat in external_cat_list: if args.mode == 1: catalog = ugali.candidate.associate.catalogFactory(external_cat) external_cut = cut_circles(catalog['ra'], catalog['dec'], default_radius=0.1) elif args.mode == 2: catalog = associate.catalogFactory(external_cat) external_cut = cut_circles(catalog['ra'], catalog['dec'], catalog['radius'], default_radius=0.1) healpix_mask[external_cut] |= 0b00010 known_dwarfs = ['McConnachie15', 'ExtraDwarfs'] for external_cat in known_dwarfs: if args.mode == 1: catalog = ugali.candidate.associate.catalogFactory(external_cat) external_cut = cut_circles(catalog['ra'], catalog['dec'], default_radius=0.1) elif args.mode == 2: catalog = associate.catalogFactory(external_cat) external_cut = cut_circles(catalog['ra'], catalog['dec'], catalog['radius'], default_radius=0.1) healpix_mask[external_cut] |= 0b00100 reader_bsc = pyfits.open('bsc5.fits') d_bsc = reader_bsc[1].data bsc_cut = cut_circles(d_bsc['RA'], d_bsc['DEC'], default_radius=0.1) healpix_mask[bsc_cut] |= 0b01000 if 'des' == survey: des_footprint = ugali.utils.healpix.read_map( 'y3a2_footprint_griz_1exp_v2.0.fits.gz', nest=True) #print('Masking footprint...') #npix = hp.nside2npix(NSIDE) #nbad = 3 #des_cut = np.fromiter( (des_footprint[i] < 1 or sum(des_footprint[hp.get_all_neighbours(NSIDE, i)] < 1) >= nbad for i in range(npix)), dtype=bool, count=npix ) # Mask if at least nbad neighbors outside the footprint des_cut = des_footprint < 1 healpix_mask[des_cut] |= 0b10000 if 'ps1' == survey: ps1_cut = hp.query_strip( NSIDE, np.radians(90.0 - -25.0), np.radians(90.0 - -90.0), nest=False ) # This function apparently isn't implemented for nest=True ps1_cut = hp.ring2nest(NSIDE, ps1_cut) healpix_mask[ps1_cut] |= 0b10000 #failures = pyfits.open('ugali_failures.fits')[1].data # NSIDE = 256 #fail_pix_256 = [ugali.utils.healpix.angToPix(256, fail['ra'], fail['dec'], nest=NEST) for fail in failures] #fail_pix = ugali.utils.healpix.ud_grade_ipix(fail_pix_256, 256, NSIDE, nest=NEST) #healpix_mask[fail_pix] |= 0b100000 # Artifact masks artifact_coords = np.array([ (278.70, 38.67), # J1834.8+3840, obvious masking issue (35.01, -3.04), # J0220.1-0302, psf failures (201.59, -11.47), # J1326.4-1128, obvious masking issue (214.52, 19.20), # J1418.1+1912, obvious masking issue #(131.50, 28.57), # J0846.0+2834, ??? (262.66, 52.11), # J1730.7+5206, likely artifact #(169.99, -14.96), # J1120.0-1457, ??? (186.55, 46.17), # J1226.2+4609, likely artifact (145.22, -13.74), # J0940.9-1344, likely artifact (28.11, 19.39), # J0152.5+1923, no uglai source? #(247.73, -0.97), # J1630.9+0058, real star cluster (19.40, -17.44) ]) # J0117.6-1726, Cetus II #(39.88, 0.18)]) # J0239.5+0010, artifact_ras, artifact_decs = artifact_coords.T artifact_cut = cut_circles(artifact_ras, artifact_decs, default_radius=0.1) healpix_mask[artifact_cut] |= 0b1000000 if plot: print("Simplifying mask for plotting...") simplified_mask = np.copy(healpix_mask) cut_catalog = np.where((simplified_mask & 0b00010) | (simplified_mask & 0b00100) | (simplified_mask & 0b01000)) cut_ebv = np.where(simplified_mask & 0b00001) cut_footprint = np.where((simplified_mask & 0b10000) | (simplified_mask & 0b100000) | (simplified_mask & 0b1000000)) simplified_mask[cut_catalog] = 1 simplified_mask[cut_ebv] = 2 simplified_mask[cut_footprint] = 3 print("Plotting...") title = '' if survey == 'des': title = 'DES ' + title elif survey == 'ps1': title = 'Pan-STARRS ' + title """ # Using mollview hp.mollview(simplified_mask, nest=True, coord='C', cmap=new_cmap, title=title, xsize=1600) ax = plt.gca() cbar = ax.images[-1].colorbar cbar.set_ticks( (np.arange(n) + 0.5)*(n-1)/n ) cbar.set_ticklabels(['Unmasked', 'Association', r'$E(B-V)$', 'Footprint']) hp.graticule() plt.savefig('healpix_mask_{}_v{}.png'.format(survey, version), bbox_inches='tight') """ # Using skymap simplified_mask_ring = hp.reorder(simplified_mask, n2r=True) fig, ax = plt.subplots(figsize=(12, 8)) smap = Skymap(projection='mbtfpq', lon_0=0) im, lon, lat, values = smap.draw_hpxmap(simplified_mask_ring, xsize=1600, cmap=new_cmap) cbar = plt.colorbar(ticks=(np.arange(n) + 0.5) * (n - 1) / n, fraction=0.02) cbar.set_ticklabels( ['Unmasked', 'Association', r'$E(B-V) > 0.2$', 'Footprint']) plt.title(title) plt.savefig('healpix_mask_{}_v{}.png'.format(survey, version), bbox_inches='tight') if write: print('Writing mask to healpix_mask_{}_v{}.fits.gz ...'.format( survey, version)) hp.write_map('healpix_mask_{}_v{}.fits.gz'.format(survey, version), healpix_mask, dtype=np.int32, nest=NEST, coord='C', overwrite=True) return healpix_mask, simplified_mask_ring
if args.survey is None: des_mask, des_mask_simplified = main('des', plot=(not args.no_plot), write=(not args.no_write)) ps1_mask, ps1_mask_simplified = main('ps1', plot=(not args.no_plot), write=(not args.no_write)) # Put the two healpix masks on the same plot fig, axes = plt.subplots(nrows=2, ncols=1, figsize=(12, 10)) plt.sca(axes[0]) smap = Skymap(projection='mbtfpq', lon_0=0) im, lon, lat, values = smap.draw_hpxmap(des_mask_simplified, xsize=1600, cmap=new_cmap) plt.title('DES', fontsize='large') plt.sca(axes[1]) smap = Skymap(projection='mbtfpq', lon_0=0) im, lon, lat, values = smap.draw_hpxmap(ps1_mask_simplified, xsize=1600, cmap=new_cmap) plt.title('Pan-STARRS', fontsize='large') fig.subplots_adjust(right=0.8) cbar_ax = fig.add_axes([0.85, 0.175, 0.020, 0.65]) cbar = fig.colorbar(im, cax=cbar_ax, ticks=(np.arange(n) + 0.5) * (n - 1) / n) cbar.set_ticklabels( ['Unmasked', 'Association', r'$E(B-V) > 0.2$', 'Footprint'])