convolve_rs/lib.rs
1//! Smooth radio astronomy FITS images and cubes to a common resolution by
2//! convolution in the UV plane. A Rust port of `beamcon_2D` and `beamcon_3D`
3//! from [RACS-tools](https://github.com/AlecThomson/RACS-tools), also
4//! available as a [Python package](https://pypi.org/project/convolve-rs/) and
5//! the `convolvers` CLI.
6//!
7//! - [`Beam`]: an elliptical Gaussian beam and its algebra ([`beam`]).
8//! - [`common_beam`](fn@common_beam): the smallest beam a set of beams can be
9//! convolved to.
10//! - [`convolve_uv`](fn@convolve_uv): UV-plane convolution between two beams.
11//! - [`smooth`](fn@smooth): convolution plus Jy/beam or Kelvin flux scaling.
12//! - [`fits_io`], [`cube_io`]: FITS image and cube I/O.
13//!
14//! ```
15//! use convolve_rs::{Beam, BrightnessUnit, smooth};
16//! use ndarray::Array2;
17//!
18//! let old_beam = Beam::from_arcsec(10.0, 10.0, 0.0)?;
19//! let new_beam = Beam::from_arcsec(20.0, 20.0, 0.0)?;
20//! let image = Array2::<f32>::from_elem((64, 64), 1.0);
21//! let pixel_deg = 2.5 / 3600.0;
22//!
23//! let smoothed = smooth(
24//! &image,
25//! &old_beam,
26//! &new_beam,
27//! pixel_deg,
28//! pixel_deg,
29//! BrightnessUnit::JyPerBeam,
30//! None,
31//! )?;
32//! assert_eq!(smoothed.dim(), image.dim());
33//! # Ok::<(), Box<dyn std::error::Error>>(())
34//! ```
35pub mod beam;
36pub mod common_beam;
37pub mod convolve_uv;
38pub mod cube_io;
39pub mod fits_io;
40pub mod smooth;
41
42pub use beam::{Beam, BeamError, gauss_factor};
43pub use common_beam::{CommonBeamError, common_beam, find_commonbeam_between};
44pub use convolve_uv::{
45 ConvolutionResult, ConvolveError, FftFloat, FftPlans, convolve_uv, fftfreq, gaussft,
46};
47pub use fits_io::{
48 FitsError, FitsImageData, FitsImageHeader, output_path, read_fits, read_fits_header,
49 read_fits_plane, write_fits,
50};
51pub use smooth::{BrightnessUnit, smooth};
52
53#[cfg(feature = "python")]
54mod python;
55#[cfg(feature = "python")]
56pub use python::_convolve_rs;