# Checking for points inside regions¶

Let’s continue with sky and pixel regions defined in the Getting started section:

>>> from astropy.coordinates import Angle, SkyCoord
>>> from regions import CircleSkyRegion, PixCoord, CirclePixelRegion

>>> sky_center = SkyCoord(42, 43, unit='deg')
>>> pixel_center = PixCoord(x=42, y=43)

>>> print(sky_region)
Region: CircleSkyRegion
center: <SkyCoord (ICRS): (ra, dec) in deg
(42., 43.)>
>>> print(pixel_region)
Region: CirclePixelRegion
center: PixCoord(x=42, y=43)


To test if a given point is inside or outside the regions, the Python in operator can be called, which calls the special __contains__ method defined on the region classes:

>>> from regions import PixCoord
>>> PixCoord(55, 40) in pixel_region
True
>>> PixCoord(55, 200) in pixel_region
False


The in operator only works for scalar coordinates, because Python requires the return value to be a scalar bool, and only works for pixel regions. If you try to use in for non-scalar coordinates, you’ll get a ValueError:

>>> pixcoord = PixCoord([50, 50], [10, 60])
>>> pixcoord in pixel_region
Traceback (most recent call last):
...
ValueError: coord must be scalar. coord=PixCoord(x=[50 50], y=[10 60])


If you have arrays of coordinates, use the regions.SkyRegion.contains or regions.PixelRegion.contains methods:

>>> pixcoords = PixCoord.from_sky(sky_center, wcs)
>>> pixel_region.contains(pixcoords)
True


Note that regions.SkyRegion.contains requires a WCS to be passed:

>>> skycoord = SkyCoord([50, 50], [10, 60], unit='deg')
>>> sky_region.contains(skycoord, wcs)
array([False, True])