# opencr.analysis.emission

*module*

Line emission and synthetic spectra.

Each spontaneous emission ``u -> l`` of a network is a line of photon energy
``E_u - E_l`` with emissivity ``eps = n_u A_ul`` (photons m^-3 s^-1; the escape
factor is already in ``A``). In a quasi-static solve the upper population is a
sum over the drivers, ``n_u = sum_d C_ud n_d``, so the emissivity splits into
photon emissivity coefficients ``PEC_d = A_ul C_ud / n_e`` (m^3/s) with
``eps = n_e sum_d PEC_d n_d``.

A synthetic spectrum puts each line on a wavelength grid as a Gaussian of the
Doppler width at the gas temperature (or a given instrumental FWHM, or both
added in quadrature).

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/analysis/emission.py#L1-L1)

## opencr.analysis.emission.doppler_fwhm

*function*

```python
def doppler_fwhm(wavelength: np.ndarray, temperature: float, mass: float) -> np.ndarray
```

Return the Doppler FWHM in nm of lines at ``wavelength`` (nm), ``kT`` in eV, mass in kg.

**Numerics**

*fwhm*

$$
\Delta\lambda_{\mathrm{FWHM}} = \lambda\, 2\sqrt{2\ln 2}\, \frac{\sigma_v}{c}, \qquad \sigma_v = \sqrt{\frac{kT}{m}}
$$

Assumptions:

- a Maxwellian of the emitters at $T$: $\sigma_v$ per velocity component

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/analysis/emission.py#L79-L97)

## opencr.analysis.emission.hydrogen_line_name

*function*

```python
def hydrogen_line_name(upper: int, lower: int) -> str
```

Return the spectroscopic name of an H line, e.g. ``"H-α"`` for 3 -> 2, ``"Ly-β"`` for 3 -> 1.

Lines past the Greek alphabet's twelfth member, or of series beyond
Humphreys, are named ``"<upper>-<lower>"``.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/analysis/emission.py#L38-L47)

## opencr.analysis.emission.line_table

*function*

```python
def line_table(network: ReactionNetwork, rates: np.ndarray, populations: dict[str, float], air: bool = False) -> xr.Dataset
```

Return every line's wavelength, emissivity and power.

**Parameters**

- `network` (`ReactionNetwork`) — The network.
- `rates` (`np.ndarray`) — The rate coefficients (the escape factors applied).
- `populations` (`dict[str, float]`) — Every state's density.
- `air` (`bool`) (default: `False`) — Wavelengths in standard air above 200 nm instead of vacuum.

**Returns**

- (`xr.Dataset`) — A dataset over ``line`` (the reaction names) with ``wavelength`` (nm),
- (`xr.Dataset`) — ``photon_energy`` (eV), ``emissivity`` (photons m^-3 s^-1), ``power``
- (`xr.Dataset`) — (W m^-3), ``upper``, ``lower`` and ``label``.

**Numerics**

*line*

$$
E = E_u - E_l, \qquad \lambda = \frac{hc}{E}, \qquad \epsilon = g\,A_{ul}\, n_u \ [\mathrm{photons\ m^{-3}\,s^{-1}}], \qquad P = \epsilon\, E\, e \ [\mathrm{W\,m^{-3}}]
$$

Assumptions:

- every spontaneous emission $u \to l$ is a line; the escape factor $g$ is already in the rate
- photon energies from the state energies; vacuum wavelengths, or in air above 200 nm

Built from:

- `opencr.constants.photon_wavelength`
- `opencr.constants.air_wavelength`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/analysis/emission.py#L100-L167)

## opencr.analysis.emission.spectrum

*function*

```python
def spectrum(lines: xr.Dataset, wavelength: np.ndarray, temperature: float | None = None, mass: float = 1.00794 * ATOMIC_MASS, fwhm: float = 0.0, quantity: str = 'power') -> xr.DataArray
```

Return the spectral emissivity of ``lines`` on the grid ``wavelength`` (nm).

Each line is a normalised Gaussian whose FWHM is the Doppler width at
``temperature`` (eV, of an emitter of ``mass``) and the instrumental
``fwhm`` (nm) added in quadrature.

**Parameters**

- `lines` (`xr.Dataset`) — The output of `line_table`.
- `wavelength` (`np.ndarray`) — The grid in nm.
- `temperature` (`float | None`) (default: `None`) — The emitters' ``kT`` in eV; no Doppler broadening if ``None``.
- `mass` (`float`) (default: `1.00794 * ATOMIC_MASS`) — The emitters' mass in kg.
- `fwhm` (`float`) (default: `0.0`) — The instrumental FWHM in nm.
- `quantity` (`str`) (default: `'power'`) — ``"power"`` (W m^-3 nm^-1) or ``"emissivity"`` (photons m^-3 s^-1 nm^-1).

**Numerics**

*spectrum*

$$
\epsilon_\lambda(\lambda) = \sum_{\mathrm{lines}} \frac{\epsilon}{\sigma\sqrt{2\pi}}\, e^{-(\lambda - \lambda_0)^2/2\sigma^2}, \qquad \sigma = \frac{\Delta\lambda_{\mathrm{FWHM}}}{2\sqrt{2\ln 2}}
$$

*width*

$$
\Delta\lambda_{\mathrm{FWHM}}^2 = \Delta\lambda_{\mathrm{Doppler}}^2 + \Delta\lambda_{\mathrm{instrument}}^2
$$

Assumptions:

- Gaussian lines only: no Stark, Zeeman or natural broadening
- a line without either width raises

Built from:

- `opencr.analysis.emission.doppler_fwhm`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/analysis/emission.py#L170-L226)
