Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename to brainglobe-space #42

Merged
merged 7 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,62 @@ name: Run tests

on:
push:
branches: [ main ]
branches:
- "main"
tags:
- "v**"
pull_request:
workflow_dispatch:

concurrency:
# Cancel this workflow if it is running,
# and then changes are applied on top of the HEAD of the branch,
# triggering another run of the workflow
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
linting:
name: Check Linting
runs-on: ubuntu-latest
steps:
- uses: neuroinformatics-unit/actions/lint@v1
- uses: neuroinformatics-unit/actions/lint@v2

manifest:
name: Check Manifest
runs-on: ubuntu-latest
steps:
- uses: neuroinformatics-unit/actions/lint@v2

test:
needs: lint
name: ${{ matrix.os }} py${{ matrix.python-version }}
name: Run package tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
# Run across a mixture of Python versions and operating systems
include:
- os: ubuntu-latest
python-version: "3.11"
- os: macos-latest
python-version: "3.10"
- os: windows-latest
python-version: "3.9"
- os: ubuntu-latest
python-version: "3.8"

steps:
- uses: neuroinformatics-unit/actions/test@v1
with:
python-version: ${{ matrix.python-version }}

build_sdist_wheel:
name: Build source distribution and wheel
needs: [test, linting, manifest]
if: github.event_name == 'push' && github.ref_type == 'tag'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.TWINE_API_KEY }}
8 changes: 8 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
include LICENSE
include README.md

exclude .pre-commit-config.yaml
exclude .codecov.yml

graft brainglobe_space

prune tests
prune docs
42 changes: 18 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
# `bg-space` has become `brainglobe-space`

