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

Exposed the invert_dim parameter #391

Merged
merged 7 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
8 changes: 5 additions & 3 deletions brainrender/actors/neurons.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(
alpha=1,
neurite_radius=8,
soma_radius=15,
invert_dims=True,
name=None,
):
"""
Expand All @@ -50,6 +51,7 @@ def __init__(
:param color: str,
:param neuron_radius: float, radius of axon/dendrites
:param soma_radius: float, radius of soma
:param invert_dims: bool, invert dimensions of neuron
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this docstring be expanded? It's not immediately obvious what "inverting dimensions" means.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated! Hopefully, that's a bit clearer.

:param name: str, actor name
"""
logger.debug("Creating a Neuron actor")
Expand All @@ -61,7 +63,7 @@ def __init__(
self.name = None

if isinstance(neuron, (str, Path)):
mesh = self._from_file(neuron)
mesh = self._from_file(neuron, invert_dims)
elif isinstance(neuron, (Mesh)):
mesh = neuron
elif isinstance(neuron, Actor):
Expand All @@ -86,7 +88,7 @@ def _from_morphapi_neuron(self, neuron: MorphoNeuron):
)[1]
return mesh

def _from_file(self, neuron: (str, Path)):
def _from_file(self, neuron: (str, Path), invert_dims):
path = Path(neuron)
if not path.exists():
raise FileExistsError(f"Neuron file doesn't exist: {path}")
Expand All @@ -99,5 +101,5 @@ def _from_file(self, neuron: (str, Path)):
self.name = self.name or path.name

return self._from_morphapi_neuron(
MorphoNeuron(data_file=neuron, invert_dims=True)
MorphoNeuron(data_file=neuron, invert_dims=invert_dims)
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import sys
from time import sleep

import pandas as pd
import requests
from loguru import logger

from brainrender import base_dir
Expand Down Expand Up @@ -86,7 +88,18 @@
:param gene_symbol: str
"""
url = self.gene_experiments_url.replace("-GENE_SYMBOL-", gene)
data = request(url).json()["msg"]
max_retries = 8
delay = 4
data = None

for i in range(max_retries):
try:
data = request(url).json()["msg"]
break
except requests.exceptions.JSONDecodeError:
print(f"Unable to connect to Allen API, retrying in {delay}")
sleep(delay)
delay *= 2

Check warning on line 102 in brainrender/atlas_specific/allen_brain_atlas/gene_expression/api.py

View check run for this annotation

Codecov / codecov/patch

brainrender/atlas_specific/allen_brain_atlas/gene_expression/api.py#L99-L102

Added lines #L99 - L102 were not covered by tests

if not len(data):
print(f"No experiment found for gene {gene}")
Expand Down
8 changes: 7 additions & 1 deletion examples/neurons.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from morphapi.api.mouselight import MouseLightAPI
from myterial import orange
from rich import print
from urllib3.exceptions import NewConnectionError, MaxRetryError

from brainrender import Scene
from brainrender.actors import Neuron, make_neurons
Expand All @@ -28,7 +29,12 @@
to_add = [neurons_metadata[47], neurons_metadata[51]]
neurons = mlapi.download_neurons(to_add)
neurons = scene.add(*make_neurons(*neurons, neurite_radius=12))
except ConnectionError or requests.exceptions.ReadTimeout as e:
except (
NewConnectionError,
MaxRetryError,
requests.exceptions.ConnectionError,
requests.exceptions.ReadTimeout,
) as e:
print("Failed to download neurons data from neuromorpho.org.")

# Render!
Expand Down
Loading