-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge "Add / correct diameter models, fix relevant tests."
- Loading branch information
Showing
7 changed files
with
291 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# SWC structure for testing: | ||
# index, type, x, y, z, radius, parent | ||
|
||
1 1 0 0 0 1. -1 | ||
2 3 1 0 0 2. 1 | ||
3 3 2 0 0 1.9 2 | ||
4 3 3 0 0 1.8 3 | ||
5 3 4 0 0 1.7 4 | ||
6 3 5 0 0 1.6 5 | ||
7 3 6 0 0 1.5 6 | ||
8 3 7 0 0 1.4 7 | ||
9 3 7 1 0 1.4 8 | ||
10 3 7 2 0 1.3 9 | ||
11 3 7 3 0 1.2 10 | ||
12 3 7 4 0 1.1 11 | ||
13 3 7 5 0 1.0 12 | ||
14 3 7 -1 0 1.0 8 | ||
15 3 7 -2 0 1.2 14 | ||
16 3 7 -3 0 1.0 15 | ||
17 3 7 -4 0 1.1 16 | ||
18 3 7 -5 0 1.0 17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,82 @@ | ||
import neurom | ||
import os | ||
|
||
from numpy.testing import assert_array_equal | ||
|
||
'''Test tns.generate.diametrizer code''' | ||
import os | ||
from nose import tools as nt | ||
import numpy as np | ||
from numpy.testing import assert_array_almost_equal | ||
from tns.generate import diametrizer | ||
import morphio | ||
import tns.generate.diametrizer as test_module | ||
from tns import extract_input | ||
|
||
_path = os.path.dirname(os.path.abspath(__file__)) | ||
NEU_PATH1 = os.path.join(_path, '../test_data/diam_simple.swc') | ||
NEU_PATH2 = os.path.join(_path, '../test_data/simple.swc') | ||
|
||
MODEL = {3: {'Rall_ratio': 2./3., | ||
'siblings_ratio': 1.0, | ||
'taper': [0.1], | ||
'term': [0.6], | ||
'trunk': [4., 3.], | ||
'trunk_taper': [0.2]}} | ||
|
||
def test_sample(): | ||
assert(diametrizer.sample([0.]) == 0.) | ||
np.random.seed(0) | ||
assert(diametrizer.sample([1., 1., 1., 2., 2., 3.]) == 2.) | ||
|
||
def test_bifurcator(): | ||
d1 = diametrizer.bifurcator(1.0, 2., 3./2., 1.) | ||
assert(d1 == 0.6299605249474366) | ||
d1 = diametrizer.bifurcator(1.0, 2., 1., 1.) | ||
assert(d1 == 0.5) | ||
d1 = diametrizer.bifurcator(1.0, 2., 1., 0.5) | ||
assert(d1 == 0.6666666666666666) | ||
|
||
|
||
def test_taper_section_diam(): | ||
neu1 = morphio.mut.Morphology(NEU_PATH1) | ||
section = neu1.root_sections[0] | ||
diametrizer.taper_section_diam(section, 4., 0.3, 0.07, 100.) | ||
assert_array_almost_equal(section.diameters, | ||
[4. , 3.8, 3.6, 3.4, 3.2, 3. , 2.8]) | ||
|
||
def test_diametrize_constant_per_section(): | ||
neu2 = morphio.mut.Morphology(NEU_PATH2) # has to be loaded to start clean | ||
diametrizer.diametrize_constant_per_section(neu2) | ||
assert_array_almost_equal(morphio.Morphology(neu2).diameters, | ||
[2., 2., 2.5, 2.5, 2.5, 2.5, 2., 2., 3., 3., 3., 3.]) | ||
|
||
def test_diametrize_constant_all(): | ||
neuron = morphio.mut.Morphology(os.path.join(_path, '..', 'test_data', 'simple.swc')) | ||
test_module.diametrize_constant_all(neuron) | ||
def test_diametrize_constant_per_neurite(): | ||
neu2 = morphio.mut.Morphology(NEU_PATH2) # has to be loaded to start clean | ||
diametrizer.diametrize_constant_per_neurite(neu2) | ||
assert_array_almost_equal(morphio.Morphology(neu2).diameters, | ||
[2.333333, 2.333333, 2.333333, 2.333333, 2.333333, 2.333333, | ||
2.666667, 2.666667, 2.666667, 2.666667, 2.666667, 2.666667]) | ||
|
||
# assert_array_equal(morphio.Morphology(neuron).diameters, | ||
# [2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5]) | ||
def test_diametrize_smoothing(): | ||
neu1 = morphio.mut.Morphology(NEU_PATH1) # has to be loaded to start clean | ||
diametrizer.diametrize_smoothing(neu1) | ||
assert_array_almost_equal(morphio.Morphology(neu1).diameters, | ||
[4. , 3.6 , 3.2 , 2.8 , 2.4 , 2. , | ||
1.599999, 2.8 , 2.8 , 2.5312 , 2.2624 , 1.9936 , | ||
1.7248 , 2.8 , 2.8 , 2.688 , 2.576 , 2.464 , | ||
2.352]) | ||
|
||
def test_diametrize_constant(): | ||
neuron = morphio.mut.Morphology(os.path.join(_path, '..', 'test_data', 'simple.swc')) | ||
test_module.diametrize_constant(neuron) | ||
def test_diametrize_from_root(): | ||
neu1 = morphio.mut.Morphology(NEU_PATH1) # has to be loaded to start clean | ||
np.random.seed(0) # ensure constant random number for sampling | ||
diametrizer.diametrize_from_root(neu1, MODEL) | ||
assert_array_almost_equal(morphio.Morphology(neu1).diameters, | ||
[3. , 2.9 , 2.8 , 2.7 , 2.6 , 2.5 , | ||
2.4 , 2.4 , 0.848528, 0.831558, 0.814587, 0.797616, | ||
0.780646, 2.4 , 0.848528, 0.831558, 0.814587, 0.797616, | ||
0.780646]) | ||
|
||
assert_array_equal(morphio.Morphology(neuron).diameters, | ||
[2., 2., 2.5, 2.5, 2.5, 2.5, 2., 2., 3., 3., 3., 3.]) | ||
def test_diametrize_from_tips(): | ||
neu1 = morphio.mut.Morphology(NEU_PATH1) # has to be loaded to start clean | ||
np.random.seed(0) # ensure constant random number for sampling | ||
diametrizer.diametrize_from_tips(neu1, MODEL) | ||
assert_array_almost_equal(morphio.Morphology(neu1).diameters, | ||
[1.770291, 1.711282, 1.652272, 1.593262, 1.534253, 1.475243, | ||
1.416233, 1.416233, 0.62 , 0.6076 , 0.6 , 0.6 , | ||
0.6 , 1.416233, 0.62 , 0.6076 , 0.6 , 0.6 , | ||
0.6]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.