SWEaver — Harmonic-domain manipulation of electomagnetic beams for CMB analysis
SWEaver is currently under active development alongside an upcoming companion paper (Tomasi et al., in prep). If you wish to use this tool for academic work prior to publication, please contact the authors.
This repository contains SWEaver, a Python library that bridges antenna engineering solvers and Cosmic Microwave Background (CMB) pipelines by directly manipulating TICRA Spherical Wave Expansion (SWE) files. By avoiding pixel-space interpolations, SWEaver performs mathematically exact rotations in the purely harmonic domain, and high-fidelity phase-shift translations using projections free from integration errors. The software can transform the physical electric field into the spin-weighted Stokes parameters ($I, Q, U$) required by total-convolution codes, and evaluates the resulting fields onto arbitrary real-space grids and cuts.
Features
- Native SWE Parsing: Directly ingests and parses binary and ASCII TICRA Spherical Wave Expansion files.
- Spin-1 to Spin-2 Transformation: Converts physical electric far-fields (spin-1) into Stokes parameters ($I, Q, U$) and maps them directly to the spin-weighted spherical harmonic coefficients ($a_{\ell m}^E$, $a_{\ell m}^B$) required by CMB total-convolution codes.
- Exact Coordinate Rotations: Implements exact 3D rigid-body rotations of harmonic coefficients using Wigner-$D$ matrices.
- Phase-Shift Translations: Features
ElectricField.translate_phase_center(), utilizing spherical Bessel function padding to apply exact spatial translation phase shifts without introducing spatial aliasing. - Linear Superposition: Enables direct algebraic addition (
+) and subtraction (-) of multiple optical paths (e.g., combining main beam, subreflector spillover, and baffle blockage) in coefficient space. - Polarization Projections: Comprehensive support for standard $\theta/\phi$ projections and Ludwig’s 3rd definition (with automatic mapping to the IAU polarization convention).
- High-Performance Backend: Powered by
ducc0for ultra-fast, double-precision Spherical Harmonic Transforms.
Validation
SWEaver is verified to match native TICRA Tools evaluations to the literal numerical truncation limit of the ASCII files (~ −80 dB) across complex, highly oscillatory asymmetric interferometric patterns.
The following is a model containing two Gaussian feeds displaced $-4\lambda$ and $+7\lambda$ along the x-axis and rotated by 15° and −22°.
The following plot compares the .cut file saved by TICRA and the cut computed by SWEaver by performing the following operations:
- Load one SWE file containing the SWE of a Gaussian feed;
- Duplicate the SWE coefficients and rotate each instance by +15° and −22° using Wigner D-matrices;
- Translate the two rotated SWE to their position
- Sum the two SWE
- Project the SWE in real space along the same points of the TICRA cut.
The overall numerical error is $10^{-8}$ dB.
Installation
The easiest way to add SWEaver to your Python code is using uv:
uv add sweaver
Development setup
Prerequisites
Ensure you have uv installed. You can grab the installer from the Astral website or run the following script from the command line:
curl -LsSf https://astral.sh/uv/install.sh | sh
Installation Environments
We use dependency groups to keep the environment lean. Depending on your task, sync the environment using one of the following commands:
-
Standard Development (Tests, Linting, Typing):
uv sync --group dev
-
Visualization & Research (JupyterLab, Matplotlib, Plotting):
uv sync --group dev --group visualization
-
Documentation:
uv sync --group docs
-
Minimal/Production (Library only):
uv sync
Building the documentation
The documentation is built using Sphinx. To build the HTML manual locally, simply use Nox:
uv run nox -s docs
The generated HTML files will be available in the docs/_build/html directory. You can open docs/_build/html/index.html in your web browser.
Alternatively, if you prefer to build the documentation without Nox, ensure you have synced the docs dependency group, then run:
uv run sphinx-build -b html docs/ docs/_build/html
Working with Notebooks
If you are debugging or visually inspecting results using the visualization group, we recommend using the integrated Jupyter kernel.
-
Using VS Code / Cursor:
-
Open a .ipynb file.
-
Select the kernel associated with the .venv created by uv.
-
If the kernel isn't detected, ensure you have run
uv sync --group visualization.
-
-
Using JupyterLab:
uv run jupyter lab
Note: The visualization group includes heavy dependencies like matplotlib and jupyterlab. These are excluded from the core library installation to keep the package lightweight for end-users.
Cleaning the workspace
If you need to remove the virtual environment and start fresh, run the following commands:
rm -rf .venv
uv sync
Licensing
This project is licensed under the GPL 3.0. See LICENSE.txt.
Citation
A paper describing SWEaver is currently being prepared. Contact the authors if you want to cite SWEaver.
Metadata
Release files for sweaver 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sweaver-0.1.0.tar.gz | 3.5 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sweaver-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.9 MB
Release files / sweaver-0.1.0.tar.gz
| Download URL | sweaver-0.1.0.tar.gz |
|---|---|
| Size | 3.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e40bb4dbd7f14bbf8a5934263cda2eb696c2e1ec9fb2db2d0119e5319d821bd2
|
|
BLAKE2b-256 checksum How to use checksums |
d9de934b84d562a77f451c1d1ae4570d0494163d53cfe0911a27c2e2c2d2db22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"EndeavourOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / sweaver-0.1.0-py3-none-any.whl
| Download URL | sweaver-0.1.0-py3-none-any.whl |
|---|---|
| Size | 3.5 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f6407fefff7906faad4649a3e3deb7bc58718421894ff8408bd391d7e23f2bff
|
|
BLAKE2b-256 checksum How to use checksums |
54dbda8e3310ac32b305e0c7a00570f91fea514b21032def1e52d9dac0505260
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"EndeavourOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|