toSpatialData
toSpatialData ¶
toSpatialData(
data,
imageId="imageid",
xCoordinate="X_centroid",
yCoordinate="Y_centroid",
radius=None,
area="Area",
instanceKey="CellID",
regionKey=None,
tableName="table",
outputDir=None,
verbose=True,
sdataTable=None,
)
Convert a cell table into a scverse SpatialData.
One circles element is created per image, holding that image's cell centroids,
and the whole table is attached to those elements as a SpatialData table.
Every obs column is preserved, so a z-coordinate or any other metadata
survives the conversion even though the geometry itself is two-dimensional.
A SpatialData passed in is returned unchanged, which makes the call safe to
leave at the top of a pipeline that might receive either kind of input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
(AnnData | SpatialData | str, required)
|
The cell table. An |
required |
imageId
|
str
|
Column in |
'imageid'
|
xCoordinate
|
str
|
Column in |
'X_centroid'
|
yCoordinate
|
str
|
Column in |
'Y_centroid'
|
radius
|
str | float
|
Circle radius: an |
None
|
area
|
str
|
Column in |
'Area'
|
instanceKey
|
str
|
Column in |
'CellID'
|
regionKey
|
str
|
Column in |
None
|
tableName
|
str
|
Name for the table inside the new |
'table'
|
outputDir
|
str
|
When given, the store is written as |
None
|
verbose
|
bool
|
Print progress messages. |
True
|
sdataTable
|
str
|
Which table to use when |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
sdata |
SpatialData | None
|
The new store, or |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Example
# Radius derived from obs['Area'].
sdata = sp.pp.toSpatialData(adata)
sdata.tables["table"]
# Write a store instead of returning one.
sp.pp.toSpatialData(adata, outputDir="converted")
# A fixed radius, and a custom table name.
sdata = sp.pp.toSpatialData(adata, radius=5, tableName="cells")
# Everything downstream then works on the store.
sdata = sp.tl.spatialDistance(sdata, sdataTable="cells")