Fast region handling for catalogue data.
Project description
regionx
A high-performance Python library for astronomical region operations, powered by Rust. regionx provides fast spherical geometry calculations for identifying sources within regions on the celestial sphere.
Features
- Fast spherical geometry operations - Rust-powered performance for large astronomical catalogs
- Simple Python interface - Easy-to-use classes for common astronomical regions
- Batch operations - Efficiently check multiple points at once
- Three region types:
Polygon- Arbitrary spherical polygons defined by verticesAperture- Circular regions on the skyAnulus- Annular (ring-shaped) regions
Installation
pip install regionx
Or build from source:
git clone https://github.com/yourusername/regionx.git
cd regionx
pip install maturin
maturin develop --release
Usage
Polygon
Create spherical polygons and check if sky coordinates fall within them.
from regionx import Polygon
# Define a polygon with RA/Dec vertices (in degrees)
ra_vertices = [10.0, 15.0, 15.0, 10.0]
dec_vertices = [20.0, 20.0, 25.0, 25.0]
polygon = Polygon(ra_vertices, dec_vertices)
# Check a single point
is_inside = polygon.is_inside(ra_point=12.5, dec_point=22.5)
print(f"Point is inside: {is_inside}")
# Check multiple points at once (much faster for large catalogs)
ra_points = [12.0, 16.0, 11.0, 14.0]
dec_points = [22.0, 22.0, 24.0, 21.0]
results = polygon.check_points(ra_points, dec_points)
print(f"Results: {results}") # [True, False, True, True]
Aperture
Create circular apertures for source identification.
from regionx import Aperture
# Create a circular aperture centered at RA=180°, Dec=45° with 2° radius
aperture = Aperture(ra_center=180.0, dec_center=45.0, radius_deg=2.0)
# Check single point
is_inside = aperture.is_inside(ra_point=181.0, dec_point=45.5)
# Check multiple points
ra_catalog = [180.5, 179.5, 185.0, 180.0]
dec_catalog = [45.2, 44.8, 45.0, 46.5]
mask = aperture.check_points(ra_catalog, dec_catalog)
Anulus
Create annular (ring-shaped) regions for background estimation or source selection.
from regionx import Anulus
# Create an annulus with inner radius 1° and outer radius 3°
anulus = Anulus(
ra_center=150.0,
dec_center=-30.0,
inner_radius=1.0,
outer_radius=3.0
)
# Check single point
is_inside = anulus.is_inside(ra_point=151.5, dec_point=-30.5)
# Check multiple points
ra_points = [150.5, 150.1, 152.5, 154.0]
dec_points = [-30.2, -30.0, -29.5, -30.0]
mask = anulus.check_points(ra_points, dec_points)
Working with Astronomical Catalogs
Here's a complete example using numpy arrays and astronomical data:
import numpy as np
from regionx import Aperture
# Load your catalog (example with random data)
catalog_ra = np.random.uniform(0, 360, 100000)
catalog_dec = np.random.uniform(-90, 90, 100000)
# Define a search region
search_region = Aperture(ra_center=180.0, dec_center=0.0, radius_deg=5.0)
# Find all sources in the region
inside_mask = search_region.check_points(
catalog_ra.tolist(),
catalog_dec.tolist()
)
# Filter your catalog
sources_in_region = np.array(inside_mask)
filtered_ra = catalog_ra[sources_in_region]
filtered_dec = catalog_dec[sources_in_region]
print(f"Found {np.sum(sources_in_region)} sources in the region")
API Reference
Polygon
Constructor:
Polygon(ra_vertices: List[float], dec_vertices: List[float])ra_vertices: Right ascension coordinates of polygon vertices (degrees)dec_vertices: Declination coordinates of polygon vertices (degrees)
Methods:
is_inside(ra_point: float, dec_point: float) -> boolcheck_points(ra_points: List[float], dec_points: List[float]) -> List[bool]
Aperture
Constructor:
Aperture(ra_center: float, dec_center: float, radius_deg: float)ra_center: Right ascension of aperture center (degrees)dec_center: Declination of aperture center (degrees)radius_deg: Aperture radius (degrees)
Methods:
is_inside(ra_point: float, dec_point: float) -> boolcheck_points(ra_points: List[float], dec_points: List[float]) -> List[bool]
Anulus
Constructor:
Anulus(ra_center: float, dec_center: float, inner_radius: float, outer_radius: float)ra_center: Right ascension of center (degrees)dec_center: Declination of center (degrees)inner_radius: Inner radius (degrees)outer_radius: Outer radius (degrees)
Methods:
is_inside(ra_point: float, dec_point: float) -> boolcheck_points(ra_points: List[float], dec_points: List[float]) -> List[bool]
Coordinate System
All coordinates are in degrees:
- RA (Right Ascension): 0° to 360°
- Dec (Declination): -90° to +90°
The library correctly handles spherical geometry, including regions that cross the RA=0°/360° boundary and poles.
Performance Tips
- Use batch operations:
check_points()is much faster than callingis_inside()repeatedly - Convert numpy arrays to lists:
ra_array.tolist()before passing tocheck_points() - Reuse region objects: Create the region once and reuse it for multiple queries
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgments
Built on top of the astroxide Rust library for spherical geometry calculations.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file regionx-0.2.0.tar.gz.
File metadata
- Download URL: regionx-0.2.0.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a0a5ab42d7d93daa182040e61e509f9252957feb46a3e272aac206c8dbab4f2
|
|
| MD5 |
32464e6b49dc5ee58f62259ed6085303
|
|
| BLAKE2b-256 |
fcce9029b7b9fc14dd5bbc65f00c13175f9c046bae20cfd24b3b6bea84e27818
|
File details
Details for the file regionx-0.2.0-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: regionx-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 261.2 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41e7d50198ca7efe2fa0e2263654b98a6c619a7e493f406bce6017af26f8b533
|
|
| MD5 |
9414d042d0c1327d99b1d795fbd7a29d
|
|
| BLAKE2b-256 |
964ec5350812cfe4a6f6ff40fd2ee42d647c3b9a6e325c8728fcadcf72acb99a
|
File details
Details for the file regionx-0.2.0-cp313-cp313-macosx_10_12_x86_64.whl.
File metadata
- Download URL: regionx-0.2.0-cp313-cp313-macosx_10_12_x86_64.whl
- Upload date:
- Size: 263.5 kB
- Tags: CPython 3.13, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8eaa909599b251d1eb5ffd1c4b98448eff74a8540606cd42e7dff7854e48f18
|
|
| MD5 |
ae398837633c474de0412aa3fde75d2c
|
|
| BLAKE2b-256 |
afcf824af9542469cc4f4015c83af52a5cea737747777fdb05ed8201a7697538
|
File details
Details for the file regionx-0.2.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: regionx-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 261.0 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6dae8ce4b08896a2c473a17adb0ef2f218f935db6dedcc2fcead097c27989d55
|
|
| MD5 |
68dbe3fb9561676f8b6837a5002d3b71
|
|
| BLAKE2b-256 |
96c2e77d6d514d20b42761c4d878f98f3e9b23604cb601446acce56767c589ab
|
File details
Details for the file regionx-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl.
File metadata
- Download URL: regionx-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl
- Upload date:
- Size: 263.5 kB
- Tags: CPython 3.12, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff10822db83c84a6132b358e40db0e684b884454cf4ef242a863d1f230b1a4b4
|
|
| MD5 |
2ec780416c9c26b249411744f6190fed
|
|
| BLAKE2b-256 |
43eb3cb00f7a2bfdfc4c1d41d338e0f56db381fe45954da1b7d7a342e77bdb73
|
File details
Details for the file regionx-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: regionx-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 301.0 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4855566b536dd7099833df127cb603d2757efc3b284ae4e5841d4b0848ddba36
|
|
| MD5 |
e9a708719cfde9fed49b00a42cd1c9f2
|
|
| BLAKE2b-256 |
f70ae41bb185ad62e7250d5fc7e45e74c18b0a3e0b92ae576637d4fce0fe82bd
|