Create a MOC from a filtered astropy TableΒΆ

[1]:
import astropy.units as u
from astropy.visualization.wcsaxes.frame import EllipticalFrame
from astroquery.vizier import Vizier
from mocpy import MOC
[2]:
viz = Vizier(columns=["*", "_RAJ2000", "_DEJ2000"])
viz.ROW_LIMIT = -1
table = viz.get_catalogs("I/293/npm2cros")[0]
[3]:
galex = MOC.from_fits("../resources/P-GALEXGR6-AIS-FUV.fits")
WARNING: Wrong depth_max 29. Reset to 13
[4]:
def plot(moc, title=""):
    """Create a plot of a MOC."""
    import matplotlib.pyplot as plt

    fig = plt.figure(figsize=(15, 10))

    from astropy.wcs import WCS

    wcs = WCS(naxis=2)
    wcs.wcs.ctype = ["GLON-AIT", "GLAT-AIT"]
    wcs.wcs.crval = [110.0, 0.0]
    wcs.wcs.cdelt = [-0.675, 0.675]
    wcs.wcs.crpix = [240.5, 120.5]

    ax = fig.add_subplot(1, 1, 1, projection=wcs, frame_class=EllipticalFrame)

    moc.fill(
        ax=ax,
        wcs=wcs,
        edgecolor="r",
        facecolor="r",
        linewidth=1.0,
        fill=True,
        alpha=0.5,
    )
    moc.border(ax=ax, wcs=wcs, color="black", alpha=0.5)

    ax.set_aspect(1.0)

    plt.xlabel("ra")
    plt.ylabel("dec")
    if title:
        plt.title(title)
    plt.grid(color="black", linestyle="dotted")
    plt.show()
    plt.close()


plot(moc=galex, title="P-GALEXGR6-AIS-FUV")
../../_images/_collections_notebooks_filtering_astropy_table_4_0.png
[5]:
table
[5]:
Table length=46887
_RAJ2000_DEJ2000NPM2KLARAJ2000DEJ2000IDIQINr_Starmagtyc
degdegmag
float64float64str8str3str10str9uint8uint8uint8int16float32str1
339.63833383.166667+83.0016HPM22 38 33.2+83 10 0010081114.20
339.63833383.166667+83.0016HPM22 38 33.2+83 10 0010081314.20
349.53083383.010556+83.0022VAR23 18 07.4+83 00 38000843--T
349.53083383.010556+83.0022SRA23 18 07.4+83 00 3800019.60T
323.85416782.997222+82.0030UBV21 35 25.0+82 59 50000510.08T
332.10791782.747500+82.0055WD22 08 25.9+82 44 51000101216.00
332.93375082.607778+82.0059HPM22 11 44.1+82 36 2810081116.70
335.08875082.970833+82.0065HPM22 20 21.3+82 58 1510081111.00T
337.11916782.763889+82.0074UBV22 28 28.6+82 45 50000510.42T
....................................
257.227500-23.094167-23.0151ELS17 08 54.6-23 05 3900051113.50
267.989583-23.012222-23.0162CMC17 51 57.5-23 00 4410081711.13T
267.989583-23.012222-23.0162ELS17 51 57.5-23 00 44100252--T
270.244583-23.032222-23.0164CMC18 00 58.7-23 01 5610081710.52T
270.244583-23.032222-23.0164EA18 00 58.7-23 01 56000110.20T
270.337500-23.000556-23.0165COM18 01 21.0-23 00 0200081911.20T
270.442917-23.020000-23.0166UNK18 01 46.3-23 01 1210081614.00
270.474167-23.028889-23.0167COM18 01 53.8-23 01 4401081911.60T
271.357083-23.005556-23.0168ELS18 05 25.7-23 00 20000252--T
271.357083-23.005556-23.0168OB18 05 25.7-23 00 200003939.70T
[6]:
indexes = galex.contains_lonlat(
    table["_RAJ2000"].T * u.deg,
    table["_DEJ2000"].T * u.deg,
)
filtered_table = table[indexes]
filtered_table
[6]:
Table length=10714
_RAJ2000_DEJ2000NPM2KLARAJ2000DEJ2000IDIQINr_Starmagtyc
degdegmag
float64float64str8str3str10str9uint8uint8uint8int16float32str1
339.63833383.166667+83.0016HPM22 38 33.2+83 10 0010081114.20
339.63833383.166667+83.0016HPM22 38 33.2+83 10 0010081314.20
349.53083383.010556+83.0022VAR23 18 07.4+83 00 38000843--T
349.53083383.010556+83.0022SRA23 18 07.4+83 00 3800019.60T
323.85416782.997222+82.0030UBV21 35 25.0+82 59 50000510.08T
335.08875082.970833+82.0065HPM22 20 21.3+82 58 1510081111.00T
337.11916782.763889+82.0074UBV22 28 28.6+82 45 50000510.42T
337.27458382.662222+82.0075HPM22 29 05.9+82 39 4411081117.40
338.33791782.369167+82.0079HPM22 33 21.1+82 22 0910081116.20
....................................
292.318750-22.677778-22.2070ELS19 29 16.5-22 40 4000052013.50
292.665000-22.236667-22.2079CMC19 30 39.6-22 14 1210081712.57
292.892917-22.538056-22.2084CMC19 31 34.3-22 32 1710081711.12T
293.529583-22.156389-22.2101CMC19 34 07.1-22 09 2311081712.69
293.727083-22.121667-22.2108CMC19 34 54.5-22 07 1810081713.35
294.078333-22.048333-22.2118CMC19 36 18.8-22 02 5410081712.63
294.845417-22.401667-22.2128CMC19 39 22.9-22 24 0610081712.32
295.010833-22.548333-22.2133HPM19 40 02.6-22 32 5410081114.10
297.006250-22.252500-22.2166CMC19 48 01.5-22 15 0910081710.95T
297.245417-22.472778-22.2169HPM19 48 58.9-22 28 2212081115.60
[7]:
m1 = MOC.from_lonlat(
    table["_RAJ2000"].T * u.deg,
    table["_DEJ2000"].T * u.deg,
    max_norder=6,
)
m2 = MOC.from_lonlat(
    filtered_table["_RAJ2000"].T * u.deg,
    filtered_table["_DEJ2000"].T * u.deg,
    max_norder=6,
)
plot(moc=m1, title="MOC from table")
plot(moc=m2, title="MOC from filtered table")
../../_images/_collections_notebooks_filtering_astropy_table_7_0.png
../../_images/_collections_notebooks_filtering_astropy_table_7_1.png