def from_polygon(cls, lon, lat, max_depth=10): """ Creates a MOC from a polygon The polygon is given as lon and lat `astropy.units.Quantity` that define the vertices of the polygon. Concave, convex and self-intersecting polygons are accepted. Parameters ---------- lon : `astropy.units.Quantity` The longitudes defining the polygon. Can describe convex and concave polygons but not self-intersecting ones. lat : `astropy.units.Quantity` The latitudes defining the polygon. Can describe convex and concave polygons but not self-intersecting ones. max_depth : int, optional The resolution of the MOC. Set to 10 by default. Returns ------- result : `~mocpy.moc.MOC` The resulting MOC """ pix, depth, fully_covered_flags = cdshealpix.polygon_search(lon, lat, max_depth) return MOC.from_healpix_cells(pix, depth, fully_covered_flags)
from cdshealpix import polygon_search import astropy.units as u import numpy as np lon = [20, -20, -20, 20] * u.deg lat = [20, 20, -20, -20] * u.deg depth = 7 ipix, depth, fully_covered = polygon_search(lon, lat, depth) from mocpy import MOC, WCS from astropy.coordinates import SkyCoord, Angle moc = MOC.from_healpix_cells(ipix, depth, fully_covered) # Plot the MOC using matplotlib import matplotlib.pyplot as plt fig = plt.figure(111, figsize=(10, 10)) # Define a astropy WCS easily with WCS(fig, fov=100 * u.deg, center=SkyCoord(0, 0, unit='deg', frame='icrs'), coordsys="icrs", rotation=Angle(0, u.degree), projection="AIT") as wcs: ax = fig.add_subplot(1, 1, 1, projection=wcs) # Call fill with a matplotlib axe and the `~astropy.wcs.WCS` wcs object. moc.fill(ax=ax, wcs=wcs, alpha=0.5, fill=True, color="green") # Draw the perimeter of the MOC in black moc.border(ax=ax, wcs=wcs, alpha=0.5, color="black") plt.xlabel('ra') plt.ylabel('dec')