Metadata-Version: 2.4
Name: syncem
Version: 0.9.0
Summary: Differentiable synchrotron kernels and explicitly scoped statistical approximations
License-Expression: MIT
Project-URL: Homepage, https://github.com/zzhang0123/syncem
Project-URL: Documentation, https://syncem.readthedocs.io
Project-URL: Changelog, https://github.com/zzhang0123/syncem/blob/main/CHANGELOG.md
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: jax<0.11,>=0.10
Requires-Dist: equinox<0.14,>=0.13.7
Requires-Dist: numpy<3,>=2.3
Requires-Dist: scipy<2,>=1.16
Provides-Extra: validation
Requires-Dist: scipy<2,>=1.16; extra == "validation"
Requires-Dist: matplotlib<4,>=3.10; extra == "validation"
Requires-Dist: pytest<10,>=8; extra == "validation"
Provides-Extra: high-harmonic
Requires-Dist: scipy<2,>=1.16; extra == "high-harmonic"
Provides-Extra: dev
Requires-Dist: black>=25; extra == "dev"
Requires-Dist: ruff>=0.12; extra == "dev"
Provides-Extra: docs
Requires-Dist: sphinx<9,>=8; extra == "docs"
Requires-Dist: myst-parser<5,>=4; extra == "docs"
Requires-Dist: furo>=2024.8; extra == "docs"
Dynamic: license-file

# SyncEM

Documentation: <https://syncem.readthedocs.io> · Releases: <https://github.com/zzhang0123/syncem/releases>

SyncEM is a JAX and Equinox package for differentiable synchrotron kernels,
finite-moment spectral bases, and statistical spectral inference accompanying
*A statistical framework for the modelling of synchrotron emission* (Zhang, Chluba & Watson).

## Scope and explicit boundaries

SyncEM separates four operations rather than folding them into a single black box:

1. **Physical kernel approximation**: discrete finite-$\gamma$ harmonics or the ultra-relativistic continuum kernel.
2. **Finite basis expansion**: per-cell local polynomials, Legendre angular projections, azimuth harmonics, and Faraday phase series.
3. **Statistical closure**: declared distributions, conditional laws, symmetries, or free moment coordinates.
4. **Numerical solution**: quadrature, differentiation, and linear or nonlinear inference.

Every forward prediction and spectral fit carries a typed error ledger
(`bound`, `measured`, `estimate`, `unbounded`, `not_applicable`).
Passing a kernel or regression test does not certify a Galactic foreground model
at 21-cm precision. Unsupplied physical, tail, and modelling discrepancies remain
labelled `unbounded`.

> **Note on companion repositories:** The positive finite-cumulant PDF
> reconstruction and the independent 21-cm assessment live in the manuscript
> repository's `validation/` directory and do not import SyncEM.
> `CumulantExpansion` in this package is a historical alias for a quadratic
> fixed-harmonic Taylor average, not that PDF reconstruction.

## Installation

Python 3.12 is the tested runtime. The examples below use version 0.9.0.

```bash
python -m pip install syncem==0.9.0
```

For local tests and validation tools from a checkout:

```bash
python -m pip install -e '.[validation]'
python -m pytest tests -q
```

Importing `syncem` enables JAX 64-bit floating point (`jax_enable_x64`) globally.
Import `syncem` at the top of a script before creating JAX arrays.

## Quick start

Build a spectral basis on energy cells, predict Stokes spectra in physical units,
and inspect the error ledger:

```python
import syncem as se

channels = se.Channels.log(0.2, 8.0, 16, unit="GHz", half_width=0.2)
population = se.paper.e1()
lattice = se.Lattice(gamma=se.paper.cells(order=2))

basis = se.spectral_basis(population, channels, lattice=lattice)
spectrum = basis.predict(population, check=False).to("Jy/sr")
print(spectrum.table())
print(spectrum.ledger.unbounded())
```

The example skips the direct comparison. Set `check=True` to request it.

To fit observations with unknown electron moments, replace the energy law with
`se.FreeMoments()` and call `se.fit`:

```python
data = se.StokesData(
    channels,
    I=spectrum.I,
    Q=spectrum.Q,
    U=spectrum.U,
    unit=spectrum.unit,
    sigma=0.01 * spectrum.I[:, None],
).withhold([1, 5, 9, 13])

result = se.fit(population.replace(gamma=se.FreeMoments()), data, basis=basis)
print(result)
```

## Package layers

