Skip to main content

Package to load and write morphologies with spines

Project description

morph-spines

A Python library for loading, writing, and accessing neuron morphologies with dendritic spine data from HDF5 files. It provides structured access to spine skeletons, meshes, and spatial transformations.

Quick example

Loading

from morph_spines import load_morphology_with_spines

m = load_morphology_with_spines("neuron.h5", spines_are_centered=True, load_meshes=True)

# Access spine meshes
mesh = m.spines.spine_mesh(0)
print(mesh.vertices.shape, mesh.faces.shape)

# Get only the head region of a spine
head_mesh = m.spines.spine_mesh(0, include_neck=False)

# Spine type classification
spine_type = m.spines.spine_type(0)

Writing

from morph_spines import write_spine_table, write_morphology, write_soma_mesh

# Write a spine table (pandas DataFrame with mandatory columns)
write_spine_table("output.h5", "neuron_01", spine_table_df)

# Write neuron morphology skeleton
write_morphology("output.h5", "neuron_01", points, structure)

# Write soma mesh
write_soma_mesh("output.h5", "neuron_01", vertices, triangles)

Installation

pip install morph-spines

For development:

git clone https://github.com/openbraininstitute/morph-spines.git
cd morph-spines
pip install -e ".[test]"

Features

  • Load and write neuron morphologies with spine data from/to HDF5 files
  • Access the spine table with per-spine properties (position, orientation, section placement)
  • Access spine skeletons (via NeuroM/MorphIO) and meshes (via trimesh)
  • Write spine tables, morphologies, soma meshes, spine meshes, and spine skeletons
  • Validate spine tables against the format specification before writing
  • Head/neck triangle classification with filtering (include_head, include_neck)
  • Support for branched spines with multiple heads
  • Spine type classification (thin, mushroom, stubby, filopodium, branched, etc.)
  • Lazy or eager mesh loading
  • Coordinate transformations between local spine and global neuron frames

Upgrading from v0.x

Version 1.0 drops support for reading spine tables stored as pandas DataFrames (v0.1 format) inside HDF5 files. If you have files in the old format, convert them before loading:

python scripts/h5_dataframe_to_h5_datasets_group.py old_file.h5 new_file.h5

The conversion script requires the tables package:

pip install morph-spines[scripts]

File format

The morphology-with-spines format is documented in examples/data/README.md.

Development

Run tests:

pytest

Lint:

ruff check src/ tests/

Type check:

mypy src/

Examples

See the examples/ folder for Jupyter notebooks demonstrating visualization and usage.

License

Copyright (c) 2025-2026 Open Brain Institute.

Licensed under Apache-2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

morph_spines-1.0.0.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

morph_spines-1.0.0-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

Details for the file morph_spines-1.0.0.tar.gz.

File metadata

  • Download URL: morph_spines-1.0.0.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for morph_spines-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bab671305a72696fadf4f19c12e67bc0426fd113cfeb3e1e852788f28bc258de
MD5 287ec68a54c52c91ef2625a5cb56ce65
BLAKE2b-256 7a6770841506f9c3880e05d22490a6b867addaa3202432b5eb828b85c37f7f5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for morph_spines-1.0.0.tar.gz:

Publisher: publish.yml on openbraininstitute/morph-spines

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file morph_spines-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: morph_spines-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 24.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for morph_spines-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6f206628edae0e951df012be64cf614916f401f1675a845b5ed60f3c1980516f
MD5 0917535ff88741c8adcb5f759d56b75d
BLAKE2b-256 42ea0c5cad94ec78dbafc5a657d5a623a13653b9e227bfcafc2a3eb7a2372f42

See more details on using hashes here.

Provenance

The following attestation bundles were made for morph_spines-1.0.0-py3-none-any.whl:

Publisher: publish.yml on openbraininstitute/morph-spines

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page