sddb.loader.StainNormalize#
- class sddb.loader.StainNormalize(method: Literal['macenko'] = 'macenko', *, reference: StainFit | None = None)#
Normalise H&E stains to one reference with squidpy's stain module.
fit()pools the tissue pixels of a cohort's items into one reference (fit_stain_reference());referenceoverrides it.build()applies it lazily per block (transform(), uint8 out, background kept) and records it initem.stain_referenceforDatasetContract.stain_reference.Both run squidpy on the source image's coarsest level, which
Rasterizekeeps on the item, with the tissue maskTissueMaskfound on that level.fit()passes every item's level and mask in one SpatialData withscale="auto"(squidpy fits on the coarsest level and takes the mask scale closest to it,_stain/_normalize.py_resolve_fit_inputs); each item weighs in proportion to its tissue area there. The level and its shape per item are recorded asfit_inputs.build()passes a two-entry multiscale image (the written image, then the source level) and the matching tissue masks:transformnormalises the finest entry and takes each image's own stain statistics from the coarsest, so nothing is downsampled from the written grid. The two entries are not one pyramid (the written grid may be rotated against the source); squidpy uses the coarse one only for statistics, paired with its own mask.- Parameters:
- method
The squidpy method;
"macenko".- reference
A fitted reference to apply instead of fitting one.
- Raises:
ValueError -- In
fit()andbuild(), on an IF item, an item withoutlabels["tissue"], or (inbuild()) without a reference.
Attributes table#
Methods table#
build(sdata)Return the item with the normalised image (uint8, lazy).
fit(items)Fit one reference on the pooled tissue pixels of
items, keep it asreferenceand return it.from_record(rec)Rebuild the step, and its reference if the record has one.
An H&E item with
labels["tissue"].The step as an
AdapterRecordthatfrom_record()rebuilds.validate(sdata)Require an H&E item with a tissue mask.
validate_meta(meta)No catalog metadata decides these steps; the checks run on the item in
validate().Attributes#
- FITTED: ClassVar[tuple[str, ...]] = ('reference', 'fit_inputs')#
The params a fit adds to the record.
Methods#
- build(sdata: LoaderItem) LoaderItem#
Return the item with the normalised image (uint8, lazy).
- fit(items: Sequence[LoaderItem]) StainFit#
Fit one reference on the pooled tissue pixels of
items, keep it asreferenceand return it.
- classmethod from_record(rec: AdapterRecord) Self#
Rebuild the step, and its reference if the record has one.
- to_record() AdapterRecord#
The step as an
AdapterRecordthatfrom_record()rebuilds.
- validate(sdata: LoaderItem) list[str]#
Require an H&E item with a tissue mask.
- validate_meta(meta: ObjectMeta) list[str]#
No catalog metadata decides these steps; the checks run on the item in
validate().