Skip to content

Commit

Permalink
Chore: Apply Copier template
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-berchet committed Feb 16, 2023
1 parent f1d6a97 commit 63b0065
Show file tree
Hide file tree
Showing 30 changed files with 26 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changes here will be overwritten by Copier

_commit: 0.1.33
_commit: 0.1.36
_src_path: git@bbpgitlab.epfl.ch:neuromath/python-template.git
author_email: ''
author_name: Blue Brain Project, EPFL
Expand Down
6 changes: 4 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[flake8]
ignore =
E203, # E203: whitespace before ':'
W503 # W503: line break before binary operator
# E203: whitespace before ':'
E203,
# W503: line break before binary operator
W503
max-line-length = 100
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default_language_version:
python: python3.8
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -13,31 +13,31 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.0.0
rev: v9.4.0
hooks:
- id: commitlint
stages:
- commit-msg
additional_dependencies: ['conventional-changelog-conventionalcommits']
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 22.6.0
rev: 23.1.0
hooks:
- id: black
- repo: https://github.com/codespell-project/codespell
rev: v2.2.1
rev: v2.2.2
hooks:
- id: codespell
args: ["-x", ".codespellignorelines"]
- repo: https://github.com/PyCQA/pydocstyle
rev: 6.1.1
rev: 6.3.0
hooks:
- id: pydocstyle
additional_dependencies: ["toml"]
additional_dependencies: ["tomli"]
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
1 change: 0 additions & 1 deletion neurots/astrocyte/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class SpaceColonizationContext:
"""

def __init__(self, params):

self.morphology_points = DynamicPointArray()

if "endfeet_targets" in params:
Expand Down
9 changes: 2 additions & 7 deletions neurots/astrocyte/grower.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from neurots.morphmath import sample
from neurots.morphmath.utils import norm as vectorial_norm
from neurots.morphmath.utils import normalize_vectors
from neurots.utils import NeuroTSError

L = logging.getLogger(__name__)

Expand All @@ -41,7 +42,7 @@ def _number_of_trees(tree_type, oris, distributions, random_generator=np.random)
n_trees = len(oris)

if tree_type == "basal" and n_trees < 2:
raise Exception(f"There should be at least 2 basal dendrites (got {n_trees})")
raise NeuroTSError(f"There should be at least 2 basal dendrites (got {n_trees})")

return n_trees

Expand All @@ -63,9 +64,7 @@ def _ensure_endfeet_are_reached(cell, targets):
distances, section_indices = KDTree(termination_points, copy_data=False).query(target_points)

for distance, section_index, target_point in zip(distances, section_indices, target_points):

if not np.isclose(distance, 0.0):

L.warning(
"Target %s was not reached. Extending closest section to reach it.",
target_point,
Expand Down Expand Up @@ -175,7 +174,6 @@ def _create_process_trunks(self, tree_type, parameters, distributions):
tree_type = "perivascular" if tree_type == "axon" else "perisynaptic"

if tree_type == "perivascular":

target_ids = np.array(parameters["target_ids"], dtype=np.int32)
target_points = self.context.endfeet_targets.points[target_ids]

Expand All @@ -193,15 +191,13 @@ def _create_process_trunks(self, tree_type, parameters, distributions):
), "Number of targets is not equal to number of orientations"

for target_id, trunk_point in zip(target_ids, trunk_points):

neurite_params = deepcopy(parameters)
neurite_params["target_id"] = target_id
neurite_params["distance_soma_target"] = vectorial_norm(
self.soma_grower.soma.center - self.context.endfeet_targets.points[target_id]
)
self._add_active_neurite(trunk_point, neurite_params, distributions)
else:

oris = parameters["orientation"]

if oris is not None:
Expand All @@ -214,7 +210,6 @@ def _create_process_trunks(self, tree_type, parameters, distributions):
)

for i, trunk_point in enumerate(trunk_points):

neurite_params = deepcopy(parameters)
if "domain_distances" in neurite_params:
neurite_params["distance_to_domain"] = parameters["domain_distances"][i]
Expand Down
1 change: 0 additions & 1 deletion neurots/astrocyte/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def grow_to_target(start_point, start_direction, target_point, segment_length, p

points = []
while not in_squared_proximity(point, target_point, target_proximity):

target_direction = from_to_direction(point, target_point)
direction = (1.0 - p) * direction + p * target_direction

Expand Down
6 changes: 0 additions & 6 deletions neurots/astrocyte/space_colonization.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ def _colonization_split(section, angles, parameters, context):
repulsion = _repulsion(morphology_points[ids], current_point, kill_distance)

if section.process == "major":

seed_ids = point_cloud.partial_ball_query(
current_point,
influence_distance,
Expand All @@ -254,7 +253,6 @@ def _colonization_split(section, angles, parameters, context):
section_direction, vectors_to_seeds, repulsion
)
else:

seed_ids = point_cloud.upper_half_ball_query(
current_point, influence_distance, section_direction
)
Expand All @@ -266,7 +264,6 @@ def _colonization_split(section, angles, parameters, context):
dir1, dir2 = _colonization_strategy_secondary(vectors_to_seeds, repulsion)

if np.allclose(dir1, dir2):

L.warning(
"Splitting directions are identical. Use of fallback strategy to recalculate them."
)
Expand Down Expand Up @@ -348,15 +345,13 @@ def _colonization_split_with_target_influence(section, angles, parameters, conte
target_point = context.endfeet_targets.points[target_id]

if in_squared_proximity(current_point, target_point, ENDFOOT_SQUARED_DISTANCE):

# this section will become the endfoot section that will connect to the target
process2 = "endfoot"

# make the target invisible for the rest of the section growers
context.endfeet_targets.active[target_id] = False
dir2 = from_to_direction(current_point, target_point)
else:

max_target_distance = parameters["distance_soma_target"]
if process1 == "major":
dir1 = _add_attraction_bias(
Expand All @@ -367,7 +362,6 @@ def _colonization_split_with_target_influence(section, angles, parameters, conte
section.context.field,
)
else:

process1 = _majorize_process(
process1,
section.stop_criteria["TMD"],
Expand Down
2 changes: 1 addition & 1 deletion neurots/extract_input/from_neurom.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def trunk_neurite(pop, neurite_type=nm.BASAL_DENDRITE, bins=30):
Args:
pop (neurom.core.population.Population): The given population.
neurite_type (neurom.core.types.NeuriteType): Consider only the neurites of this type.
bins (int or list[int] or str, optional): The bins to use (this pararmeter is passed to
bins (int or list[int] or str, optional): The bins to use (this parameter is passed to
:func:`numpy.histogram`).
Returns:
Expand Down
1 change: 0 additions & 1 deletion neurots/extract_input/input_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ def distributions(
elif (
isinstance(diameter_model, str) and diameter_model == "default"
) or diameter_model is None:

input_distributions["diameter"] = {}
input_distributions["diameter"]["method"] = "default"
input_distributions["diameter"]["diameter"] = build_diameter_models(
Expand Down
6 changes: 3 additions & 3 deletions neurots/generate/diametrizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import numpy as np
from morphio import SectionType

from neurots.utils import NeuroTSError


def section_filter(neuron, tree_type=None):
"""Filter all sections according to type."""
Expand Down Expand Up @@ -71,7 +73,7 @@ def redefine_diameter_section(section, diam_ind, diam_new):
+ section.diameters.tolist()[(diam_ind + 1) :]
)
if len(section.points) != len(section.diameters):
raise Exception("Mismatch in dimensions of diameters.")
raise NeuroTSError("Mismatch in dimensions of diameters.")


def bifurcator(initial_diam, num_children, rall_ratio, siblings_ratio):
Expand Down Expand Up @@ -223,7 +225,6 @@ def diametrize_from_root(
random_generator (numpy.random.Generator): The random number generator to use.
"""
for r in root_section_filter(neuron, tree_type=neurite_type):