To continue receiving updates, please switch to using [`brainglobe-space`](https://github.com/brainglobe/brainglobe-space) instead of this package.
`bg-space` will no longer be receiving updates, and has been replaced by `brainglobe-space` in all other aspects of the BrainGlobe tool suite.

Old README.md contents are below.

# BG-Space

Anatomical space conventions made easy.

[![Python Version](https://img.shields.io/pypi/pyversions/bg-space.svg)](https://pypi.org/project/bg-space)
[![PyPI](https://img.shields.io/pypi/v/bg-space.svg)](https://pypi.org/project/bg-space)
[![Build Status](https://travis-ci.com/brainglobe/bg-space.svg?branch=master)](https://travis-ci.com/brainglobe/bg-space)
[![Python Version](https://img.shields.io/pypi/pyversions/brainglobe-space.svg)](https://pypi.org/project/brainglobe-space)
[![PyPI](https://img.shields.io/pypi/v/brainglobe-space.svg)](https://pypi.org/project/brainglobe-space)
[![Build Status](https://travis-ci.com/brainglobe/brainglobe-space.svg?branch=master)](https://travis-ci.com/brainglobe/brainglobe-space)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![Coverage Status](https://coveralls.io/repos/github/brainglobe/bg-space/badge.svg)](https://coveralls.io/github/brainglobe/bg-space)
[![Coverage Status](https://coveralls.io/repos/github/brainglobe/brainglobe-space/badge.svg)](https://coveralls.io/github/brainglobe/brainglobe-space)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4552537.svg)](https://doi.org/10.5281/zenodo.4552537)

# 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).

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

If you use `bg-space` for your analyses, please cite its Zenodo DOI https://zenodo.org/record/4552537#.YDAFzi1Q2Rs!
If you use `brainglobe-space` for your analyses, please cite its [Zenodo DOI](https://zenodo.org/record/4552537#.YDAFzi1Q2Rs!) <https://zenodo.org/record/4552537#.YDAFzi1Q2Rs!>

## Installation

You can install `bg-space` with:
You can install `brainglobe-space` with:

```bash
pip install bg-space
pip install brainglobe-space
```

## Usage
Expand All @@ -43,7 +36,7 @@ target_origin = ("Inferior", "Posterior", "Right")
A stack can be then easily transformed from the source to the target space:

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

Expand All @@ -60,7 +53,8 @@ mapped_stack = bg.map_stack_to("lsa", "ipr", stack)
```

---
**NOTE**

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

Expand All @@ -84,7 +78,6 @@ mapped_stack = source_space.map_stack_to("ipr", stack) # transform the stack
mapped_annotations = source_space.map_points_to("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:

Expand All @@ -98,6 +91,7 @@ transformation_matrix = source_space.transformation_matrix_to("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
Expand All @@ -114,7 +108,6 @@ target_space = bgs.AnatomicalSpace("asl", resolution=(1, 1, 1), shape=(5, 4, 2))
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:
Expand All @@ -130,7 +123,8 @@ for i, (plane, labels) in enumerate(zip(sc.sections, sc.axis_labels)):
axs[i].set_xlabel(labels[1])
```

![](/docs/img/projections.png)
![Projection illustrations](/docs/img/projections.png)

## Contributing

Contributions are very welcome. Please see the [developers guide](https://brainglobe.info/developers/index.html).
17 changes: 0 additions & 17 deletions bg_space/__init__.py

This file was deleted.

10 changes: 10 additions & 0 deletions brainglobe_space/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
__author__ = """Luigi Petrucco @brainglobe"""
__version__ = "0.6.0"

from brainglobe_space.core import AnatomicalSpace, SpaceConvention
from brainglobe_space.functions import (
map_to,
map_stack_to,
transformation_matrix_to,
transform_points_to,
)
4 changes: 2 additions & 2 deletions bg_space/core.py → brainglobe_space/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
from scipy import ndimage as nd

from bg_space.utils import deprecated, ordered_list_from_set
from brainglobe_space.utils import deprecated, ordered_list_from_set


def to_target(method):
Expand Down Expand Up @@ -486,7 +486,7 @@ def __eq__(self, other):

@deprecated(
"SpaceConvention will be removed from v0.6. "
"Use bg_space.AnatomicalSpace instead"
"Use brainglobe_space.AnatomicalSpace instead"
)
class SpaceConvention(AnatomicalSpace):
pass
2 changes: 1 addition & 1 deletion bg_space/functions.py → brainglobe_space/functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from bg_space.core import AnatomicalSpace
from brainglobe_space.core import AnatomicalSpace


# TODO convert to a smarter way to generate those parsing class' methods:
Expand Down
File renamed without changes.
57 changes: 29 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,66 +1,67 @@
[project]
name = "bg_space"
name = "brainglobe_space"
description = "Anatomical space conventions made easy"
readme = "README.md"
authors = [
{name = "Luigi Petrucco", email = "[email protected]"},
]
authors = [{ name = "Luigi Petrucco", email = "[email protected]" }]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
requires-python = ">=3.8"
dependencies = [
"numpy",
"scipy",
]
requires-python = ">=3.9"
dependencies = ["numpy", "scipy"]
dynamic = ["version"]

[project.urls]
Homepage = "https://github.com/brainglobe/bg-space"
Homepage = "https://github.com/brainglobe/brainglobe-space"

[project.optional-dependencies]
dev = [
"gitpython",
"pre-commit",
"pytest",
"pytest-cov",
]
dev = ["gitpython", "pre-commit", "pytest", "pytest-cov"]

[build-system]
requires = [
"setuptools>=45",
"wheel",
"setuptools_scm[toml]>=6.2",
]
requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
include-package-data = true

[tool.setuptools.packages.find]
include = ["bg_space*"]
include = ["brainglobe_space*"]

[tool.setuptools_scm]

[tool.pytest.ini_options]
filterwarnings = [
"error",
]
filterwarnings = ["error"]

[tool.black]
target-version = ['py38', 'py39', 'py310', 'py311']
target-version = ['py39', 'py310', 'py311']
skip-string-normalization = false
line-length = 79

[tool.ruff]
line-length = 79
exclude = ["__init__.py","build",".eggs"]
exclude = ["__init__.py", "build", ".eggs"]
select = ["I", "E", "F"]
fix = true

[tool.tox]
legacy_tox_ini = """
[tox]
envlist = py{39,310,311}

[gh-actions]
python =
3.9: py39
3.10: py310
3.11: py311

[testenv]
extras =
dev
commands =
pytest -v --color=yes --cov=brainglobe_space --cov-report=xml
"""
2 changes: 1 addition & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import pytest

from bg_space import AnatomicalSpace, SpaceConvention
from brainglobe_space import AnatomicalSpace, SpaceConvention

from .utils import create_label_array

Expand Down
4 changes: 2 additions & 2 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np
import pytest

from bg_space.core import AnatomicalSpace
from bg_space.functions import (
from brainglobe_space.core import AnatomicalSpace
from brainglobe_space.functions import (
map_stack_to,
map_to,
transform_points_to,
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from bg_space import AnatomicalSpace
from brainglobe_space import AnatomicalSpace

char_add = np.core.defchararray.add

Expand Down
15 changes: 0 additions & 15 deletions tox.ini

This file was deleted.

Loading