Skip to main content

SPatial Analysis for CodEX data (SPACEc)

Stars Downloads PyPI-Server Documentation Status Test Workflow DOI:10.1038/s41467-025-65658-3

Welcome to SPACEc 2.0

For the original release described in our 2025 publication, please refer to version 0.1.2.

Multiplexed imaging technologies offer valuable insights into intricate tissue structures, yet they pose significant computational hurdles. These include cumbersome data handoffs, inefficiencies in processing large images (often ranging from 8 to 40 gigabytes per image), and limited spatial analysis capabilities. We created SPACEc, an all-in-one, scalable Python platform that advances both analytical capabilities and computational efficiency. Through careful engineering optimization, it streamlines the entire process from image extraction and cell segmentation to data preprocessing, while introducing novel approaches such as Patch Proximity Analysis for mapping cellular microenvironments to fill in the current analytic gaps. The platform significantly improves the performance of existing tools through parallelization and GPU acceleration, including enhanced cell-cell interaction analysis and simplified deep-learning annotation workflows, while its intuitive user-friendly design makes these advanced spatial analyses accessible to a wider scientific audience.

General outline of SPACEc analysis

SPACEc

In-depth introduction to SPACEc

For an in-depth introduction to SPACEc v0.1.2, take a look at this YouTube video.

Installation notes

Note: We currently support Python 3.10–3.12, and test against 3.12.

  • The example tonsil data is available on dryad
  • The extensive tutorial is available here
  • The original SPACEc version (0.1.2), as used in the publication, is available here

Upgrading from an older SPACEc? You no longer need to install graphviz, libvips or openslide from conda-forge, apt or brew. pip install spacec now pulls all three in as wheels (pygraphviz, pyvips[binary], openslide-bin), so a plain virtualenv works and conda is optional.

If an older system libvips is still installed and import spacec fails with OSError: cannot load library 'libvips.42', rebuild pyvips with the stray copy hidden:

    PKG_CONFIG_PATH=/nonexistent PKG_CONFIG_LIBDIR=/nonexistent \
        pip install --no-cache-dir --force-reinstall "pyvips[binary]"

Install

Linux

SPACEc CPU

    # Create virtual environment (conda create -n spacec python=3.12 works as well)
    python3.12 -m venv spacec-env
    source spacec-env/bin/activate

    # Install spacec
    pip install spacec

Continue the following steps only if you have GPU(s)

SPACEc GPU

No separate CUDA installation is needed. The PyTorch wheels installed with SPACEc ship their own CUDA runtime and cuDNN.

  1. OPTIONAL: For GPU-accelerated clustering via RAPIDS run the following. Note that only RTX20XX or better GPUs are supported. More information on rapids-singlecell are available here: https://rapids-singlecell.readthedocs.io/en/latest/Installation.html
    # Check which CUDA your torch was built against:
    python -c "import torch; print(torch.version.cuda)"

    # CUDA 13:
    pip install 'spacec[rapids13]' --extra-index-url=https://pypi.nvidia.com

    # CUDA 12:
    pip install 'spacec[rapids12]' --extra-index-url=https://pypi.nvidia.com
  1. OPTIONAL: To use STELLAR run the following (or run sp.tl.install_stellar()):
    pip install 'spacec[stellar]'
    pip install torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-2.5.1+cpu.html   # or +cu124 etc.
    pip install git+https://github.com/TKempchen/stellar-py3.12
  1. OPTIONAL: To use the legacy louvain clustering backend (Python <= 3.11 only) run the following:
    pip install 'spacec[legacy]'
  1. Test if SPACEc loads and if your GPU is visible:
    python -c "import spacec as sp; sp.hf.check_for_gpu()"
    
Apple M1/M2/M3/M4

SPACEc CPU:

    # Create virtual environment (conda create -n spacec python=3.12 works as well)
    python3.12 -m venv spacec-env
    source spacec-env/bin/activate

    # Install spacec
    pip install spacec

Homebrew vips, openslide and graphviz are no longer needed.