model = model_params[r.type.name] # Selected by the root type.
trunk_diam = sample(model["trunk"], random_generator)
min_diam = np.min(model["term"])
Expand All @@ -233,7 +234,6 @@ def diametrize_from_root(

while active:
for section in list(active):

if section.is_root:
taper = sample(model["trunk_taper"], random_generator)
init_diam = trunk_diam
Expand Down
15 changes: 7 additions & 8 deletions neurots/generate/grower.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from neurots.generate.tree import TreeGrower
from neurots.morphmath import sample
from neurots.morphmath.utils import normalize_vectors
from neurots.utils import NeuroTSError
from neurots.utils import convert_from_legacy_neurite_type
from neurots.validator import validate_neuron_distribs
from neurots.validator import validate_neuron_params
Expand Down Expand Up @@ -253,7 +254,6 @@ def _convert_orientation2points(self, orientation, n_trees, distr, params):
), "Orientations should have non-zero lengths"
if params.get("trunk_absolute_orientation", False):
if len(orientation) == 1:

orientation = np.asarray(orientation[0], dtype=np.float64)
orientation /= np.linalg.norm(orientation)

Expand All @@ -271,7 +271,6 @@ def _convert_orientation2points(self, orientation, n_trees, distr, params):
raise ValueError("The orientation should contain exactly one point!")
else:
if len(orientation) >= n_trees:

