spatialdata.models.Labels2DModel#
- class spatialdata.models.Labels2DModel(*args, **kwargs)#
Attributes table#
Methods table#
Attributes#
- Labels2DModel.ATTRS_KEY = 'spatialdata_attrs'#
- Labels2DModel.array_type = <xarray_schema.components.ArrayTypeSchema object>#
- Labels2DModel.attrs = <xarray_schema.components.AttrsSchema object>#
- Labels2DModel.checks#
- Labels2DModel.chunks#
- Labels2DModel.coords#
- Labels2DModel.dims = <xarray_schema.components.DimsSchema object>#
- Labels2DModel.dtype#
- Labels2DModel.json#
- Labels2DModel.name#
- Labels2DModel.shape#
Methods#
- classmethod Labels2DModel.parse(*args, **kwargs)#
Validate (or parse) raster data.
- Parameters:
data – Data to validate (or parse). The shape of the data should be c(z)yx for 2D (3D) images and (z)yx for 2D ( 3D) labels. If you have a 2D image with shape yx, you can use
numpy.expand_dims()
(or an equivalent function) to add a channel dimension.dims – Dimensions of the data (e.g. [‘c’, ‘y’, ‘x’] for 2D image data). If the data is a
xarray.DataArray
, the dimensions can also be inferred from the data. If the dimensions are not in the order (c)(z)yx, the data will be transposed to match the order.transformations – Dictionary of transformations to apply to the data. The key is the name of the target coordinate system, the value is the transformation to apply. By default, a single
Identity
transformation mapping to the"global"
coordinate system is applied.scale_factors – Scale factors to apply to construct a multiscale image (
datatree.DataTree
). IfNone
, axarray.DataArray
is returned instead. Importantly, each scale factor is relative to the previous scale factor. For example, if the scale factors are[2, 2, 2]
, the returned multiscale image will have 4 scales. The original image and then the 2x, 4x and 8x downsampled images.method – Method to use for multiscale downsampling. Please refer to
multiscale_spatial_image.to_multiscale
.chunks – Chunks to use for dask array.
kwargs (
Any
) – Additional arguments forto_spatial_image()
. In particular thec_coords
kwargs argument (an iterable) can be used to set the channel coordinates for image data.c_coords
is not available for labels data as labels do not have channels.
- Return type:
DataArray
|DataTree
- Returns:
:
xarray.DataArray
ordatatree.DataTree
Notes
RGB images
If you have an image with 3 or 4 channels and you want to interpret it as an RGB or RGB(A) image, you can use the
c_coords
argument to specify the channel coordinates as["r", "g", "b"]
or["r", "g", "b", "a"]
.You can also pass the
rgb
argument tokwargs
to automatically set thec_coords
to["r", "g", "b"]
. Please refer toto_spatial_image()
for more information. Note: if you setrgb=None
inkwargs
, 3-4 channel images will be interpreted automatically as RGB(A) images.
- Labels2DModel.to_json(**dumps_kws)#
- Return type:
str
- Labels2DModel.validate(data)#
Validate data.
- Parameters:
data (
Any
) – Data to validate.- Raises:
ValueError – If data is not valid.
- Return type:
None