SyncEM exposes four distinct layers. New work should start at the top-level
`syncem` interface.

| Layer | Entry points | Purpose |
| --- | --- | --- |
| **Spectral bases & inference (0.8+)** | `se.Population`, `se.Channels`, `se.Lattice`, `se.spectral_basis`, `se.predict`, `se.fit`, `se.problem` | General per-variable cells, conditionals, physical electron columns ($\text{cm}^{-2}$), unit-area channels, and typed error ledgers. |
| **Two-regime paper model (0.9)** | `se.RegimeBasis`, `se.paper.population`, `se.paper.regime_basis`, `se.paper.energy_basis` | Joins finite-$\gamma$ harmonic kernels below $\gamma = 300$ with continuum kernels at and above $\gamma = 300$ for Sec. 5 of the manuscript. |
| **Low-level kernels & transfer** | `syncem.stokes`, `syncem.derivatives`, `syncem.expansion`, `syncem.rm`, `syncem.faraday`, `syncem.transfer`, `syncem.magnus`, `syncem.los_moments` | Single-electron Schott harmonics, fixed-harmonic quadratic averages, discrete Faraday screens, and exploratory ordered radiative transfer. |
| **Single-reference layer (v0.7.10)** | `syncem.model`, `syncem.model.fit` | Preserved single-reference moment interface with unit-normalised moments and unit-peak channels. |

## Documentation map

Full documentation is hosted at <https://syncem.readthedocs.io>:

- **Start here**: [Installation](https://syncem.readthedocs.io/en/latest/installation.html) · [Quickstart](https://syncem.readthedocs.io/en/latest/quickstart.html)
- **Core concepts**: [Architecture & Data Model](https://syncem.readthedocs.io/en/latest/concepts/architecture.html) · [Error Ledger & Defaults](https://syncem.readthedocs.io/en/latest/concepts/error_ledger.html)
- **User guides**: [Spectral Bases & Lattices](https://syncem.readthedocs.io/en/latest/guide/moment_lattice.html) · [Fitting & Inference](https://syncem.readthedocs.io/en/latest/guide/fitting.html) · [Two-Regime Spectra](https://syncem.readthedocs.io/en/latest/guide/two_regime.html) · [Faraday Rotation & Screens](https://syncem.readthedocs.io/en/latest/guide/faraday.html) · [High-Order Harmonics](https://syncem.readthedocs.io/en/latest/guide/high_order_harmonic.html)
- **Low-level & v0.7.10**: [Harmonic Radiation](https://syncem.readthedocs.io/en/latest/guide/radiation.html) · [Fixed-Harmonic Contractions](https://syncem.readthedocs.io/en/latest/guide/fixed_harmonic.html) · [Radiative Transfer](https://syncem.readthedocs.io/en/latest/guide/transfer.html) · [`syncem.model` Guide](https://syncem.readthedocs.io/en/latest/guide/model.html) · [Identifiable SED Fits](https://syncem.readthedocs.io/en/latest/guide/reconstruction.html)
- **Design & Reference**: [0.8/0.9 Architecture](https://syncem.readthedocs.io/en/latest/design/architecture.html) · [`syncem.model` Design](https://syncem.readthedocs.io/en/latest/DESIGN.html) · [API Reference](https://syncem.readthedocs.io/en/latest/api/index.html) · [Scope & Compatibility](https://syncem.readthedocs.io/en/latest/scope.html)

## Verification and companion scripts

- **Standard test suite**: `python -m pytest tests -q` (skips tests marked `slow`).
- **Paper replays and slow tests**: `python -m pytest tests -m slow` or `SYNCEM_RUN_SLOW=1`.
- **Full diagnostic runner**: `PYTHONPATH=. python scripts/run_all.py --no-figures`.
- **Independent symbolic derivation**: `wolframscript -file derivation/verify.wls` (see [`derivation/README.md`](https://github.com/zzhang0123/syncem/blob/main/derivation/README.md)).
- **Paper reproduction**: [Study scripts and commands](https://github.com/zzhang0123/syncem/tree/v0.9.0/studies/classical-models) and [output archive](https://github.com/zzhang0123/syncem/releases/download/v0.9.0/classical-models-outputs-v0.9.0.tar.gz).

## Citation and license

Please cite Zhang, Chluba & Watson, *A statistical framework for the modelling of synchrotron emission*.

Released under the MIT License. See [LICENSE](https://github.com/zzhang0123/syncem/blob/main/LICENSE).
