brainglobe-space

Anatomical space conventions made easy.

https://github.com/brainglobe/brainglobe-space

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 2 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.5%) to scientific vocabulary
Last synced: 10 months ago · JSON representation ·

Repository

Anatomical space conventions made easy.

Basic Info
  • Host: GitHub
  • Owner: brainglobe
  • License: bsd-3-clause
  • Language: Python
  • Default Branch: main
  • Size: 365 KB
Statistics
  • Stars: 10
  • Watchers: 4
  • Forks: 7
  • Open Issues: 2
  • Releases: 6
Created about 6 years ago · Last pushed 11 months ago
Metadata Files
Readme License Citation

README.md

Python Version PyPI Downloads Wheel Development Status Tests codecov Code style: black Imports: isort pre-commit Contributions Twitter License: GPL v3 DOI

brainglobe-space

Anatomical space conventions made easy.

Working with anatomical images, one often encounters the problem of matching the orientation of stacks with different conventions about axes orientation and order. Moreover, when multiple swaps and flips are involved, it can be annoying to map the same transformations to volumes and points (e.g., coordinates or meshes).

brainglobe-space provides a neat way of defining an anatomical space, and of operating stacks and point transformations between spaces.

Installation

You can install brainglobe-space with:

bash pip install brainglobe-space

Usage

To define a new anatomical space, it is sufficient to give the directions of the stack origin position:

python source_origin = ("Left", "Superior", "Anterior") target_origin = ("Inferior", "Posterior", "Right")

A stack can be then easily transformed from the source to the target space:

```python import brainglobe_space as bg import numpy as np stack = np.random.rand(3, 2, 4)

mappedstack = bg.mapstackto(sourceorigin, target_origin, stack) ```

The transformation is handled only with numpy index operations; i.e., no complex image affine transformations are applied. This is often useful as the preparatory step for starting any kind of image registration.

A shortened syntax can be used to define a space using initials of the origin directions:

python mapped_stack = bg.map_stack_to("lsa", "ipr", stack)


NOTE

When you work with a stack, the origin is the upper left corner when you show the first element stack[0, :, :] with matplotlib or when you open the stack with ImageJ. First dimension is the one that you are slicing, the second the height of the image, and the third the width of the image.


The AnatomicalSpace class

Sometimes, together with the stack we have to move a set of points (cell coordinates, meshes, etc.). This introduces the additional complexity of keeping track, together with the axes swaps and flips, of the change of the origin offset.

To handle this situation, we can define a source space using the AnatomicalSpace class, specifying also the stack shape:

```python

stack = np.random.rand(3, 2, 4) # a stack in source space annotations = np.array([[0, 0, 0], [2, 1, 3]]) # related point annotations

sourcespace = bg.AnatomicalSpace(sourceorigin, stack.shape)

mappedstack = sourcespace.mapstackto("ipr", stack) # transform the stack mappedannotations = sourcespace.mappointsto("ipr", annotations) # transform the points ```

The points are transformed through the generation of a transformation matrix. Finally, if we want to log this matrix (e.g., to reconstruct the full transformations sequence of a registration), we can get it:

```python targetspace = bg.AnatomicalSpace("ipr", stack.shape) transformationmatrix = sourcespace.transformationmatrixto(targetspace)

 equivalent to:

transformationmatrix = sourcespace.transformationmatrixto("ipr", stack.shape) ```

The target get always be defined as a bg.AnatomicalSpace object, or a valid origin specification plus a shape (the shape is required only if axes flips are required).

Matching space resolutions and offsets

The AnatomicalSpace class can deal also with stack resampling/padding/cropping. This requires simply specifying values for resolutions and offsets when instantiating a AnatomicalSpace object. Once that is done, using AnatomicalSpace.transformation_matrix_to creating affine transformation matrices from one space to the other will be a piece of cake!

python source_space = bgs.AnatomicalSpace("asl", resolution=(2, 1, 2), offset=(1, 0, 0)) target_space = bgs.AnatomicalSpace("sal", resolution=(1, 1, 1), offset=(0, 0, 2)) source_space.transformation_matrix_to(target_space)

Moreover, we can now use those space objects to resample stacks, and to generate stacks matching a target shape with the correct padding/cropping simply by specifying a target offset:

