def make_image_of_MOC(fits_bytes): """make_image_of_MOC. Args: fits_bytes: """ inbuf = io.BytesIO(fits_bytes) moc = MOC.from_fits(inbuf) notmoc = moc.complement() fig = plt.figure(111, figsize=(10, 5)) with World2ScreenMPL(fig, fov=360 * u.deg, projection="AIT") as wcs: ax = fig.add_subplot(1, 1, 1, projection=wcs) notmoc.fill(ax=ax, wcs=wcs, alpha=1.0, fill=True, color="lightgray", linewidth=None) moc.fill (ax=ax, wcs=wcs, alpha=1.0, fill=True, color="red", linewidth=None) moc.border(ax=ax, wcs=wcs, alpha=1, color="red") plt.grid(color="black", linestyle="dotted") outbuf = io.BytesIO() plt.savefig(outbuf, format='png', bbox_inches='tight', dpi=200) bytes = outbuf.getvalue() outbuf.close() return bytes
import astropy.units as u ipix, depth, fully_covered = cone_search(lon=Longitude(0, u.deg), lat=Latitude(0, u.deg), radius=10 * u.deg, depth=10) from mocpy import MOC, World2ScreenMPL 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 from the mocpy.WCS class with World2ScreenMPL(fig, fov=30 * 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') plt.title('Cone search') plt.grid(color="black", linestyle="dotted") plt.show()
from matplotlib.path import Path from matplotlib.patches import PathPatch import astropy.units as u moc = MOC.from_fits('polygon_moc.fits') skycoords = moc.get_boundaries() # Plot the MOC using matplotlib import matplotlib.pyplot as plt fig = plt.figure(111, figsize=(10, 10)) # Define a astropy WCS easily with World2ScreenMPL( fig, fov=20 * u.deg, center=SkyCoord(10, 5, unit='deg', frame='icrs'), coordsys="icrs", rotation=Angle(0, u.degree), # The gnomonic projection transforms great circles into straight lines. projection="TAN") 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="red", linewidth=1) moc.border(ax=ax, wcs=wcs, alpha=1, color="red") # Plot the border from astropy.wcs.utils import skycoord_to_pixel x, y = skycoord_to_pixel(skycoords[0], wcs) p = Path(np.vstack((x, y)).T) patch = PathPatch(p, color="black", fill=False, alpha=0.75, lw=2) ax.add_patch(patch)