> ## 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.

# bioptimus.data.tile_spec

Tile specification dataclass.

Defines [`TileSpec`](https://docs.bioptimus.com/sdk-reference/data/tile_spec#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`](https://docs.bioptimus.com/sdk-reference/data/tile_spec#tilespec) is re-exported from `bioptimus.extraction.wsi.types`.

## TileSpec

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

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

**Attributes**:

* `size` - The size of the tile as `(width, height)` or a single integer for both dimensions.
* `stride` - The stride of the tile as `(stride_width, stride_height)` or a single integer for both dimensions.
* `resolution` - The resolution at which the tile is defined.
* `unit` - The unit of measurement for the tile dimensions.

**Example**:

```python 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.

**downsample\_ratio**

Ratio of the reference-level downsample to the target-resolution downsample.

**mpp**

Microns-per-pixel at the target resolution.

**Returns**:

A new `TileSpec` in reference-level pixels.

**Raises**:

* `ValueError` - If `unit` is not `PIXELS` or `UM`, or if the scaled size or stride rounds to zero (the requested geometry is finer than one reference-level pixel).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.