Skip to main content

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 ducc0 for 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:

    1. Open a .ipynb file.

    2. Select the kernel associated with the .venv created by uv.

    3. 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.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 sweaver 0.2.0
File Size Uploaded
sweaver-0.2.0.tar.gz 3.5 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for sweaver 0.2.0
File Interpreter ABI Platform
sweaver-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.9 MB

Release files / sweaver-0.2.0.tar.gz

Download URL sweaver-0.2.0.tar.gz
Size 3.5 MB
Tags Source
SHA-256 checksum
How to use checksums
ba5e002afcc96f39aac2a04dd1bef1b23f7ef650ad179b463fe45e0a7be3203f
BLAKE2b-256 checksum
How to use checksums
4dd6be0bfb57b0a9f84468234152e0adf5fb4160951aee61dbee060f521ee60a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.20 {"installer":{"name":"uv","version":"0.12.20","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.2.0-py3-none-any.whl

Download URL sweaver-0.2.0-py3-none-any.whl
Size 3.5 MB
Tags Python 3
SHA-256 checksum
How to use checksums
04308ecf245bad3dac298b24bf267ecc35f4dbcd7e3bad08672cd0b041984afb
BLAKE2b-256 checksum
How to use checksums
cecc9e523f973bd999d2d7e9ccb79637ac6e2b2edb2322bd79a01000853c035c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.20 {"installer":{"name":"uv","version":"0.12.20","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 history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

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