Skip to main content

Rust port of beamcon from RACS-tools: smooth FITS images and cubes to a common beam via UV-plane (FFT) convolution

Project description

convolve-rs

A Rust port of beamcon from RACS-tools. Smooths FITS images and spectral cubes to a common beam using UV-plane (FFT) convolution to avoid numerical issues with undersampled kernels.

Note: This is an experiment in LLM-assisted coding with Claude. Do not trust this software as far as you can throw it.

Installation

Python library

pip install convolve-rs

CLI binary

Requires Rust 1.85+.

cargo install convolve-rs

Python usage

from astropy.io import fits
import numpy as np
from convolve_rs import Beam, common_beam, smooth

hdu = fits.open("image.fits")
data = hdu[0].data.squeeze().astype(np.float32)
dx_deg = hdu[0].header["CDELT1"]   # may be negative
dy_deg = hdu[0].header["CDELT2"]

current = Beam.from_fits_header(hdu[0].header)
target = Beam(0.002, 0.002, 0.0)   # or common_beam([...]) across channels

# `bunit` selects the flux scaling: Jy/beam images are rescaled to stay in
# Jy/beam; Kelvin (brightness temperature) images are left unscaled. An
# unrecognised unit emits a UserWarning and is treated as Jy/beam.
smoothed = smooth(data, current, target, dx_deg, dy_deg, bunit=hdu[0].header.get("BUNIT"))

hdu[0].data[0, 0] = smoothed
fits.writeto("smoothed.fits", hdu[0].data, hdu[0].header, overwrite=True)

CLI usage

convolvers --help
convolvers 2d --help
convolvers 3d --help

Development

Install in editable mode:

uv pip install -e .

After changing the Python-facing Rust API in src/python.rs, rebuild with the stubgen feature (the default build omits _generate_stubs) and regenerate the type stubs:

uv run maturin develop --features stubgen
uv run --no-sync python -c "from convolve_rs._convolve_rs import _generate_stubs; _generate_stubs()"

This overwrites convolve_rs/_convolve_rs.pyi from the Rust annotations and docstrings. Commit the result alongside any API changes.

Pre-commit hooks

Formatters and linters run via prek, a fast drop-in pre-commit reimplementation. The hooks (.pre-commit-config.yaml) are the same checks CI enforces: ruff lint + format, ty type checking, cargo fmt, and cargo clippy.

uv sync --extra dev   # installs prek + ty into the venv
uvx prek install      # install the git hook (runs on every commit)
uvx prek run --all-files   # run all hooks manually

License

convolve-rs is released under the BSD 3-Clause License.

It builds on prior work in the radio-astronomy community: the UV-plane convolution and cube handling are ported from RACS-tools, and the common-beam computation follows radio_beam (both BSD). The Gaussian beam algebra implements the standard formulae of Wild (1970), and MIRIAD (GPL) serves as a validation reference in the test suite. See NOTICE.md for full attributions.

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

convolve_rs-1.0.2.tar.gz (461.2 kB view details)

Uploaded Source

Built Distributions

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

convolve_rs-1.0.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (694.9 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

convolve_rs-1.0.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (587.3 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

convolve_rs-1.0.2-cp310-abi3-macosx_11_0_arm64.whl (531.8 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file convolve_rs-1.0.2.tar.gz.

File metadata

  • Download URL: convolve_rs-1.0.2.tar.gz
  • Upload date:
  • Size: 461.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for convolve_rs-1.0.2.tar.gz
Algorithm Hash digest
SHA256 02f8d53f5d20e9eb46058c909c476bfca4e66c9ed80c11b99b4b94516a403d55
MD5 5a04f5e52d44bb721ddccf11484eff9e
BLAKE2b-256 313afbcde315d9d86d7ef23f4452c1c22c883ee4533145c3d63a94f11d7dcd6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for convolve_rs-1.0.2.tar.gz:

Publisher: cd.yml on AlecThomson/convolve-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file convolve_rs-1.0.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for convolve_rs-1.0.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b8372e4e3b7ac73b34df312e080a61f7ad789d5117d19c63882bcda53b4fa84f
MD5 3cc45bb8f1b3270f05de1bb7cd4081df
BLAKE2b-256 a5a75f895157fc2ad945a2a5d52b494139e6754a8e3d10a18db57ce95f3d6614

See more details on using hashes here.

Provenance

The following attestation bundles were made for convolve_rs-1.0.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: cd.yml on AlecThomson/convolve-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file convolve_rs-1.0.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for convolve_rs-1.0.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 07be9f8882fecfa9509ad39a2efe2a635da3059e676ad59c895f36ca4977b0f2
MD5 4d4c8280386883972eab1a96851d56e2
BLAKE2b-256 d175f419f0467f57b4935b859a4dc9cd88bff59e91b93dcd95dc67db94ae7d33

See more details on using hashes here.

Provenance

The following attestation bundles were made for convolve_rs-1.0.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: cd.yml on AlecThomson/convolve-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file convolve_rs-1.0.2-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for convolve_rs-1.0.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6e9685a94a6f80dedd087d34d1496c1fbadac03c583c63092f70ef76b24c5283
MD5 82ffee7abad51afb14e051344cbcebb2
BLAKE2b-256 cf5e280e0e29cf415b97d79ab66bd48cf4937bced461c208f72264b47425243a

See more details on using hashes here.

Provenance

The following attestation bundles were made for convolve_rs-1.0.2-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: cd.yml on AlecThomson/convolve-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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