sddb.loader.Rasterize#

class sddb.loader.Rasterize(mpp: float | None, *, allow_upsample: bool = False, tile: int = 4096, value_range: Sequence[float] | None = None)#

Resample the image and the cells onto the written grid.

The written grid is axis-aligned in the coordinate system the image shares with the cells and covers the image's footprint there, so any rotation or affine of the image is baked in. Its pixel is mpp microns (the "target" grid) or, without mpp or with an unknown mpp_native, the size of an image pixel (the "native" grid, native_to_written = 1).

The image is resampled (order 1) from the coarsest multiscale level whose mpp is still at most mpp, and converted to the role's dtype by a rule recorded in item.dtype_rule (see value_range). An H&E source is already 3-channel uint8 (LoaderItem.from_sdata() drops a constant alpha and refuses anything else), so only an IF source is converted to uint16. Outside the image's footprint the written image is glass (255) for H&E and 0 for IF. Existing labels are resampled with order 0; otherwise the shapes the table annotates are rasterised once, filled, with each row's obs["label_id"], one tile of tile x tile pixels at a time.

Parameters:
mpp

Microns per pixel of the target grid, or None for the native grid.

allow_upsample

Allow a target finer than the native grid (mpp_native / mpp > 1). Without it any such factor raises.

tile

Chunk side of the written image and labels, and of the rasterisation tiles.

value_range

(lo, hi) of the source pixels, mapped linearly onto the role's dtype (lo to 0, hi to its max). Without it, a source already in the role's dtype passes through, and any other source must fit its dtype's natural range, judged from the min and max of the coarsest pyramid level: a float in [0, 1] is scaled to the role's max, an integer whose values fit the role's dtype keeps them. Anything else raises and asks for value_range.

Attributes table#

config

The constructor kwargs.

name

version

Methods table#

build(sdata)

Return the item on the written grid, with labels["cells"].

from_record(rec)

Rebuild the step from to_record()'s output.

requirements()

An item fresh from LoaderItem.from_sdata().

to_record()

The step as an AdapterRecord that from_record() rebuilds.

validate(sdata)

Refuse an item that was already rasterised, and upsampling unless it is allowed.

validate_meta(meta)

No catalog metadata decides these steps; the checks run on the item in validate().

Attributes#

property config: dict[str, Any]#

The constructor kwargs.

name: ClassVar[str] = 'Rasterize'#
version: ClassVar[str] = '0.1.0'#

Methods#

build(sdata: LoaderItem) → LoaderItem#

Return the item on the written grid, with labels["cells"].

classmethod from_record(rec: AdapterRecord) → Self#

Rebuild the step from to_record()'s output.

Raises:

ValueError -- If the record is of another adapter or another version.

requirements() → dict[str, Any]#

An item fresh from LoaderItem.from_sdata().

to_record() → AdapterRecord#

The step as an AdapterRecord that from_record() rebuilds.

validate(sdata: LoaderItem) → list[str]#

Refuse an item that was already rasterised, and upsampling unless it is allowed.

validate_meta(meta: ObjectMeta) → list[str]#

No catalog metadata decides these steps; the checks run on the item in validate().