In [1]:
import numpy as np
import astropy.units as u
from astropy.coordinates import SkyCoord
from mocpy import MOC
Let's start by loading a local MOC and plotting it
In [2]:
%time m1 = MOC.from_fits('../resources/P-SDSS9-r.fits')
Now, we load MOC for GALEX GR6 AIS FUV:
In [3]:
%time m2 = MOC.from_fits('../resources/P-GALEXGR6-AIS-FUV.fits')
In [4]:
import matplotlib.pyplot as plt
fig = plt.figure(111, figsize=(15, 15))
from mocpy import World2ScreenMPL
from astropy.coordinates import Angle
with World2ScreenMPL(fig,
fov=200 * u.deg,
center=SkyCoord(0, 20, unit='deg', frame='icrs'),
coordsys="icrs",
rotation=Angle(0, u.degree),
projection="AIT") as wcs:
ax = fig.add_subplot(1, 1, 1, projection=wcs)
%time m1.fill(ax=ax, wcs=wcs, alpha=0.5, fill=True, color="green")
%time m2.fill(ax=ax, wcs=wcs, alpha=0.5, fill=True, color="dodgerblue")
plt.xlabel('ra')
plt.ylabel('dec')
plt.grid(color="black", linestyle="dotted")
We can compute the intersection between the 2 MOC:
In [5]:
m_intersect = m1.intersection(m2)
import matplotlib.pyplot as plt
fig = plt.figure(111, figsize=(15, 15))
from mocpy import World2ScreenMPL
from astropy.coordinates import Angle
with World2ScreenMPL(fig,
fov=250 * u.deg,
center=SkyCoord(20, 15, unit='deg', frame='icrs'),
coordsys="icrs",
rotation=Angle(0, u.degree),
projection="AIT") as wcs:
ax = fig.add_subplot(1, 1, 1, projection=wcs)
%time m_intersect.fill(ax=ax, wcs=wcs, alpha=0.5, fill=True, color="green")
%time m_intersect.border(ax=ax, wcs=wcs, alpha=0.5, fill=True, color="black")
plt.xlabel('ra')
plt.ylabel('dec')
plt.grid(color="black", linestyle="dotted")
And serialize it to FITS (official serialization):
In [6]:
%time hdulist = m_intersect.serialize(format='fits')
MOC can also be serialized in JSON:
m_intersect.write(format='json')
Or write it directly to a FITS/JSON file:
m_intersect.write(path=<filename>, write_to_file=True, format='json'/'fits')