# opencr.tables

*module*

Effective-rate tables for the codes that use OpenCR's results.

`effective_rate_table` solves a model on a grid of electron
temperature and density and stores named quantities
(`opencr.analysis.quantities`: effective rates, population and electron
cooling coefficients, line emissivities) as an xarray dataset with the
model's provenance; `EffectiveRateTable` interpolates such a table,
bilinearly in ``ln q`` against ``ln T_e`` and ``ln n_e`` (end values outside),
and writes and reads it as netCDF. carafe, beamtracer and freeofcharge
take their effective rates from these tables in place of fits.

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

## opencr.tables.EffectiveRateTable

*class*

```python
class EffectiveRateTable
```

A table of quantities against ``T_e`` and ``n_e``, interpolated in log space.

**Parameters**

- `dataset` (`xr.Dataset`) — A dataset as `effective_rate_table` makes it.

**Numerics**

*bilinear*

$$
\ln q(x, y) = (1-u)(1-w)\, \ln q_{ij} + u(1-w)\, \ln q_{i+1,j} + (1-u)w\, \ln q_{i,j+1} + uw\, \ln q_{i+1,j+1}
$$

*coordinates*

$$
x = \ln T_e, \quad y = \ln n_e, \qquad u = \frac{x - x_i}{x_{i+1} - x_i}, \quad w = \frac{y - y_j}{y_{j+1} - y_j}
$$

Order of accuracy: 2.

Assumptions:

- end values outside the table ($x$ and $y$ clipped)
- a quantity with zero or negative values (an effective loss rate, a cooling with recombination) is interpolated in $q$ instead of $\ln q$
- the order is in the table spacing in $\ln T_e$ and $\ln n_e$

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/tables.py#L60-L163)

### opencr.tables.EffectiveRateTable.dataset

*attribute* · *instance attribute*

```python
dataset = dataset
```

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

### opencr.tables.EffectiveRateTable.quantities

*property*

```python
quantities: tuple[str, ...]
```

The tabulated quantities.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/tables.py#L92-L94)

### opencr.tables.EffectiveRateTable.from_netcdf

*method* · *classmethod*

```python
def from_netcdf(path: str | Path) -> EffectiveRateTable
```

Read a table written by `to_netcdf`.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/tables.py#L112-L116)

### opencr.tables.EffectiveRateTable.function

*method*

```python
def function(name: str, electron_density: float)
```

Return ``T_e -> quantity`` at a fixed ``n_e``, for codes whose rates depend on ``T_e`` only.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/tables.py#L96-L104)

### opencr.tables.EffectiveRateTable.to_netcdf

*method*

```python
def to_netcdf(path: str | Path) -> Path
```

Write the table to ``path`` (netCDF) and return the path.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/tables.py#L106-L110)

## opencr.tables.effective_rate_table

*function*

```python
def effective_rate_table(model: Model, conditions: Conditions, outputs: Sequence[str], temperatures: Sequence[float] = tuple(np.geomspace(0.5, 100.0, 25)), densities: Sequence[float] = tuple(np.geomspace(1e+16, 1e+21, 11)), mode: str = 'quasi-static') -> EffectiveRateTable
```

Solve ``model`` on a grid of ``T_e`` (eV) and ``n_e`` (m^-3) and tabulate ``outputs``.

**Parameters**

- `model` (`Model`) — The model.
- `conditions` (`Conditions`) — The conditions with the driver densities (the quasi-static quantities per driver do not depend on them for a linear network).
- `outputs` (`Sequence[str]`) — The quantities.
- `temperatures` (`Sequence[float]`) (default: `tuple(np.geomspace(0.5, 100.0, 25))`) — The electron temperatures in eV (or quantities), increasing.
- `densities` (`Sequence[float]`) (default: `tuple(np.geomspace(1e+16, 1e+21, 11))`) — The electron densities in m^-3 (or quantities), increasing.
- `mode` (`str`) (default: `'quasi-static'`) — The steady-state mode.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/tables.py#L166-L211)