SPACEc GPU: Mac GPU support can be limited depending on your PyTorch/Cellpose setup (in some cases we try to use the MPS backend if possible but that can be tricky). We recommend to use a Linux system for full GPU acceleration.

SPACEc supports both classic Cellpose (cyto3) and Cellpose-SAM (cpsam, cellpose>=4) for cell segmentation — see docs/cellpose_models.md for how to choose and switch between them.

Windows

Although SPACEc can run directly on Windows systems, we highly recommend running it in WSL. If you are unfamiliar with WSL, you can find more information on how to use and install it here: https://learn.microsoft.com/en-us/windows/wsl/install If you decide to use WSL, follow the Linux instructions.

If you plan to continue with the native Windows environment

  1. One of the segmentation tools within SPACEc neeeds a C++ compiler. If your environment doesn't have it already, the easiest way is to:
    1. Download the community version of Visual Studio from the official Microsoft website: https://visualstudio.microsoft.com. After installing the software on your system, select the following options to install the components needed for C++ development (see screenshots)

      image

      image 1

    2. That is the only manual prerequisite. libvips and Graphviz are installed automatically as wheels — you no longer need to download vips-dev-w64-all or edit your PATH.

SPACEc CPU:

    # Create virtual environment (conda create -n spacec python=3.12 works as well)
    py -3.12 -m venv spacec-env
    spacec-env\Scripts\activate

    # Install spacec
    pip install spacec

SPACEc GPU:

No separate CUDA installation is needed — the PyTorch wheels ship their own CUDA runtime and cuDNN.

    # If Pytorch does not find the GPU, reinstall it against a specific CUDA build:
    # pip install torch --index-url https://download.pytorch.org/whl/cu121

Test if SPACEc loads and if your GPU is visible if you installed the GPU version.

    import spacec as sp
    sp.hf.check_for_gpu()
Docker If you encounter installation issues or prefer a containerized setup, use the SPACEc Docker image. You can build or modify it using the repository's Dockerfiles.

Run these from the repository root:

# Run CPU version:
docker build -f Docker/spacec_cpu_build.dockerfile -t spacec:cpu .
docker run -p 127.0.0.1:8888:8888 -p 127.0.0.1:5100:5100 spacec:cpu

# If running an amd64 image on apple silicon, use the following command:
docker run --platform linux/amd64 -p 127.0.0.1:8888:8888 -p 127.0.0.1:5100:5100 spacec:cpu

# Or run GPU version:
docker build -f Docker/spacec_gpu_build.dockerfile -t spacec:gpu .
docker run --gpus all -p 127.0.0.1:8888:8888 -p 127.0.0.1:5100:5100 spacec:gpu

License

SPACEc is distributed under the Stanford Academic Software License for non-commercial academic use only. See LICENSE.txt for the full terms. For commercial use, contact Stanford's Office of Technology Licensing.

If you use SPACEc in your research, please cite the SPACEc publication: doi:10.1038/s41467-025-65658-3.

Metadata

Release files for SPACEc 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for SPACEc 2.0.0
File Size Uploaded Provenance Actions
spacec-2.0.0.tar.gz 332.4 kB Without provenance Details for spacec-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for SPACEc 2.0.0
File Interpreter ABI Platform Actions
spacec-2.0.0-py3-none-any.whl Python 3 none any Details for spacec-2.0.0-py3-none-any.whl

Total release size: 653.9 kB

Release files / spacec-2.0.0.tar.gz

Download URL spacec-2.0.0.tar.gz
Size 332.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1991cffd5f5ca597ac67a8c07c169e76fba5588b66b732c81f46188053808a89
BLAKE2b-256 checksum
How to use checksums
1e91a78c5c14cc1b232308b64f8e699391a5061cf51b7195bd9f370a3462332a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / spacec-2.0.0-py3-none-any.whl

Download URL spacec-2.0.0-py3-none-any.whl
Size 321.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
279f61aeb90e4ca1e549c8a34cf025062fb8562ce1fd7d5bb31e6163aa381bd6
BLAKE2b-256 checksum
How to use checksums
d03206bae64f211a036d1b7bad99c4146b4aac20f9ba06da90340407519c9ef0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for SPACEc 2.0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page