Regions
Regions can be used to spatially query datasets and collections. Regions are constructed with opencosmo.make_box() or opencosmo.make_cone().
- opencosmo.make_box(p1, p2)
Create a 3-Dimensional box region of arbitrary size. The quantities of the box region are unitless, but will be converted to the unit convention of any dataset they interact with.
- Parameters:
p1 ((float, float, float)) – 3D Point definining one corner of the box
p1 – 3D Point definining the other corner of the box
p2 (Point3d)
- Returns:
region – The constructed region
- Return type:
- Raises:
ValueError – If the region has zero length in any dimension
- opencosmo.make_cone(center, radius)
Construct a cone region used for querying lightcones. A cone region is defined by a location on the sky and an angular size, which is used as a radius.
- Parameters:
center (astropy.coordinates.SkyCord | tuple[float, float]) – The center of the cone region. If a unitless tuple is passed, the values are assumed to be in degrees.
radius (astropy.units.Quantity | float) – The radius of the region. If a unitless value is passed, it is assumed to be in degrees.
- Returns:
region – The constructed region
- Return type:
- opencosmo.make_skybox(p1, p2)
Make a box on the plane of the sky defined by two points. These points can be passed as a tuple of values or astropy sky coordinates.
- Parameters:
p1 (tuple[float, float] | SkyCoord)
p2 (tuple[float, float] | SkyCoord)
- class opencosmo.spatial.BoxRegion(center, halfwidths)
A region representing a 3-dimensional box of arbitrary length, width, and depth. A BoxRegion can be used to query snapshot data. BoxRegions can be constructed with
opencosmo.make_box()When used in a spatial query, the values defining a box region will always be interpreted in the same unit convention as the dataset it is being used to query. This means two queries on the same dataset with the same box region can return different results if the unit convention changes between them.
- Parameters:
center (Point3d)
halfwidths (BoxSize)
- property bounds
The bounds of this region in the form [(min,max) …]
- Returns:
bounds
- Return type:
list[tuple(float,float), ….]
- contains(other)
Check if this box region contains another region or set of points. Points should be passed in as a numpy array with shape (3, n_points). Note that this method requires that the bounds of the test region be fully inside the other region. Functionally this means that a region does not contain itself.
- Parameters:
other (BoxRegion | np.ndarray) – The region or points to check
- Returns:
contained – Whether the region or points are contained in the region
- Return type:
bool or np.ndarray[bool]
- Raises:
ValueError – If the input not a region or points
- intersects(other)
Check if this BoxRegion intersects another BoxRegion. This function returns true of the regions intersect in any way, including if one contains the other. Regions that share a bound but do not cross will return False.
- Parameters:
other (BoxRegion) – The region to check
- Returns:
intersects – Whether the regions intersect
- Return type:
bool
- Raises:
ValueError: – If the input is not a BoxRegion
- class opencosmo.spatial.ConeRegion(center, radius)
Cone region for querying lightcones. Defined by RA/Dec coordinate and an angular size. Should always be constructed with
opencosmo.make_cone()Note that the underlying coordinate representation of the data may or may not be in RA and Dec. Spatial queries handle all the necessary conversions, but this may mean that the coordinates in the query output do not appear to match the coordinates of the region used to perform the query.
- Parameters:
center (SkyCoord)
radius (u.Quantity)
- property center
The center of this region.
- Returns:
coordinate
- Return type:
astropy.coordinates.SkyCoord
- property radius
The angular radius of the region.
- Returns:
radius
- Return type:
astropy.units.Quantity
- contains(other)
Check if this ConeRegion contains another ConeRegion or a sky coordinate. A region does not contain itself — the test object must be strictly interior.
- Parameters:
other (ConeRegion | astropy.coordinates.SkyCoord)
- intersects(other)
Check if this ConeRegion intersects with another cone region. Regions which touch at a single point but do not cross will return False.
- Parameters:
other (
opencosmo.spatial.ConeRegion) – The other region to query.- Returns:
intersects – Whether the two regions intersect
- Return type:
bool