---
title: "tomojax.corrections.api"
description: "Expert correction helpers for streaming row-slab pipelines."
canonical: "https://tomojax.dev/api/corrections-api/"
last-updated: "2026-11-28"
---

# tomojax.corrections.api

> For the complete documentation index, see [llms.txt](https://tomojax.dev/llms.txt).

| Name | Summary |
| --- | --- |
| [`CorrectedRows`](https://tomojax.dev/api/corrections-api/#correctedrows) | Owned device projections and their records, completed only when requested. |
| [`check_rows`](https://tomojax.dev/api/corrections-api/#check_rows) | Check a half-open row interval in the binned output. |
| [`check_scan_steps`](https://tomojax.dev/api/corrections-api/#check_scan_steps) | Check that a line-integral scan still has the domains required by each step. |
| [`corrected_row_source`](https://tomojax.dev/api/corrections-api/#corrected_row_source) | Read corrected detector-row intervals without a materialized projection stack. |
| [`positive_finite`](https://tomojax.dev/api/corrections-api/#positive_finite) | Check a positive finite correction parameter. |
| [`preview_window`](https://tomojax.dev/api/corrections-api/#preview_window) | Propagate complete native output blocks backwards across the ordered corrections. |
| [`raw_cache_bytes`](https://tomojax.dev/api/corrections-api/#raw_cache_bytes) | Estimate the bytes held in the raw reader's two cached blocks and its prefetch. |
| [`slab_steps`](https://tomojax.dev/api/corrections-api/#slab_steps) | Check which corrections can run independently on complete detector rows. |
| [`validated_views_per_batch`](https://tomojax.dev/api/corrections-api/#validated_views_per_batch) | Check the requested correction batch size. |

## `CorrectedRows` [#correctedrows]

```python
class CorrectedRows(
    projections: jax.Array,
    flat: Correction,
    steps: tuple[Step, ...],
    epsilon: float,
    counts: tuple[jax.Array, jax.Array],
    raw: np.ndarray,
)
```

<small>Defined in [src/tomojax/corrections/_rows.py:106](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/corrections/_rows.py#L106)</small>

Owned device projections and their records, completed only when requested.

**Parameters**

- **`projections`** (*jax.Array*): Corrected line integrals of the requested rows, in (view, row, column) order.
- **`flat`** (*Correction*): Record of the flat and dark normalization.
- **`steps`** (*tuple of Step*): Corrections applied after normalization, in order.
- **`epsilon`** (*float*): Floor applied to transmission before the logarithm.
- **`counts`** (*tuple of jax.Array*): Device counts of nonpositive transmissions and of nonfinite results.
- **`raw`** (*numpy.ndarray*): Raw detector counts read for these rows.

### `CorrectedRows.records` [#correctedrowsrecords]

```python
@property
records: tuple[Correction, ...]
```

Correction records for these measured rows, including any sampling halo.

**Returns**

- *tuple of Correction*: Flat normalization, transmission steps, logarithm and line-integral steps.

**Raises**

- *ValueError*: If any corrected value is not finite.

## `check_rows` [#check_rows]

```python
check_rows(rows: tuple[int, int], native_rows: int, binning: int) -> None
```

<small>Defined in [src/tomojax/corrections/_validation.py:86](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/corrections/_validation.py#L86)</small>

Check a half-open row interval in the binned output.

**Parameters**

- **`rows`** (*tuple of int*): Requested start and exclusive stop.
- **`native_rows`** (*int*): Native detector height.
- **`binning`** (*int*): Number of native rows in an output row.

**Raises**

- *InvalidParameter*: If the interval lies outside complete detector blocks.

## `check_scan_steps` [#check_scan_steps]

```python
check_scan_steps(steps: Sequence[Step]) -> None
```

<small>Defined in [src/tomojax/corrections/_validation.py:17](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/corrections/_validation.py#L17)</small>

Check that a line-integral scan still has the domains required by each step.

**Parameters**

- **`steps`** (*sequence of Step*): Corrections in user-supplied order.

**Raises**

- *InvalidParameter*: If a step requires the original counts or transmission.

## `corrected_row_source` [#corrected_row_source]

```python
corrected_row_source(
    counts: Any,
    *,
    flats: Any,
    flat_positions: np.ndarray | None,
    darks: Any,
    white_level: float | None,
    steps: Sequence[Step],
    epsilon: float = 1e-06,
    view_positions: np.ndarray | None = None,
    exposure_times: np.ndarray | float | None = None,
    flat_exposure_times: np.ndarray | float | None = None,
    host: bool = False,
    dark_source: str | None = None,
    linear_limit: tuple[float, str] | None = None,
    flat_weights: FlatWeighting = FLAT_WEIGHTS,
) -> Iterator[Callable[[int, int], CorrectedRows | Corrected]]
```

<small>Defined in [src/tomojax/corrections/_rows.py:283](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/corrections/_rows.py#L283)</small>

Read corrected detector-row intervals without a materialized projection stack.

Each request returns owned projections, independent of later reads and
context closure. Only whole-row transmission and line-integral steps without view
selection are supported; operations requiring neighboring rows must run on full frames.
Raw inputs must be NumPy arrays or support lazy detector windows. The source
and calibration arrays must remain unchanged until this context closes.

**Parameters**

- **`counts`** (*array-like*): Detector counts with shape `(views, rows, columns)`. May be a lazy source.
- **`flats`** (*array-like or None*): Open-beam frames with shape `(frames, rows, columns)`, or None when
  white_level supplies the open-beam count.
- **`flat_positions`** (*numpy.ndarray or None*): Number of views recorded before each flat frame. Frames at the same
  position form one set; None puts all frames in one set.
- **`darks`** (*array-like or None*): Dark frames with shape `(frames, rows, columns)`; None uses zero dark.
- **`white_level`** (*float or None*): Positive open-beam count used when flats is None.
- **`steps`** (*sequence of Step*): Corrections, run by domain and in the supplied order within each domain.
- **`epsilon`** (*float, optional*): Positive transmission floor before the logarithm. Default is 1e-6.
- **`view_positions`** (*numpy.ndarray or None, optional*): Position of each view among the flats. Defaults to `i + 0.5` for view i.
- **`exposure_times`** (*numpy.ndarray or float or None, optional*): Sample exposure durations in seconds, one per view or a common duration.
- **`flat_exposure_times`** (*numpy.ndarray or float or None, optional*): Flat exposure durations in seconds, one per flat or a common duration.
- **`host`** (*bool, optional*): Return NumPy bands using bounded device view batches, instead of keeping
  the whole corrected band on the device. Default is False.
- **`dark_source`** (*str or None, optional*): What removed the dark before the counts were recorded (a camera that
  subtracts it, say), kept in the record as `dark_removed_by` in place of
  a count of dark frames. Default None.
- **`linear_limit`** (*tuple of (float, str) or None, optional*): The detector's stated linear range in counts and where it is stated. The
  record keeps the fraction of counts above it and the line integral where
  it ends, and a warning names both when any count lies above. Default None.
- **`flat_weights`** (*\{'views', 'position'\}, optional*): How a view between two flat sets blends them, as for
  [`tomojax.corrections.correct_frames`](https://tomojax.dev/api/corrections/#correct_frames).

**Yields**

- *callable*: Reader accepting a half-open row interval `(first, stop)` and returning
  corrected rows with their correction records. Use within a `with` block.

**Raises**

- *ValueError*: If steps require full frames or select views, or calibration or positions
  are invalid.
- *TypeError*: If counts lack detector-window access or a correction is not a Step.

## `positive_finite` [#positive_finite]

```python
positive_finite(value: float, name: str) -> float
```

<small>Defined in [src/tomojax/corrections/_validation.py:65](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/corrections/_validation.py#L65)</small>

Check a positive finite correction parameter.

**Parameters**

- **`value`** (*float*): Proposed value.
- **`name`** (*str*): Field to identify in an error.

**Returns**

- *float*: Validated value.

## `preview_window` [#preview_window]

```python
preview_window(
    steps: Sequence[Step],
    shape: tuple[int, int],
    lower: int,
    upper: int,
    factor: int,
) -> tuple[slice, tuple[Step, ...]]
```

<small>Defined in [src/tomojax/corrections/_rows.py:54](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/corrections/_rows.py#L54)</small>

Propagate complete native output blocks backwards across the ordered corrections.

**Parameters**

- **`steps`** (*sequence of Step*): Corrections in their supplied order.
- **`shape`** (*tuple of int*): Native detector rows and columns.
- **`lower`, `upper`** (*int*): Half-open row bounds in the binned output.
- **`factor`** (*int*): Native block size.

**Returns**

- *tuple*: Native input interval and its locally registered correction steps.

## `raw_cache_bytes` [#raw_cache_bytes]

```python
raw_cache_bytes(counts: np.ndarray | FrameStack) -> int
```

<small>Defined in [src/tomojax/corrections/_rows.py:178](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/corrections/_rows.py#L178)</small>

Estimate the bytes held in the raw reader's two cached blocks and its prefetch.

**Parameters**

- **`counts`** (*numpy.ndarray or FrameStack*): Raw acquisition in (view, row, column) order. A lazy stack supplies its
  shape and dtype without reading detector pixels.

**Returns**

- *int*: Bytes of resident counts for an array, or bytes of raw blocks cached
  for a file. In-flight transfers can retain older blocks.

## `slab_steps` [#slab_steps]

```python
slab_steps(steps: Sequence[Step]) -> list[tuple[str, Step]]
```

<small>Defined in [src/tomojax/corrections/_rows.py:258](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/corrections/_rows.py#L258)</small>

Check which corrections can run independently on complete detector rows.

**Parameters**

- **`steps`** (*sequence of Step*): Proposed raw corrections.

**Returns**

- *list of tuple*: Domain and step pairs in pipeline order.

## `validated_views_per_batch` [#validated_views_per_batch]

```python
validated_views_per_batch(value: int | None) -> int | None
```

<small>Defined in [src/tomojax/corrections/_validation.py:43](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/corrections/_validation.py#L43)</small>

Check the requested correction batch size.

**Parameters**

- **`value`** (*int or None*): Positive view count or automatic selection.

**Returns**

- *int or None*: Validated batch size.
