Skip to main content

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 vertices
    • Aperture - Circular regions on the sky
    • Anulus - 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) -> bool
  • check_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) -> bool
  • check_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) -> bool
  • check_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

  1. Use batch operations: check_points() is much faster than calling is_inside() repeatedly
  2. Convert numpy arrays to lists: ra_array.tolist() before passing to check_points()
  3. 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.

Metadata

Release files for regionx 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for regionx 0.2.0
File Size Uploaded Provenance Actions
regionx-0.2.0.tar.gz 16.7 kB Without provenance Details for regionx-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for regionx 0.2.0
File Actions
regionx-0.2.0-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for regionx-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
regionx-0.2.0-cp313-cp313-macosx_10_12_x86_64.whl CPython 3.13 CPython 3.13 macOS 10.12+ x86-64 Details for regionx-0.2.0-cp313-cp313-macosx_10_12_x86_64.whl
regionx-0.2.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for regionx-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
regionx-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.12+ x86-64 Details for regionx-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl
regionx-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details for regionx-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Total release size: 1.4 MB

Release files / regionx-0.2.0.tar.gz

Download URL regionx-0.2.0.tar.gz
Size 16.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2a0a5ab42d7d93daa182040e61e509f9252957feb46a3e272aac206c8dbab4f2
BLAKE2b-256 checksum
How to use checksums
fcce9029b7b9fc14dd5bbc65f00c13175f9c046bae20cfd24b3b6bea84e27818
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / regionx-0.2.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL regionx-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Size 261.2 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
41e7d50198ca7efe2fa0e2263654b98a6c619a7e493f406bce6017af26f8b533
BLAKE2b-256 checksum
How to use checksums
964ec5350812cfe4a6f6ff40fd2ee42d647c3b9a6e325c8728fcadcf72acb99a
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / regionx-0.2.0-cp313-cp313-macosx_10_12_x86_64.whl

Download URL regionx-0.2.0-cp313-cp313-macosx_10_12_x86_64.whl
Size 263.5 kB
Tags CPython 3.13 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
e8eaa909599b251d1eb5ffd1c4b98448eff74a8540606cd42e7dff7854e48f18
BLAKE2b-256 checksum
How to use checksums
afcf824af9542469cc4f4015c83af52a5cea737747777fdb05ed8201a7697538
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / regionx-0.2.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL regionx-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Size 261.0 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6dae8ce4b08896a2c473a17adb0ef2f218f935db6dedcc2fcead097c27989d55
BLAKE2b-256 checksum
How to use checksums
96c2e77d6d514d20b42761c4d878f98f3e9b23604cb601446acce56767c589ab
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / regionx-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl

Download URL regionx-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl
Size 263.5 kB
Tags CPython 3.12 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
ff10822db83c84a6132b358e40db0e684b884454cf4ef242a863d1f230b1a4b4
BLAKE2b-256 checksum
How to use checksums
43eb3cb00f7a2bfdfc4c1d41d338e0f56db381fe45954da1b7d7a342e77bdb73
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / regionx-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL regionx-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 301.0 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
4855566b536dd7099833df127cb603d2757efc3b284ae4e5841d4b0848ddba36
BLAKE2b-256 checksum
How to use checksums
f70ae41bb185ad62e7250d5fc7e45e74c18b0a3e0b92ae576637d4fce0fe82bd
Upload date
Uploaded using Trusted Publishing?
What is 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}

Security for regionx 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

6 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page