Metadata-Version: 2.4
Name: opencr
Version: 0.1.0
Summary: Collisional-radiative models of low-temperature plasmas: reaction networks with provenance, steady and time-dependent populations, effective rates and emission.
Author: Max
Project-URL: Source, https://github.com/max-models/OpenCR
Keywords: atomic data,collisional-radiative,effective rates,hydrogen,plasma,spectroscopy
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Physics
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: methodcard
Requires-Dist: numpy
Requires-Dist: plasmacoll>=0.5.0
Requires-Dist: scipy>=1.10
Requires-Dist: scope-profiler>=0.7.5
Requires-Dist: xarray
Provides-Extra: dev
Requires-Dist: jupyterlab; extra == "dev"
Requires-Dist: pre-commit; extra == "dev"
Requires-Dist: pyproject-fmt; extra == "dev"
Requires-Dist: pyright; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: opencr[docs,test]; extra == "dev"
Provides-Extra: cunumpy
Requires-Dist: cunumpy>=0.7; extra == "cunumpy"
Provides-Extra: docs
Requires-Dist: griffe; extra == "docs"
Requires-Dist: ipykernel; extra == "docs"
Requires-Dist: jax; extra == "docs"
Requires-Dist: kaleido; extra == "docs"
Requires-Dist: matplotlib>=3.10.9; extra == "docs"
Requires-Dist: nbclient>=0.11; extra == "docs"
Requires-Dist: nbformat>=5.11.1; extra == "docs"
Requires-Dist: plasma-plots[web]; extra == "docs"
Requires-Dist: scikit-learn; extra == "docs"
Provides-Extra: jax
Requires-Dist: jax; extra == "jax"
Provides-Extra: ml
Requires-Dist: scikit-learn; extra == "ml"
Provides-Extra: test
Requires-Dist: astropy; extra == "test"
Requires-Dist: jax; extra == "test"
Requires-Dist: methodcard[symbolic]; extra == "test"
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Requires-Dist: scikit-learn; extra == "test"

# opencr


<!-- README.md is generated from README.qmd: edit the .qmd and run `make readme`. -->

[![Tests](https://github.com/max-models/OpenCR/actions/workflows/test_pytest.yml/badge.svg)](https://github.com/max-models/OpenCR/actions/workflows/test_pytest.yml)
[![Static
analysis](https://github.com/max-models/OpenCR/actions/workflows/static_analysis.yml/badge.svg)](https://github.com/max-models/OpenCR/actions/workflows/static_analysis.yml)
[![Docs](https://github.com/max-models/OpenCR/actions/workflows/docs.yml/badge.svg)](https://max-models.github.io/OpenCR/)
[![codecov](https://codecov.io/gh/max-models/opencr/branch/main/graph/badge.svg)](https://codecov.io/gh/max-models/opencr)
[![PyPI](https://img.shields.io/pypi/v/opencr.png)](https://pypi.org/project/opencr/)
[![Python](https://img.shields.io/pypi/pyversions/opencr.png)](https://pypi.org/project/opencr/)

Collisional-radiative (CR) models of low-temperature plasmas in Python:
explicit states and reactions with traceable data, steady-state and
time-dependent population kinetics, effective ionization, recombination
and emission coefficients, and synthetic spectra. Atomic hydrogen first;
molecular hydrogen, accelerated backends (cunumpy, JAX) and surrogate
models are optional extensions. Cross sections and rates come from
[plasmacoll](https://github.com/max-models/plasmacoll).

Documentation: <https://max-models.github.io/OpenCR/>

## Example

``` python
import opencr

model = opencr.load_model("hydrogen/atomic/basic")
conditions = opencr.Conditions(
    electron_temperature=2.0,  # eV
    electron_density=1e18,  # m^-3
    densities={"H(n=1)": 1e19, "H+": 1e18},  # the drivers, m^-3
)
result = model.solve_steady_state(conditions)
result.populations["H(n=3)"]  # m^-3
result.emission().sel(line="A:3-2")  # H-alpha
result.reduction.effective_rate("H(n=1)", "H+")  # S_CR, m^3/s
```

Every physical setting (temperatures, densities, lengths, times,
energies, masses) also takes an [astropy](https://www.astropy.org/)
quantity or a string such as `"300 K"`, as in a configuration file; it
is converted once to the documented unit (SI, temperatures as kT in eV),
and a bare number keeps meaning that unit:

``` python
import astropy.units as u

conditions = opencr.Conditions(
    electron_temperature="23200 K",  # 2.0 eV
    electron_density=1e12 * u.cm**-3,  # 1e18 m^-3
    densities={"H(n=1)": "1e13 cm-3", "H+": 1e18},  # a bare number is in m^-3
)
```

The physics, the closures and the units are in [The CR
model](https://max-models.github.io/OpenCR/guides/model/); the
acceptance criteria of the atomic hydrogen model in
[Verification](https://max-models.github.io/OpenCR/guides/verification/).

## Install

With [uv](https://docs.astral.sh/uv/):

``` bash
make install    # uv sync --extra dev, plus the pre-commit hooks
uv run opencr list
```

Or create and activate a Python environment (3.10 or newer):

``` bash
python -m venv env
source env/bin/activate
pip install --upgrade pip
```

Install the code and requirements with pip:

``` bash
pip install -e .
```

The optional extras `cunumpy`, `jax` and `ml` add the accelerated
backends and the surrogate models; the `test`, `docs` and `dev` extras
install the test runner, the documentation tooling and the linters:

``` bash
pip install -e ".[dev]"
```

## Development

Formatting and linting use [ruff](https://docs.astral.sh/ruff/), type
checking [pyright](https://microsoft.github.io/pyright/), run by
[pre-commit](https://pre-commit.com/) and in CI:

``` bash
make lint     # ruff check, ruff format --check, pyright
make test     # pytest with coverage
```

Commit messages follow [Conventional
Commits](https://www.conventionalcommits.org/); see
[CONTRIBUTING.md](CONTRIBUTING.md).

## Build docs

The documentation in `docs/` is an Astro + Starlight site: hand-written
pages, the notebooks in `tutorials/` executed and published as pages,
complete Python scripts in `examples/` published with their plots, and
the API reference generated from the docstrings with
[starlight-pydocs](https://ewels.github.io/starlight-pydocs/). It needs
Node 22 or newer.

``` bash
make docs-install     # npm packages and the Python docs extra
make docs-notebooks   # execute tutorials/*.ipynb and convert them to pages
make docs-examples    # run examples/*.py and publish their plots
make docs-dev         # live preview at http://localhost:4321/OpenCR/
make docs-build       # the static site in docs/dist
```

## Build the README

`README.md` is rendered from `README.qmd` with
[Quarto](https://quarto.org/):

``` bash
make readme
```

## Releases

Before merging a release to `main`, update the version in
`pyproject.toml`, `src/opencr/__init__.py` and `CITATION.cff` (including
its release date), and add the release notes to `CHANGELOG.md`. The push
to `main` creates a GitHub release with a `vX.Y.Z` tag and publishes the
package to PyPI with trusted publishing (OIDC). The one-time PyPI and
GitHub configuration is described in the [publishing
tutorial](https://max-models.github.io/OpenCR/development/publishing/).