# TODO: pick orientations randomly?
orientations = normalize_vectors(np.asarray(orientation, dtype=np.float64))[
:n_trees
Expand Down Expand Up @@ -319,7 +318,6 @@ def _grow_trunks(self):
legacy_mode = not isinstance(self.input_parameters[tree_types[0]]["orientation"], dict)

if not legacy_mode:

trunk_orientations_manager = self._trunk_orientations_class(
soma=self.soma_grower.soma,
parameters=self.input_parameters,
Expand All @@ -329,29 +327,30 @@ def _grow_trunks(self):
)

for type_of_tree in tree_types:

params = self.input_parameters[type_of_tree]
distr = self.input_distributions[type_of_tree]

if legacy_mode:

n_trees = sample.n_neurites(distr["num_trees"], random_generator=self._rng)

if type_of_tree == "basal_dendrite" and n_trees < 2:
raise Exception(f"There should be at least 2 basal dendrites (got {n_trees})")
raise NeuroTSError(
f"There should be at least 2 basal dendrites (got {n_trees})"
)

orientation = params["orientation"]
points = self._convert_orientation2points(orientation, n_trees, distr, params)

else:

orientations = trunk_orientations_manager.compute_tree_type_orientations(
type_of_tree
)
n_trees = len(orientations)

if type_of_tree == "basal_dendrite" and n_trees < 2:
raise Exception(f"There should be at least 2 basal dendrites (got {n_trees})")
raise NeuroTSError(
f"There should be at least 2 basal dendrites (got {n_trees})"
)

points = self.soma_grower.add_points_from_orientations(orientations)

Expand Down
1 change: 0 additions & 1 deletion neurots/generate/orientations.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def _mode_{name}(self, values_dict, tree_type)
"""

def __init__(self, soma, parameters, distributions, context, rng):

self._soma = soma
self._parameters = parameters
self._distributions = distributions
Expand Down
1 change: 0 additions & 1 deletion neurots/generate/soma.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ def add_points_from_orientations(self, vectors):
new_points = []

for vect in vectors:

phi, theta = rotation.spherical_from_vector(vect)
point = self.soma.point_from_trunk_direction(phi, theta)
new_points.append(point)
Expand Down
1 change: 0 additions & 1 deletion neurots/morphmath/point_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class DynamicPointArray:
"""

def __init__(self, initial_capacity=100000, resize_factor=2.0):

self._size = 0
self._capacity = initial_capacity
self._resize_factor = resize_factor
Expand Down
1 change: 0 additions & 1 deletion neurots/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def convert_from_legacy_neurite_type(data):
"""Convert legacy neurite type names, basal -> basal_dendrite and apical -> apical_dendrite."""
old_data = deepcopy(data)
for key, _data in old_data.items():

if key == "apical":
neurite_type_warning(key)
data["apical_dendrite"] = data.pop("apical")
Expand Down
2 changes: 0 additions & 2 deletions tests/astrocyte/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def _input_params():


def test_constructor():

c = tested.SpaceColonizationContext(_input_params())

npt.assert_equal(len(c.endfeet_targets.points), 2)
Expand All @@ -52,7 +51,6 @@ def test_constructor():


def test_methods():

c = tested.SpaceColonizationContext(_input_params())

npt.assert_allclose(c.kill_distance(0.1), 15.0 * 0.1)
Expand Down
2 changes: 0 additions & 2 deletions tests/astrocyte/test_grower.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def _parameters():


def _distributions():

path = _path / "bio_path_distribution.json"
with open(path, "r", encoding="utf-8") as f:
distributions = json.load(f)
Expand Down Expand Up @@ -216,7 +215,6 @@ def _legacy_rng():


def _check_neurots_soma(soma):

expected_points = np.array(
[
[-5.760930017396721, 14.022942101967232, -1.909993715025774],
Expand Down
Loading

0 comments on commit 63b0065

Please sign in to comment.