SpatialExperiment
A Python package for storing and analyzing spatial-omics experimental data. SpatialExperiment extends SingleCellExperiment with dedicated slots for image data and spatial coordinates, making it ideal for spatial transcriptomics and other spatially-resolved omics data.
Install
To get started, install the package from PyPI
pip install spatialexperiment
Usage
The SpatialExperiment class extends SingleCellExperiment with the following key attributes:
-
spatial_coords: A BioFrame containing spot/cell spatial coordinates relative to the image, typically including:- x-coordinates
- y-coordinates
- Additional spatial metadata
-
img_data: A BiocFrame containing image-related information:- sample_ids: Unique identifiers for each sample
- image_ids: Unique identifiers for each image
- data: The actual image data
- scale_factor: Scaling factors for proper image interpretation
-
column_data: Contains sample_id mappings that link spots to their corresponding images
Quick Start
Here's how to create a SpatialExperiment object from scratch:
from spatialexperiment import SpatialExperiment, construct_spatial_image_class
import numpy as np
from biocframe import BiocFrame
# Create example data
nrows = 200 # Number of features (e.g., genes)
ncols = 500 # Number of spots/cells
# Generate random count data
counts = np.random.rand(nrows, ncols)
# Create feature annotations
row_data = BiocFrame({
"gene_ids": [f"gene_{i}" for i in range(nrows)],
"gene_names": [f"Gene_{i}" for i in range(nrows)]
})
# Create spot/cell annotations
col_data = BiocFrame({
"n_genes": [50, 200] * int(ncols / 2),
"condition": ["healthy", "tumor"] * int(ncols / 2),
"cell_id": [f"spot_{i}" for i in range(ncols)],
"sample_id": ["sample_1"] * int(ncols / 2) + ["sample_2"] * int(ncols / 2),
})
# Generate spatial coordinates
spatial_coords = BiocFrame({
"x": np.random.uniform(low=0.0, high=100.0, size=ncols),
"y": np.random.uniform(low=0.0, high=100.0, size=ncols)
})
# Create image data
img_data = BiocFrame({
"sample_id": ["sample_1", "sample_1", "sample_2"],
"image_id": ["aurora", "dice", "desert"],
"data": [
construct_spatial_image_class("tests/images/sample_image1.jpg"),
construct_spatial_image_class("tests/images/sample_image2.png"),
construct_spatial_image_class("tests/images/sample_image3.jpg"),
],
"scale_factor": [1, 1, 1],
})
# Create SpatialExperiment object
spe = SpatialExperiment(
assays={"counts": counts},
row_data=row_data,
column_data=col_data,
spatial_coords=spatial_coords,
img_data=img_data,
)
For more detailed information about available methods and functionality, please refer to the SingleCellExperiment documentation.
Note
This project has been set up using BiocSetup and PyScaffold.
Metadata
Release files for spatialexperiment 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spatialexperiment-0.2.0.tar.gz | 3.6 MB | With provenance | Details for spatialexperiment-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spatialexperiment-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for spatialexperiment-0.2.0-py3-none-any.whl |
Total release size: 3.7 MB
Release files / spatialexperiment-0.2.0.tar.gz
| Download URL | spatialexperiment-0.2.0.tar.gz |
|---|---|
| Size | 3.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ac019a0c3581b2fddca3db4d71e9c1b3dc70c40d9852eb68b96388f3eadb532c
|
|
BLAKE2b-256 checksum How to use checksums |
ed0ddec3cd6c872c40391412ea4d9018cf80cfbeb40cdb607c4e6a0ad3e7e3c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.
Transparency logRelease files / spatialexperiment-0.2.0-py3-none-any.whl
| Download URL | spatialexperiment-0.2.0-py3-none-any.whl |
|---|---|
| Size | 27.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
287dfbcdf41273be73e14f7867657fee05f28ca481e656e3c72311e51e5f9893
|
|
BLAKE2b-256 checksum How to use checksums |
db0c080911a11c6f80978c44d21b70464038c6b0494137d945097b93ec0014c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.
Transparency logSecurity for spatialexperiment 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for spatialexperiment-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.