> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bioptimus.com/llms.txt
> Use this file to discover all available pages before exploring further.

# tile_spec

Tile specification dataclass.

Defines `TileSpec`, a pure data structure describing tile geometry (size, stride, resolution, measurement unit).  This module lives in the data layer so it can be imported by both `bioptimus.extraction` and `bioptimus.models` without creating circular dependencies.

For backward compatibility, `TileSpec` is re-exported from `types`.

## TileSpec

```python theme={null}
@dataclass(frozen=True)
class TileSpec()
```

Defines the specifications of a tile within a WSI for extraction.

<ParamField body="size">
  The size of the tile as `(width, height)` or a single integer for both dimensions.
</ParamField>

<ParamField body="stride">
  The stride of the tile as `(stride_width, stride_height)` or a single integer for both dimensions.
</ParamField>

<ParamField body="resolution">
  The resolution at which the tile is defined.
</ParamField>

<ParamField body="unit">
  The unit of measurement for the tile dimensions.
</ParamField>

**Example**:

```pycon theme={null}
>>> spec = TileSpec(
...     size=(256, 256), stride=(128, 128),
...     resolution=Resolution(level=0),
...     unit=MeasurementUnit.PIXELS,
... )
>>> print(spec.size)
(256, 256)
```

#### size

(width, height)

#### stride

(stride\_width, stride\_height)

#### width

```python theme={null}
@property
def width() -> int
```

Returns the tile width.

#### height

```python theme={null}
@property
def height() -> int
```

Returns the tile height.

#### stride\_width

```python theme={null}
@property
def stride_width() -> int
```

Returns the horizontal stride.

#### stride\_height

```python theme={null}
@property
def stride_height() -> int
```

Returns the vertical stride.

#### scale\_to\_reference

```python theme={null}
def scale_to_reference(downsample_ratio: float, mpp: MPP) -> TileSpec
```

Returns a new TileSpec scaled to reference-level pixels.

<ParamField body="downsample_ratio" type="float" required>
  Ratio of the reference-level downsample to the target-resolution downsample.
</ParamField>

<ParamField body="mpp" type="MPP" required>
  Microns-per-pixel at the target resolution.
</ParamField>

<ResponseField name="returns" type="TileSpec">
  A new `TileSpec` in reference-level pixels.
</ResponseField>

**Raises:**

* `ValueError` — If `unit` is not `PIXELS` or `UM`.
