// SpatialData framework for handling spatial multi-modal and multi-scale data. Use this skill for questions about spatial omics data analysis, visualization, and the SpatialData Python ecosystem.
| name | spatialdata |
| description | SpatialData framework for handling spatial multi-modal and multi-scale data. Use this skill for questions about spatial omics data analysis, visualization, and the SpatialData Python ecosystem. |
Comprehensive assistance with SpatialData development, generated from official documentation.
This skill should be triggered when:
Data Analysis & Visualization:
Framework Implementation:
Technical Operations:
Ecosystem Integration:
1. Load and explore sample dataset
from spatialdata.datasets import blobs
sdata = blobs()
print(sdata)
# Shows all elements: images, labels, points, shapes, tables
2. Access element instances and properties
# Get unique label instances
from spatialdata import get_element_instances
instances = get_element_instances(sdata["blobs_multiscale_labels"])
# Get image channels
from spatialdata.models import get_channels
channels = get_channels(sdata["blobs_multiscale_image"])
3. Work with coordinate transformations
# Set image channels
from spatialdata.models import Image2DModel
sdata["blobs_image"] = Image2DModel.parse(
sdata["blobs_image"],
c_coords=["r", "g", "b"]
)
4. Retrieve annotation values from elements
from spatialdata import get_values
# Get values from points element
genes = get_values(value_key="genes", element=sdata["blobs_points"])
# Get values from table annotations
channel_values = get_values(
value_key="channel_0_sum",
sdata=sdata,
element_name="blobs_labels",
table_name="table"
)
5. Create and manage annotation tables
from anndata import AnnData
from spatialdata.models import TableModel
# Create table without spatial annotation
codebook_table = AnnData(obs={
"Gene": ["Gene1", "Gene2", "Gene3"],
"barcode": ["03210", "23013", "30121"]
})
sdata["codebook"] = TableModel.parse(codebook_table)
# Create table annotating multiple elements
table = TableModel.parse(
adata,
region=["blobs_polygons", "blobs_points"],
region_key="region",
instance_key="instance_id"
)
6. Query data by spatial regions
from spatialdata import bounding_box_query, polygon_query
# Bounding box query
result = sdata.query.bounding_box(
axes=("y", "x"),
min_coordinate=[100, 100],
max_coordinate=[200, 200],
target_coordinate_system="global"
)
# Polygon query
from shapely.geometry import Polygon
polygon = Polygon([(0, 0), (10, 0), (10, 10), (0, 10)])
result = sdata.query.polygon(polygon, target_coordinate_system="global")
7. Join spatial elements with tables
from spatialdata import join_spatialelement_table
# SQL-like join between elements and annotation tables
element_dict, filtered_table = join_spatialelement_table(
sdata=sdata,
spatial_element_names="blobs_polygons",
table_name="annotations",
how="left",
match_rows="left"
)
8. Parse and validate different data types
from spatialdata.models import (
Image2DModel, Labels2DModel,
PointsModel, ShapesModel
)
# Parse and validate 2D image
image = Image2DModel.parse(
data=numpy_array,
c_coords=["channel1", "channel2"],
transformations={"global": Identity()}
)
# Parse points from DataFrame
points = PointsModel.parse(
data=dataframe,
coordinates={"x": "x_col", "y": "y_col"},
feature_key="gene_id"
)
# Parse shapes from GeoDataFrame
shapes = ShapesModel.parse(geodataframe)
Content: Installation guide and basic setup
Content: Comprehensive API documentation
Content: Design document and advanced concepts
Content: Glossary and terminology
Content: General information and links
Beginner workflow:
# 1. Install and load
pip install spatialdata
from spatialdata.datasets import blobs
# 2. Explore the data structure
sdata = blobs()
print(sdata)
# 3. Access specific elements
points = sdata["blobs_points"]
labels = sdata["blobs_labels"]
# 4. Basic operations
from spatialdata import get_values
values = get_values("genes", element=points)
Intermediate workflow:
# 1. Create your own annotation tables
from spatialdata.models import TableModel
table = TableModel.parse(adata, region="my_labels")
# 2. Perform spatial queries
result = sdata.query.bounding_box(...)
# 3. Join data with annotations
from spatialdata import join_spatialelement_table
elements, table = join_spatialelement_table(...)
# 4. Work with coordinate systems
sdata.transform_to("global", "new_system")
Advanced workflow:
# 1. Create custom elements with specific transformations
from spatialdata.models import Image2DModel
image = Image2DModel.parse(
data,
transformations={"custom": Translation([100, 100])}
)
# 2. Optimize large datasets
# Use chunking, multi-scale representations
# Implement custom spatial indexes
# 3. Extend the framework
# Create custom models, readers, or visualization tools
To refresh this skill with updated documentation: