Skip to main content

Rust-backed aperture overlap and summation utilities

Project description

astroapers

(Astronomy + Apertures + Rust(rs) = astroapers)

astroapers aperture logo

astroapers is a Rust-backed Python package for exact pixel-aperture overlap, bbox-tight aperture weights, and aperture summation in pixel coordinates. Although it was developed for astronomical image analysis, the core algorithms operate on generic two-dimensional image arrays. They can also be useful for other scientific and technical images, including microscopy, photography, and any workflow that needs reproducible measurements over pixel-defined apertures or regions.

The package exposes three public layers:

  • PixelAp objects such as CircAp, EllipAp, RectAp, PillAp, WedgeAp, and *An for readable workflows, plotting, weights, and one-shot aperture sums.
  • bboxes(), weights_exact(), and BoundingBox methods for reusing bbox-tight aperture weights.
  • import astroapers._rust as aapr for expert users who need the raw extension functions within python and are willing to supply contiguous arrays and handle raw return values. (For how-tos for aapr, inspect astroapers.kernels; it is the Python layer that calls _rust internally).

Project links:

Install

astroapers builds a native Rust extension with maturin, so source installs require a working Rust/Cargo toolchain.

# You may activate your Python environment before this, e.g.,
# source ~/.venvs/your_env/bin/activate

# General install:
uv pip install -e .

# development install:
uv pip install -e ".[dev]"

Then try tests:

uv run pytest -q

For Rust crate use:

[dependencies]
astroapers = "0.1"

Quickstart

import astroapers as aap

ap = aap.CircAp((42.3, 17.2), r=3.0)
apsum, npix = ap.apsum_exact(data, mask=bad_pixels)  # return_npix=True by default
weights = ap.weights_exact()[0]
center_weights = ap.weights_center()[0]
bbox = ap.bboxes()[0]
center_samples = ap.sampled_values(data)[0]
weighted_values = ap.weighted_values(data)[0]
fits_section = bbox.to_fits_section(data.shape)

wedge = aap.WedgeAp((42.3, 17.2), r_in=5.0, r_out=50.0, theta_in=0.0, dtheta_in=0.2)
wedge_sum, wedge_npix = wedge.apsum_exact(data)

For maximum-performance:

import astroapers._rust as aapr

x = np.ascontiguousarray(x, dtype=np.float64)
y = np.ascontiguousarray(y, dtype=np.float64)
data = np.ascontiguousarray(data, dtype=np.float64)

apsum = aapr.apsum_circ_exact_sum(data, x, y, 3.0)

Dtype caveats

astroapers performs geometry and public aperture-sum outputs in float64. The raw _rust functions do not provide validation, mask handling, dtype conversion, or return shaping. Use contiguous arrays with the dtype-specific raw function (*_f32, *_i32, *_i16) when not using float64. Coordinate inputs and scalar geometry parameters are expected to be float64-compatible.

Bbox-tight weights from PixelAp.weights_exact() are float64. When user-supplied weights are passed to BoundingBox methods, only float32 and float64 arrays are preserved. Other numeric or boolean weight arrays, including extended precision dtypes such as float128/longdouble where NumPy provides them, are converted to float64. BoundingBox.to_image(), weighted_cutout(), and weighted_values() preserve float32 when both data and weights are float32, but BoundingBox.apsum() and BoundingBox.npix() always accumulate in float64. Bad-pixel masks passed as mask= are converted to boolean, where True means excluded.

weights_center() and sampled_values(data) are related but not synonyms: weights_center() returns bbox-tight binary weights, while sampled_values(data) returns the raw image values selected by the positive center weights.

Documentation

The documentation is hosted at https://ysbach.github.io/astroapers/ and built from the Quarto site in docs/quarto. The hosted docs contain:

  • autogenerated API reference pages from Python docstrings;
  • generated Rust API reference from rustdoc;
  • tutorial .qmd files for common aperture-sum, mask, background, vector, and raw-Rust performance workflows.

Local docs build:

uv pip install -e ".[docs]"
make docs-build

Release Checks

Before publishing both distributions, verify the Python package and Rust crate from the same source tree:

cargo test --no-default-features
cargo check --features extension-module
cargo package --allow-dirty
uv run pytest -q
uv build

Publish the Cargo crate with cargo publish, then publish the Python artifacts from dist/ with uv publish after confirming the versions match in Cargo.toml and pyproject.toml.

Conventions

Coordinates follow the SEP/Photutils pixel convention: pixel (x, y) is centered at integer coordinates and covers [x - 0.5, x + 0.5].

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

astroapers-0.1.2.tar.gz (66.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

astroapers-0.1.2-cp313-cp313-macosx_11_0_arm64.whl (606.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

Details for the file astroapers-0.1.2.tar.gz.

File metadata

  • Download URL: astroapers-0.1.2.tar.gz
  • Upload date:
  • Size: 66.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for astroapers-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ea1da390a6e9fec1e98b8e34f319e5c0d4ebf11c7ff3a44ace81b8d57fc55f83
MD5 51c4568537e517cb01b26f0d15bbd24d
BLAKE2b-256 d8a5ca93a7d58f2c304769282ce31f8e25374c8f33515575dd7793529203192e

See more details on using hashes here.

File details

Details for the file astroapers-0.1.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

  • Download URL: astroapers-0.1.2-cp313-cp313-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 606.6 kB
  • Tags: CPython 3.13, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for astroapers-0.1.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2f0e1772470d939cae99b4a31beaafcbf4b8c0f984794a4223072eaf79985940
MD5 c41e86c4b607ec2cc81bef9534da60a5
BLAKE2b-256 e6ba94dcffe55aba5f1f0b54afd7db91f0e3fd4f0eadf78ee4e98e1450a782ad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page