Chandra X-Ray Observatory
	(CXC)
Skip to the navigation links
Last modified: December 2015

URL: http://cxc.harvard.edu/ciao/ahelp/reginsideregion.html
AHELP for CIAO 4.9

regInsideRegion

Context: region

Synopsis

Is a point (or set of points) inside a region?

Syntax

regInsideRegion(region, x, y)

The return value is a scalar if x and y are scalars or a numpy array if
x and y are numpy arrays.

Description

The regInsideRegion routine queries a region to find out if a point (or an array of points) is inside the region or not. 1 is returned for yes, and 0 if no. The input values are a CIAO region variable (as returned from regParse), and the positions to query which can be either be a single X, Y position or two arrays of positions.

The region module is not available by default; see "ahelp region" for information on loading the module.

Example 1

>>> from region import *
>>> reg = regParse("circle(10,10,4)")
>>> flag = regInsideRegion(reg, 12, 11)
>>> print(flag)
1

Here we use the regInsideRegion() routine to find out whether the point at (12,11) is inside the circle centered at (10,10) with a radius of 4 pixels; if the routinr returns 1 then it is, otherwise it returns 0.

Example 2

>>> import numpy as np
>>> xc = np.array([10, 16, 12])
>>> yc = np.array([11, -4, 8])
>>> flags = regInsideRegion(reg, xc, yc)
>>> print(flags)
[1 0 1]
>>> i = np.where(flags == 1)
>>> xx = xc[i]
>>> yy = yc[i]
>>> print(zip(xx, yy))
[(10, 11), (12, 8)]

Here we have found that the points (10,11) and (12,8) are inside the region, but that (16,-4) is not. The where() routine is then used to show how you can extract from the arrays only those points that lie inside the region. If the where() function had been written

where( flag == 0 )

then it would have selected those points that lie outside the region.

Changes in CIAO 4.8

The region library (C version) was re-written in CIAO 4.8, so that some routines may give different answers, in particular when handling self-intersecting (non-simple) polygons.

Bugs

See the bugs page for the region library on the CIAO website for an up-to-date listing of known bugs.

Refer to the CIAO bug pages for an up-to-date listing of known issues.

See Also

region
regarea, regextent, reginsideregion, region, regparse, regprintregion, regregionstring

Last modified: December 2015
Smithsonian Institute Smithsonian Institute

The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory. 60 Garden Street, Cambridge, MA 02138 USA.   Email:   cxchelp@head.cfa.harvard.edu Smithsonian Institution, Copyright © 1998-2017. All rights reserved.