Skip to content

Commit

Permalink
Merge pull request #250 from brainglobe/mega-fix
Browse files Browse the repository at this point in the history
Mega fix of brainrender
  • Loading branch information
adamltyson committed Dec 1, 2023
2 parents 5a8418c + 5be13ea commit 19350ce
Show file tree
Hide file tree
Showing 125 changed files with 1,299 additions and 167,987 deletions.
4 changes: 2 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[RUN]
omit =
omit =
brainrender/gui/*
brainrender/gui

[report]
omit =
omit =
brainrender/gui/*
brainrender/gui

Expand Down
72 changes: 0 additions & 72 deletions .github/workflows/main.yml

This file was deleted.

72 changes: 72 additions & 0 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: tests

on:
push:
branches:
- '*'
tags:
- '*'
pull_request:

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

test:
needs: [linting]
name: ${{ matrix.os }} py${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Run all supported Python versions on linux
python-version: ["3.9", "3.10", "3.11"]
os: [ubuntu-latest]
# Include one windows and macos run
include:
- os: macos-latest
python-version: "3.11"
- os: windows-latest
python-version: "3.11"

steps:
- name: Install hdf5 libs for Mac
if: runner.os == 'macOS'
run: brew install hdf5

# Helps set up VTK with a headless display
- uses: pyvista/setup-headless-display-action@v2

# Sets up ffmpeg to we can run video tests on CI
- uses: FedericoCarboni/setup-ffmpeg@v2
id: setup-ffmpeg

# Run tests
- uses: neuroinformatics-unit/actions/test@v2
with:
python-version: ${{ matrix.python-version }}

build_sdist_wheels:
name: Build source distribution
needs: [test]
if: github.event_name == 'push' && github.ref_type == 'tag'
runs-on: ubuntu-latest
steps:
- uses: neuroinformatics-unit/actions/build_sdist_wheels@v2


upload_all:
name: Publish build distributions
needs: [build_sdist_wheels]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- uses: pypa/gh-action-pypi-publish@v1.5.0
with:
user: __token__
password: ${{ secrets.TWINE_API_KEY }}
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,3 @@ venv.bak/
.idea/

*.~lock.*


28 changes: 20 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
repos:
- repo: https://github.com/psf/black
rev: 23.10.1
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-toml
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.272
hooks:
- id: ruff
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ recursive-exclude tests *
recursive-exclude examples *
recursive-exclude imgs *
recursive-exclude videos *
recursive-exclude benchmark *
recursive-exclude benchmark *
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
## Update 2023-10-05: brainrender is currently unsupported
### brainrender has a number of critical bugs that we are aiming to address. Until these issues are fixed, we will be able to offer very limited support.
### For further details please see [this issue](https://github.com/brainglobe/brainrender/issues/247).


# Brainrender
<p align="center">
Expand All @@ -28,10 +24,10 @@ You can [install `brainrender`](https://brainglobe.info/documentation/brainrende

```
pip install brainrender
```
```

## Contributing
Contributions to brainrender are more than welcome. Please see the [developers guide](https://brainglobe.info/developers/index.html).
Contributions to brainrender are more than welcome. Please see the [developers guide](https://brainglobe.info/community/developers/index.html). Note that some tests are only run locally, by specifying `--runslow --runlocal` in `pytest`.

## Citing brainrender
If you use `brainrender` in your work, please cite:
Expand Down
5 changes: 2 additions & 3 deletions benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Note: the duration reported in the results does not include scene creation (`sce
## Machines tested
* **[1]** macOS - Mojave 10.14.6 - MacBook Pro (15-inch, 2019) - 2.3 GHz Intel Core i9 - Radeon Pro 560X 4 GB GPU
* **[2]** Ubuntu - 18.04.2 LTS x86_64 - Intel i7-8565U (x) @ 4.5GHz - NO GPU
* **[3]** Windows 10 - Intel(R) Core i7-7700HQ 2.8GHz - NO GPU
* **[3]** Windows 10 - Intel(R) Core i7-7700HQ 2.8GHz - NO GPU
* **[4]** Windows 10 - Intel(R) Xeon(R) CPU E5-2643 v3 3.4GHz - NVIDIA GeForce GTX 1080 Ti

## Tests
Expand All @@ -23,7 +23,7 @@ through the midline, as well as rendering the scene full screen.

### Brain regions
Render >1k brain region meshes. Measures how long it takes to fetch and render the meshes
for almost all brain regions in the mouse brain.
for almost all brain regions in the mouse brain.

### Animation
Make a short animation
Expand Down Expand Up @@ -78,4 +78,3 @@ Note: these tests are designed to push brainrender to the limits, in practice se
and increase FPS. This includes decimating/smoothing Actors to reduce the number of vertices or creating meshes with lower resolution to
begin with. For most cases a significant increase in performance can be achieved with no noticeable loss in rendering quality.
For instance on computer [4] lowering the resolution of the Points actor from 8 to 4 when rendering 1M points tripled the FPS.

3 changes: 1 addition & 2 deletions benchmark/bm_animation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from brainrender import Scene, Animation
from benchmark.timer import Timer

from brainrender import Animation, Scene

# Create a brainrender scene
scene = Scene(title="brain regions", inset=False)
Expand Down
1 change: 0 additions & 1 deletion benchmark/bm_brain_regions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from benchmark.timer import Timer
from brainrender import Scene


scene = Scene(inset=False)
regions = scene.atlas.get_structure_descendants("root")

Expand Down
8 changes: 5 additions & 3 deletions benchmark/bm_cells.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import random

import numpy as np

from benchmark.timer import Timer
from brainrender import Scene, actors
import numpy as np
import random

# create N random cells coordinates

Expand All @@ -17,7 +19,7 @@ def get_n_random_points_in_region(region, N):
Z = np.random.randint(region_bounds[4], region_bounds[5], size=10000)
pts = [[x, y, z] for x, y, z in zip(X, Y, Z)]

ipts = region.mesh.insidePoints(pts).points()
ipts = region.mesh.inside_points(pts).coordinates
return np.vstack(random.choices(ipts, k=N))


Expand Down
11 changes: 5 additions & 6 deletions benchmark/bm_napari.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import numpy as np
"""
Compare performance on napari
"""
import napari
import numpy as np

from benchmark.timer import SimpleTimer
from brainrender import Scene

"""
Compare performance on napari
"""

# get a couple meshes with brainrender
scene = Scene()

Expand All @@ -22,7 +21,7 @@
surfaces = []
for act in scene.clean_actors:
surfaces.append(
(act.points(), act.faces(), np.ones(len(act.points())) * 0.5)
(act.vertices, act.cells, np.ones(len(act.vertices)) * 0.5)
)

# render stuff in napar
Expand Down
3 changes: 2 additions & 1 deletion benchmark/bm_napari_volume.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import napari
import numpy as np

from benchmark.timer import SimpleTimer
import napari

data = np.load("benchmark/volume.npy")

Expand Down
3 changes: 2 additions & 1 deletion benchmark/bm_volume.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy as np

from benchmark.timer import Timer
from brainrender import Scene
from brainrender.actors import Volume
from benchmark.timer import Timer

scene = Scene(inset=False)
data = np.load("benchmark/volume.npy")
Expand Down
23 changes: 12 additions & 11 deletions benchmark/timer.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from rich.layout import Layout
from rich import print
from rich.panel import Panel
import time
import multiprocessing
import os
import sys
import time

import pyinspect as pi
from myterial import (
salmon,
amber,
blue_light,
orange,
orange_darker,
amber,
pink_light,
blue_light,
salmon,
)
import multiprocessing
import os
from rich import print
from rich.layout import Layout
from rich.panel import Panel


def is_GPU_available():
Expand All @@ -36,7 +37,7 @@ def __rich_console__(self, console, dimension):
)
for act in self.scene.clean_actors:
try:
points = len(act.points())
points = act.npoints
except AttributeError:
points = 0
actors.add(
Expand Down Expand Up @@ -70,7 +71,7 @@ def __rich_console__(self, console, dimension):
points = []
for act in self.scene.clean_actors:
try:
points.append(len(act.points()))
points.append(act.npoints)
except AttributeError:
pass
tot_points = sum(points)
Expand Down

0 comments on commit 19350ce

Please sign in to comment.