Skip to content

Commit

Permalink
Merge pull request #141 from BlueBrain/morph-utils-tests
Browse files Browse the repository at this point in the history
Add morphology-utils tests
  • Loading branch information
AurelienJaquier authored May 28, 2024
2 parents 8e400ce + ea96f68 commit 8d5b0ab
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 10 deletions.
6 changes: 3 additions & 3 deletions bluepyemodel/emodel_pipeline/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from bluepyemodel.evaluation.utils import define_bAP_protocol
from bluepyemodel.evaluation.utils import define_EPSP_feature
from bluepyemodel.evaluation.utils import define_EPSP_protocol
from bluepyemodel.model.morphology_utils import get_basal_and_apical_lengths
from bluepyemodel.model.morphology_utils import get_basal_and_apical_max_radial_distances
from bluepyemodel.tools.utils import make_dir
from bluepyemodel.tools.utils import parse_checkpoint_path
from bluepyemodel.tools.utils import read_checkpoint
Expand Down Expand Up @@ -1103,7 +1103,7 @@ def run_and_plot_bAP(

# get basal and apical lengths
morph_path = cell_evaluator.cell_model.morphology.morphology_path
max_basal_length, max_apical_length = get_basal_and_apical_lengths(morph_path)
max_basal_length, max_apical_length = get_basal_and_apical_max_radial_distances(morph_path)
max_basal_length = int(max_basal_length)
max_apical_length = int(max_apical_length)

Expand Down Expand Up @@ -1178,7 +1178,7 @@ def run_and_plot_EPSP(

# get basal and apical lengths
morph_path = cell_evaluator.cell_model.morphology.morphology_path
max_basal_length, max_apical_length = get_basal_and_apical_lengths(morph_path)
max_basal_length, max_apical_length = get_basal_and_apical_max_radial_distances(morph_path)
max_basal_length = int(max_basal_length)
max_apical_length = int(max_apical_length)

Expand Down
12 changes: 6 additions & 6 deletions bluepyemodel/model/morphology_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_apical_point_soma_distance(morph_path):
return neurom.morphmath.point_dist(apical_point, morphio_morph.soma.center)


def get_apical_length(morph_path):
def get_apical_max_radial_distance(morph_path):
"""Returns the max radial distance of the apical dendrites."""
import neurom

Expand All @@ -45,8 +45,8 @@ def get_apical_length(morph_path):
)


def get_basal_and_apical_lengths(morph_path):
"""Returns the max radial distance of the apical and basal dendrites."""
def get_basal_and_apical_max_radial_distances(morph_path):
"""Returns the max radial distances of the apical and basal dendrites."""
import neurom

neurom_morph = neurom.load_morphology(morph_path)
Expand All @@ -69,12 +69,12 @@ def get_hotspot_location(morph_path, hotspot_percent=20.0):
Args:
morph_path (str): path to the morphology
hotspot_percent (float): percentage of the radial apical length that is in the hot spot.
Here, we assume that the hotspot size is dependent on the apical length.
hotspot_percent (float): percentage of the radial apical distance that is in the hot spot.
Here, we assume that the hotspot size is dependent on the apical radial distance.
20% is in accordance with experiments from Larkum and Zhu, 2002
"""
ap_soma_dist = get_apical_point_soma_distance(morph_path)
apical_length = get_apical_length(morph_path)
apical_length = get_apical_max_radial_distance(morph_path)
hotspot_halfsize = apical_length * hotspot_percent / 2.0 / 100.0

return max((0.0, ap_soma_dist - hotspot_halfsize)), ap_soma_dist + hotspot_halfsize
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"gitpython",
"bluepyopt>=1.14.10",
"bluepyefe>=2.2.0",
"neurom>=3.0,<4.0",
"neurom>=3.0",
"efel>=5.5.5",
"configparser",
"neuron>=8.0",
Expand Down
75 changes: 75 additions & 0 deletions tests/unit_tests/test_morphology_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""Tests for EModelMetadata methods."""

"""
Copyright 2024, EPFL/Blue Brain Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import numpy
import pytest

from bluepyemodel.model.morphology_utils import get_apical_max_radial_distance
from bluepyemodel.model.morphology_utils import get_apical_point_soma_distance
from bluepyemodel.model.morphology_utils import get_basal_and_apical_max_radial_distances
from bluepyemodel.model.morphology_utils import get_hotspot_location

from tests.utils import DATA


@pytest.fixture
def morph_path():
return DATA / "morphology" / "C060114A5.asc"


def test_get_apical_point_soma_distance(morph_path):
"""Test get_apical_point_soma_distance function."""
soma_dist = get_apical_point_soma_distance(morph_path)
numpy.testing.assert_allclose(soma_dist, 624.8454)


def test_get_apical_max_radial_distance(morph_path):
"""Test get_apical_length function."""
apical_max_radial_distance = get_apical_max_radial_distance(morph_path)
# increase tolerance because neurom v4 has changed behavior of 'max_radial_distance'
numpy.testing.assert_allclose(apical_max_radial_distance, 1044.1445, rtol=0.02)


def test_get_basal_and_apical_max_radial_distances(morph_path):
"""Test get_basal_and_apical_max_radial_distances function."""
basal_radial_dist, apical_radial_dist = get_basal_and_apical_max_radial_distances(morph_path)
# increase tolerance because neurom v4 has changed behavior of 'max_radial_distance'
numpy.testing.assert_allclose(apical_radial_dist, 1044.1445, rtol=0.02)
numpy.testing.assert_allclose(basal_radial_dist, 232.56221, rtol=0.1)


def test_get_hotspot_location(morph_path):
"""Test get_hotspot_location function."""
hotspot_start, hotspot_end = get_hotspot_location(morph_path)
# increase tolerance because neurom v4 has changed behavior of 'max_radial_distance'
numpy.testing.assert_allclose(hotspot_start, 520.430945, rtol=0.02)
numpy.testing.assert_allclose(hotspot_end, 729.259851, rtol=0.02)


def test_morphology_utils(morph_path):
"""Test that output of morphology_utils functions are consistent with one another."""
apical_max_dist_1 = get_apical_max_radial_distance(morph_path)
basal_max_dist, apical_max_dist_2 = get_basal_and_apical_max_radial_distances(morph_path)
soma_dist = get_apical_point_soma_distance(morph_path)
hotspot_start, hotspot_end = get_hotspot_location(morph_path)

assert apical_max_dist_1 == apical_max_dist_2
assert basal_max_dist < apical_max_dist_2
assert soma_dist < apical_max_dist_1
assert hotspot_start >= 0
assert hotspot_start < soma_dist < hotspot_end

0 comments on commit 8d5b0ab

Please sign in to comment.