python source_space = bgs.AnatomicalSpace("asl", resolution=(2, 1, 2), offset=(1, 0, 0)) target_space = bgs.AnatomicalSpace("asl", resolution=(1, 1, 1), shape=(5, 4, 2)) # we need a target shape source_space.transformation_matrix_to(target_space, stack, to_target_shape=True)

Easy iteration over projections

Finally, another convenient feature of BGSpace is the possibility of iterating easily through the projections of the stack and generate section names and axes labels:

```python sc = bg.AnatomicalSpace("asl") # origin for the stack to be plotted

for i, (plane, labels) in enumerate(zip(sc.sections, sc.axis_labels)): axs[i].imshow(stack.mean(i))

axs[i].set_title(f"{plane.capitalize()} view")
axs[i].set_ylabel(labels[0])
axs[i].set_xlabel(labels[1])

```

Projection illustrations

Seeking help or contributing

We are always happy to help users of our tools, and welcome any contributions. If you would like to get in contact with us for any reason, please see the contact page of our website.

Citation

If you find brainglobe-space useful, please cite the following DOI:

Petrucco, L., & BrainGlobe Developers. (2024). brainglobe-space. Zenodo. https://zenodo.org/doi/10.5281/zenodo.4552536

Owner

  • Name: BrainGlobe
  • Login: brainglobe
  • Kind: organization
  • Location: London/Munich

Open python tools for morphological analyses in systems neuroscience

Citation (CITATION.cff)

# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: brainglobe-space
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
authors:
  - given-names: Luigi
    family-names: Petrucco
  - given-names: BrainGlobe
    family-names: Developers
    email: hello@brainglobe.info
repository-code: >-
  https://github.com/brainglobe/brainglobe-space
url: 'https://brainglobe.info'
abstract: >-
  Anatomical space conventions made easy. brainglobe-space
  provides a neat way of defining an anatomical space, and
  of operating stacks and point transformations between
  spaces.
license: BSD-3-Clause
date-released: '2024-01-24'
doi: 10.5281/zenodo.4552536
year: 2024

GitHub Events

Total
  • Release event: 1
  • Watch event: 2
  • Delete event: 10
  • Push event: 14
  • Pull request review event: 11
  • Pull request event: 24
  • Fork event: 3
  • Create event: 10
Last Year
  • Release event: 1
  • Watch event: 2
  • Delete event: 10
  • Push event: 14
  • Pull request review event: 11
  • Pull request event: 24
  • Fork event: 3
  • Create event: 10

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 0
  • Total pull requests: 10
  • Average time to close issues: N/A
  • Average time to close pull requests: about 9 hours
  • Total issue authors: 0
  • Total pull request authors: 4
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 9
  • Bot issues: 0
  • Bot pull requests: 7
Past Year
  • Issues: 0
  • Pull requests: 10
  • Average time to close issues: N/A
  • Average time to close pull requests: about 9 hours
  • Issue authors: 0
  • Pull request authors: 4
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 9
  • Bot issues: 0
  • Bot pull requests: 7
Top Authors
Issue Authors
  • niksirbi (1)
  • adamltyson (1)
  • willGraham01 (1)
  • Timbrer (1)
Pull Request Authors
  • pre-commit-ci[bot] (17)
  • adamltyson (7)
  • alessandrofelder (4)
  • IgorTatarnikov (4)
  • lochhh (1)
  • niksirbi (1)
  • willGraham01 (1)
Top Labels
Issue Labels
bug (3) enhancement (2)
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 5,068 last-month
  • Total dependent packages: 8
    (may contain duplicates)
  • Total dependent repositories: 0
    (may contain duplicates)
  • Total versions: 26
  • Total maintainers: 3
proxy.golang.org: github.com/brainglobe/brainglobe-space
  • Versions: 23
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.5%
Average: 5.7%
Dependent repos count: 5.9%
Last synced: 11 months ago
pypi.org: brainglobe-space

Anatomical space conventions made easy

  • Versions: 3
  • Dependent Packages: 8
  • Dependent Repositories: 0
  • Downloads: 5,068 Last month
Rankings
Dependent packages count: 10.0%
Average: 37.9%
Dependent repos count: 65.8%
Last synced: 11 months ago

Dependencies

.github/workflows/test_and_deploy.yml actions
  • neuroinformatics-unit/actions/lint v1 composite
  • neuroinformatics-unit/actions/test v1 composite
pyproject.toml pypi
  • numpy *
  • scipy *