def __init__( self, freq=888, plot_hpx_order=7, gridsep=30, cmap=matplotlib.pyplot.get_cmap("Dark2"), projection="Mollweide", **kwargs, ): if projection not in skymapper.projection_register.keys(): raise ValueError( f"Projection {projection} not valid for skymapper") self.freq = freq self.plot_hpx_order = plot_hpx_order self.nside = 2**self.plot_hpx_order self.gridsep = gridsep if isinstance(cmap, matplotlib.colors.ListedColormap): self.cmap = cmap.colors else: self.cmap = cmap # make the background map gsm_nside = 512 # pygsm outputs nside=512 npix = healpy.nside2npix(gsm_nside) ra, dec = healpy.pix2ang(gsm_nside, np.arange(npix), lonlat=True) coords = SkyCoord(ra, dec, unit="deg") gsm = pygsm.GlobalSkyModel() # this is in Galactic coords - convert back to equatorial bg_gsm = gsm.generate(self.freq) coords_gal = coords.galactic bg_gsm_equatorial = healpy.pixelfunc.get_interp_val(bg_gsm, coords_gal.l.value, coords_gal.b.value, lonlat=True) bg_gsm_equatorial_o7 = healpy.ud_grade( bg_gsm_equatorial, self.nside) # degrade the resolution # self.projection = skymapper.Mollweide(lon_0=RA0) self.projection = getattr(skymapper, projection)(**kwargs) self.ax = skymapper.Map(self.projection, interactive=False) self.ax.grid(sep=self.gridsep) self.color_cycle = cycler(facecolors=self.cmap) self.color_cycle_it = iter(self.color_cycle) # and plot the background map self.ax.healpix( bg_gsm_equatorial_o7, color_percentiles=[0, 99], cmap="Greys", norm=matplotlib.colors.LogNorm(), ) self.plotted_surveys = [] self.labels = []
import skymapper as skm if __name__ == "__main__": # cycle through all defined projections and show the full sky # with default graticules args = {"lon_0": 0} conic_args = {"lon_0": 0, "lat_0": -10, "lat_1": -40, "lat_2": 10} for name, proj_cls in skm.projection_register.items(): proj = None try: proj = proj_cls(**args) except TypeError: try: proj = proj_cls(**conic_args) except TypeError: pass if proj is not None: map = skm.Map(proj, interactive=False) map.grid() map.title(name) map.show()
def plot_hp_skymapper(obs, mask, projection=None, filename=None, vmax=None, cmap=None, cb_label=None, nside_out=True): """ Plot a healpix masked map using skymapper. Parameters ---------- obs : array Healpix map. mask : array Mask map. projection : type - 'DESY3', in which case it uses precomputed best projection for the Y3 footprint, - a predefined skymapper projection objectself, - or None, if which case the projection is infered from the mask. filename : string If not None, the name of the file to save the figure (the default is None). vmax : type - a float, in which case the color scale goes from -vmax to +vmax - 'best', in which case skymapper uses the 10-90 percentiles - None, in which case the min/max values of `obs` are used. cmap : type Color map (the default is None). cb_label : string Label of the color bar (the default is None). nside_out : bool or int Whether to degrade obs to make if faster or the nside to use (the default is True, in which case nside=256 is used). Returns ------- type Description of returned object. Raises ------- ExceptionName Why the exception is raised. """ import skymapper as skm import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable assert obs.shape == mask.shape, "[plot_hp_skymapper] `obs` and `mask` don't have the same shape." fig = plt.figure(figsize=(10,6)) ax = fig.add_subplot(111) nside_in = hp.npix2nside(len(mask)) theta, phi = hp.pix2ang(nside_in, np.arange(len(mask))[mask.astype(bool)]) ra, dec = thetaphi2radec(theta, phi) if projection == 'DESY3': # define the best Albers projection for the footprint # minimizing the variation in distortion # crit = skm.meanDistortion # proj = skm.Albers.optimize(a['ra'], a['dec'], crit=crit) proj = skm.Albers( 28.51234891, -43.90175288, -55.63596295, -32.39570739) else : if projection is None: crit = skm.meanDistortion proj = skm.Albers.optimize(ra, dec, crit=crit) # construct map: will hold figure and projection # the outline of the sphere can be styled with kwargs for matplotlib Polygon map = skm.Map(proj, ax=ax) # add graticules, separated by 15 deg # the lines can be styled with kwargs for matplotlib Line2D # additional arguments for formatting the graticule labels # sep = 15 map.grid() map.focus(ra, dec) obs_plot = np.copy(obs) maskmap(obs_plot, mask, fill_UNSEEN=False) if nside_out: if type(nside_out) is int: obs_plot = hp.ud_grade(obs_plot, nside_out=nside_out) else: obs_plot = hp.ud_grade(obs_plot, nside_out=256) if type(vmax) is float: mappable = map.healpix(obs_plot, cmap=cmap, vmin=-vmax, vmax=vmax) if vmax == 'best' : # skymapper uses 10-90 percentiles mappable = map.healpix(obs_plot, cmap=cmap) if vmax is None : mappable = map.healpix(obs_plot, cmap=cmap, vmin=np.min(obs_plot), vmax=np.max(obs_plot)) map.colorbar(mappable, cb_label=cb_label) plt.tight_layout() if filename is not None: plt.savefig(filename, dpi=300)
import numpy as np import skymapper as skm import matplotlib.pyplot as plt from astropy.table import Table, vstack from astropy.coordinates import SkyCoord from astropy import units as u fig = plt.figure(figsize=(7, 3.5)) proj = skm.Hammer() footprint = skm.Map(skm.Hammer(), facecolor='white', ax=fig.gca()) sep = 30 footprint.grid(sep=sep) nside = 1024 des = skm.survey.DES() vertex = footprint.footprint(des, nside, facecolor='red', alpha=0.4) footprint.ax.text(0, np.deg2rad(-70), 'DES', color='red', horizontalalignment='center', verticalalignment='bottom') pixels, rap, decp, vertices = skm.healpix.getGrid(nside, return_vertices=True) # http://kids.strw.leidenuniv.nl/overview.php ra_min_list = [0, 329.5, 156, 225, 128.5] ra_max_list = [53.5, 360, 225, 238, 141.5] dec_min_list = [-35.6, -35.6, -5, -3, -2] dec_max_list = [-25.7, -25.7, +4, +4, +3] inside = np.zeros(len(pixels), dtype=bool)
dec = dec[inside] return ra, dec if __name__ == "__main__": # load RA/Dec from catalog size = 10000 des = skm.survey.DES() ra, dec = getCatalog(size, survey=des) # define the best WagnerIV projection for the footprint # minimizing the variation in distortion, aka ellipticity for crit in [skm.meanDistortion, skm.maxDistortion, skm.stdDistortion]: proj = skm.WagnerIV.optimize(ra, dec, crit) map = skm.Map(proj) map.grid() #map.labelMeridianAtParallel(-90, meridians=[]) map.footprint(des, nside=64, zorder=20, facecolor='w', alpha=0.3) a, b = proj.distortion(ra, dec) c = map.extrapolate(ra, dec, 1 - np.abs(b / a), vmin=0, vmax=0.3, resolution=72) cb = map.colorbar(c, cb_label='distortion') map.focus(ra, dec) map.title(proj.__class__.__name__ + ": " + crit.__name__)
if __name__ == "__main__": # load RA/Dec from catalog size = 100000 des = skm.survey.DES() ra, dec = getCatalog(size, survey=des) # define the best Albers projection for the footprint # minimizing the variation in distortion crit = skm.stdDistortion proj = skm.Albers.optimize(ra, dec, crit=crit) # construct map: will hold figure and projection # the outline of the sphere can be styled with kwargs for matplotlib Polygon map = skm.Map(proj) # add graticules, separated by 15 deg # the lines can be styled with kwargs for matplotlib Line2D # additional arguments for formatting the graticule labels sep = 15 map.grid(sep=sep) # # add footprint, retain the polygon for clipping # footprint = map.footprint("DES", zorder=20, edgecolor='#2222B2', facecolor='None', lw=1) # #### 1. plot density in healpix cells #### nside = 32 mappable = map.density(ra, dec, nside=nside) cb = map.colorbar(mappable, cb_label="$n$ [arcmin$^{-2}$]")