Skip to content
This repository has been archived by the owner on Oct 6, 2021. It is now read-only.

Commit

Permalink
Brainrender 1.0.0.0 bug fixes (#45)
Browse files Browse the repository at this point in the history
* remove brainrender.Utils.image dependency

* flake8 compatibility

* add verison to init

* fix manual_seg

* slim down testing matrix
  • Loading branch information
adamltyson committed Aug 17, 2020
1 parent 83af6aa commit 7937f57
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 28 deletions.
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
repos:
- repo: https://github.com/python/black
rev: 19.10b0
hooks:
- id: black
pass_filenames: true
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
hooks:
- id: flake8
pass_filenames: true
# exclude: __init__.py
20 changes: 0 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,13 @@ jobs:
dist: bionic
python: 3.7
script: travis_wait 40 bash travis/install_test_linux.sh
- stage: test
name: "Ubuntu Xenial python 3.6"
language: python
os: linux
dist: xenial
python: 3.6
script: travis_wait 40 bash travis/install_test_linux.sh
- stage: test
name: "Ubuntu Xenial python 3.7"
language: python
os: linux
dist: xenial
python: 3.7
script: travis_wait 40 bash travis/install_test_linux.sh
- stage: test
name: "Windows Python 3.6"
language: shell
env: TRAVIS_PYTHON_VERSION=3.6
os: windows
before_install: source travis/install_windows.sh
script: travis_wait 40 bash travis/test_windows.sh
- stage: test
name: "Windows Python 3.7"
language: shell
Expand All @@ -53,12 +39,6 @@ jobs:
before_install:
- source travis/install_windows.sh
script: travis_wait 40 bash travis/test_windows.sh
- stage: test
name: "macOS Python 3.6"
os: osx
language: shell
env: TRAVIS_PYTHON_VERSION=3.6
script: travis_wait 40 bash travis/install_test_osx.sh
- stage: test
name: "macOS Python 3.7"
os: osx
Expand Down
2 changes: 2 additions & 0 deletions neuro/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__author__ = "Adam Tyson"
__version__ = "0.0.18"
12 changes: 10 additions & 2 deletions neuro/segmentation/manual_segmentation/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@
add_new_region_layer,
view_in_brainrender,
)
from neuro.gui.elements import *
from neuro.gui.elements import (
add_button,
add_checkbox,
add_float_box,
add_int_box,
add_combobox,
)

from qtpy.QtWidgets import (
QLabel,
Expand Down Expand Up @@ -451,7 +457,9 @@ def run_region_analysis(self):
def initialise_brainrender(self):
self.scene = Scene(add_root=True)
self.splines = None
self.available_meshes = [""] + self.scene.atlas.all_avaliable_meshes
self.available_meshes = [""] + list(
self.scene.atlas.lookup_df["acronym"]
)

def to_brainrender(self):
print("Closing viewer and viewing in brainrender.")
Expand Down
50 changes: 47 additions & 3 deletions neuro/visualise/brainrender_tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
from pathlib import Path
from brainrender.Utils.image import reorient_image, marching_cubes_to_obj
from brainrender.scene import Scene
from skimage import measure

Expand All @@ -12,6 +11,51 @@
)


def marching_cubes_to_obj(marching_cubes_out, output_file):
"""
Saves the output of skimage.measure.marching_cubes as an .obj file
:param marching_cubes_out: tuple
:param output_file: str
"""

verts, faces, normals, _ = marching_cubes_out
with open(output_file, "w") as f:
for item in verts:
f.write(f"v {item[0]} {item[1]} {item[2]}\n")
for item in normals:
f.write(f"vn {item[0]} {item[1]} {item[2]}\n")
for item in faces:
f.write(
f"f {item[0]}//{item[0]} {item[1]}//{item[1]} "
f"{item[2]}//{item[2]}\n"
)
f.close()


def reorient_image(image, invert_axes=None, orientation="saggital"):
"""
Reorients the image to the coordinate space of the atlas
:param image_path: str
:param threshold: float
:param invert_axes: tuple (Default value = None)
:param image:
:param orientation: (Default value = "saggital")
"""
# TODO: move this to brainio
if invert_axes is not None:
for axis in invert_axes:
image = np.flip(image, axis=axis)

if orientation != "saggital":
if orientation == "coronal":
transposition = (2, 1, 0)
elif orientation == "horizontal":
transposition = (1, 2, 0)

image = np.transpose(image, transposition)
return image


def render_region_from_custom_atlas(
output_dir,
atlas_ids,
Expand All @@ -35,7 +79,7 @@ def render_region_from_custom_atlas(
oriented_binary, 0, step_size=1
)

if voxel_size is not 1:
if voxel_size != 1:
verts = verts * voxel_size

faces = faces + 1
Expand Down Expand Up @@ -94,7 +138,7 @@ def extract_and_save_object(


def convert_obj_to_br(verts, faces, voxel_size=10):
if voxel_size is not 1:
if voxel_size != 1:
verts = verts * voxel_size

faces = faces + 1
Expand Down
1 change: 0 additions & 1 deletion neuro/visualise/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
from qtpy import QtCore
from qtpy.QtWidgets import (
QLabel,
QFileDialog,
QGridLayout,
QWidget,
Expand Down
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[tool.black]
line-length = 79
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
)/
'''
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
addopts = --cov=neuro
markers =
slow: marks tests as slow (deselect with '-m "not slow"')
17 changes: 17 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[bumpversion]
current_version = 0.0.18
commit = True
tag = True

[bumpversion:file:setup.py]
search = version="{current_version}"
replace = version="{new_version}"

[bumpversion:file:neuro/__init__.py]
search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"

[flake8]
ignore = E203, E231, W503, E501
max-line-length = 79
exclude = __init__.py
13 changes: 11 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@

setup(
name="neuro",
version="0.0.16",
version="0.0.18",
description="Visualisation and analysis of brain imaging data",
install_requires=requirements,
extras_require={
"dev": ["black", "pytest-cov", "pytest", "gitpython", "coverage",]
"dev": [
"black",
"pytest-cov",
"pytest",
"gitpython",
"coverage",
"bump2version",
"pre-commit",
"flake8",
]
},
python_requires=">=3.6, <3.8",
packages=find_namespace_packages(exclude=("docs", "tests*")),
Expand Down

0 comments on commit 7937f57

Please sign in to comment.