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)
Validation
from morph_spines import validate_morph_with_spines_file
# Check file structure only (groups, datasets, metadata)
result = validate_morph_with_spines_file("neuron.h5")
# Also check data integrity (shapes, dtypes, value ranges, cross-references)
result = validate_morph_with_spines_file("neuron.h5", check_data_integrity=True)
print(result) # Human-readable summary
assert result.is_valid # Use programmatically
### Merging
```python
from pathlib import Path
from morph_spines import merge_morphologies_with_spines
# Merge multiple files without renaming
merge_morphologies_with_spines(
source_files=[Path("neuron_A.h5"), Path("neuron_B.h5")],
output_path=Path("merged.h5"),
)
# Merge with renaming (neuron keys and/or spines library names)
src1 = Path("neuron_A.h5")
src2 = Path("neuron_B.h5")
merge_morphologies_with_spines(
source_files=[src1, src2],
output_path=Path("merged.h5"),
rename_map={
(src1, "morph_001"): "circuit_neuron_42",
(src2, "morph_001"): "circuit_neuron_43",
},
)
# Merge without meshes (smaller output)
merge_morphologies_with_spines(
source_files=[Path("a.h5"), Path("b.h5")],
output_path=Path("merged_no_meshes.h5"),
include_meshes=False,
)
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
- Merge multiple morph-with-spines files into one, with optional renaming of neuron keys and spines library names
- 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
- Validate entire morph-with-spines files (structure and optionally data integrity)
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file morph_spines-1.1.0.tar.gz.
File metadata
- Download URL: morph_spines-1.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fba112f32392775891351f34f3428c28acae287c2137b5b96d8865aacd97ef31
|
|
| MD5 |
09f3345f7dd7b88825284841ebd6f04b
|
|
| BLAKE2b-256 |
3c46f546554344a5cc2f918dcb463ca34f4cc11356f7c649a5c891344f427b2b
|
Provenance
The following attestation bundles were made for morph_spines-1.1.0.tar.gz:
Publisher:
publish.yml on openbraininstitute/morph-spines
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
morph_spines-1.1.0.tar.gz -
Subject digest:
fba112f32392775891351f34f3428c28acae287c2137b5b96d8865aacd97ef31 - Sigstore transparency entry: 1924998880
- Sigstore integration time:
-
Permalink:
openbraininstitute/morph-spines@ef5ae1f294ed3a43f3f22f52a19455d4e4c9b072 -
Branch / Tag:
refs/tags/1.1.0 - Owner: https://github.com/openbraininstitute
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ef5ae1f294ed3a43f3f22f52a19455d4e4c9b072 -
Trigger Event:
release
-
Statement type:
File details
Details for the file morph_spines-1.1.0-py3-none-any.whl.
File metadata
- Download URL: morph_spines-1.1.0-py3-none-any.whl
- Upload date:
- Size: 37.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2b651c5f5bfc901c518af714c189c11b49dbc211b7c7c76eb5ba68afaf47531
|
|
| MD5 |
8ede94f2231d05cf447da5a48414c55f
|
|
| BLAKE2b-256 |
1f11c2453af42fbd06d10d1843c8a62030109ceade0879768a0d1c68d3347134
|
Provenance
The following attestation bundles were made for morph_spines-1.1.0-py3-none-any.whl:
Publisher:
publish.yml on openbraininstitute/morph-spines
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
morph_spines-1.1.0-py3-none-any.whl -
Subject digest:
e2b651c5f5bfc901c518af714c189c11b49dbc211b7c7c76eb5ba68afaf47531 - Sigstore transparency entry: 1924999082
- Sigstore integration time:
-
Permalink:
openbraininstitute/morph-spines@ef5ae1f294ed3a43f3f22f52a19455d4e4c9b072 -
Branch / Tag:
refs/tags/1.1.0 - Owner: https://github.com/openbraininstitute
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ef5ae1f294ed3a43f3f22f52a19455d4e4c9b072 -
Trigger Event:
release
-
Statement type: