# opencr.data.checks

*module*

Checks of data before it enters a model.

Every importer runs these checks, and `check_network_data` runs them on a
whole network. A check returns a list of problems as sentences (empty when the
data are fine); `raise_problems` turns a non-empty list into a
`DataError`.

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

## opencr.data.checks.REQUIRED_PROVENANCE

*attribute* · *module attribute*

```python
REQUIRED_PROVENANCE = ('reference', 'units', 'licence')
```

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

## opencr.data.checks.DataError

*class*

```python
class DataError(ValueError)
```

Bases: `ValueError`

Data failed a check; ``problems`` lists every problem found.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/data/checks.py#L36-L42)

### opencr.data.checks.DataError.problems

*attribute* · *instance attribute*

```python
problems = list(problems)
```

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

## opencr.data.checks.check_cross_section

*function*

```python
def check_cross_section(energy: Iterable[float], sigma: Iterable[float], threshold: float = 0.0, name: str = 'cross section', max_sigma: float = 1e-14, strict_threshold: bool = True) -> list[str]
```

Check a cross-section table (eV, m^2).

Problems: arrays of different shapes or fewer than two points, missing
or infinite values, energies not increasing, negative energies or cross
sections, a negative threshold, a non-zero cross section below the
threshold (unless ``strict_threshold`` is false: plasmacoll sets a cross
section to zero below its threshold whatever the table says), and values
above ``max_sigma`` (1e-14 m^2 by default, a hint that the table is in cm^2).

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

## opencr.data.checks.check_levels

*function*

```python
def check_levels(states: Sequence[State]) -> list[str]
```

Check the levels of one or more species.

Problems: repeated names, missing or infinite energies, and, per species,
a ground state not at the lowest energy among states ordered by their
principal quantum number ``n`` (energies must increase with ``n``).

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/data/checks.py#L122-L146)

## opencr.data.checks.check_network_data

*function*

```python
def check_network_data(network: ReactionNetwork, required: Sequence[str] = REQUIRED_PROVENANCE) -> list[str]
```

Check the data of every reaction and level of a network.

The levels (`check_levels`), every cross section and rate table, and
the provenance of every reaction that is not a detailed balance.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/data/checks.py#L174-L194)

## opencr.data.checks.check_provenance

*function*

```python
def check_provenance(provenance: Provenance | None, name: str = 'data', required: Sequence[str] = REQUIRED_PROVENANCE) -> list[str]
```

Check that the fields ``required`` of a provenance are filled.

``reference`` needs a citation, ``licence`` a value other than
``"unknown"``; any other field must be non-empty.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/data/checks.py#L149-L171)

## opencr.data.checks.check_rate_table

*function*

```python
def check_rate_table(temperatures: Iterable[float], values: Iterable[float], name: str = 'rate table') -> list[str]
```

Check a rate-coefficient table (eV, SI).

Problems: arrays of different shapes or fewer than two points, missing or
infinite values, temperatures not positive and increasing, negative rates.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/data/checks.py#L95-L119)

## opencr.data.checks.raise_problems

*function*

```python
def raise_problems(problems: Sequence[str]) -> None
```

Raise `DataError` if ``problems`` is not empty.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/data/checks.py#L45-L48)
