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')


CPU times: user 58.6 ms, sys: 8.9 ms, total: 67.5 ms
Wall time: 63.1 ms

Now, we load MOC for GALEX GR6 AIS FUV:


In [3]:
%time m2 = MOC.from_fits('../resources/P-GALEXGR6-AIS-FUV.fits')


CPU times: user 11.1 ms, sys: 1.1 ms, total: 12.2 ms
Wall time: 12.3 ms

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")


CPU times: user 71.7 ms, sys: 947 µs, total: 72.6 ms
Wall time: 66.8 ms
CPU times: user 192 ms, sys: 17.8 ms, total: 210 ms
Wall time: 200 ms

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")


CPU times: user 53.6 ms, sys: 0 ns, total: 53.6 ms
Wall time: 48.7 ms
CPU times: user 70.3 ms, sys: 0 ns, total: 70.3 ms
Wall time: 67.1 ms

And serialize it to FITS (official serialization):


In [6]:
%time hdulist = m_intersect.serialize(format='fits')


CPU times: user 13.9 ms, sys: 3.49 ms, total: 17.4 ms
Wall time: 16.8 ms

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')