Bounding Regions for On-Sky Spatial Searches¶
The SphericalSkyRegion classes also provide
bounding_circle and
bounding_lonlat properties,
yielding the spherical circle and longitude and latitude ranges
enclosing the region, respectively.
This bounding information can be helpful when querying databases to select objects with tools such as Astroquery or PyVO’s TAP service.
For many regions of interest, the spherical region properties can directly provide the query search boundary (e.g., the center and radius for a circle for a cone search, or the vertices for a polygon region search). However, this depends on what query shapes are supported by the database.
When a particular region shape is not supported by a
database, these bounding properties can be used to define a
“padded” search, and the results can then be downselected to only
those within the region using the contains().
(In particular, the bounding properties may be helpful when a coordinate frame transformation is necessary to match the database coordinate system; see Coordinate Frame Transformation of Spherical Regions.)
As an example, let’s create two spherical regions, a circle and range, and determine their bounding longitude/latitude spans and circle:
>>> from astropy.coordinates import SkyCoord
>>> from astropy import units as u
>>> from regions import CircleSphericalSkyRegion, RangeSphericalSkyRegion
>>> sph_circ = CircleSphericalSkyRegion(SkyCoord(100,-40,unit=u.deg,
... frame="galactic"),
... 30*u.deg)
>>> print(sph_circ.bounding_lonlat)
(<Longitude [ 59.25424338, 140.74575662] deg>, <Latitude [-70., -10.] deg>)
>>> sph_range = RangeSphericalSkyRegion(frame="galactic",
... longitude_range=[-45,45]*u.deg,
... latitude_range=[0,45]*u.deg)
>>> print(sph_range.bounding_circle)
Region: CircleSphericalSkyRegion
center: <SkyCoord (Galactic): (l, b) in deg
(0., 16.32494994)>
radius: 47.2657903991002 deg
(The bounding circle of a circle is always itself, and in the original coordinate frame, the bounding longitude/latitude of a spherical range is equivalent to the region.)
Let’s now transform these regions into the ICRS frame, and obtain the new bounds, including the new frame longitude/latitude bounds on the transformed Range region:
>>> sph_circ_transf = sph_circ.transform_to("icrs")
>>> print(sph_circ_transf.bounding_lonlat)
(<Longitude [322.34509896, 26.43985125] deg>, <Latitude [-10.44033547, 49.55966453] deg>)
>>> sph_range_transf = sph_range.transform_to("icrs")
>>> print(sph_range_transf.bounding_lonlat)
(<Longitude [201.75437889, 288.42757587] deg>, <Latitude [-60.49575721, 27.00079109] deg>)
>>> print(sph_range_transf.bounding_circle)
Region: CircleSphericalSkyRegion
center: <SkyCoord (ICRS): (ra, dec) in deg
(251.64674219, -19.64298539)>
radius: 47.26579039910021 deg
These bounding circles and longitude/latitude are visualized below for both the original and transformed coordinate frames.
(Source code, png, hires.png, pdf, svg)