-
Notifications
You must be signed in to change notification settings - Fork 30
/
test_channel_density_plots.py
94 lines (79 loc) · 3.28 KB
/
test_channel_density_plots.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
"""
Tests for channel density plot related methods
File: tests/analysis/test_channel_density_plots.py
Copyright 2023 NeuroML contributors
"""
import logging
import unittest
import neuroml
from pyneuroml.analysis.ChannelDensityPlot import (
get_channel_densities,
get_conductance_density_for_segments,
plot_channel_densities,
)
from pyneuroml.pynml import read_neuroml2_file
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
class TestChannelDensityPlots(unittest.TestCase):
"""Tests for ChannelDensityPlot"""
def test_get_channel_densities(self):
"""test get_channel_densities method."""
cell_file = "tests/plot/L23-example/HL23PYR.cell.nml"
cell = read_neuroml2_file(cell_file).cells[0]
print(cell.id)
channel_densities = get_channel_densities(cell)
total_num = 0
for channel, densities in channel_densities.items():
total_num += len(densities)
self.assertEqual(total_num, 22)
def test_get_conductance_density_for_segments(self):
"""Test get_conductance_density_for_segments."""
cell_file = "tests/plot/L23-example/HL23PYR.cell.nml"
cell = read_neuroml2_file(cell_file).cells[0] # type: neuroml.Cell
print(cell.id)
channel_densities = get_channel_densities(cell)
channel_densities_Im = channel_densities["Im"]
data_Im = get_conductance_density_for_segments(cell, channel_densities_Im[0])
soma_group = cell.get_all_segments_in_group("soma_group")
self.assertEqual(data_Im[soma_group[0]], 3.06)
self.assertEqual(data_Im[soma_group[-1]], 3.06)
data_Im = get_conductance_density_for_segments(cell, channel_densities_Im[1])
axon_group = cell.get_all_segments_in_group("axon_group")
self.assertEqual(data_Im[axon_group[0]], 0.000000)
channel_densities_Ih = channel_densities["Ih"]
for cd in channel_densities_Ih:
if "NonUniform" in cd.__class__.__name__:
data_Ih = get_conductance_density_for_segments(cell, cd)
self.assertNotIn(soma_group[0], data_Ih.keys())
self.assertEqual(
len(data_Ih),
len(cell.get_all_segments_in_group("apical_dendrite_group")),
)
def test_plot_channel_densities(self):
"""Test the plot_channel_densities function."""
cell_file = "tests/plot/L23-example/HL23PYR.cell.nml"
cell = read_neuroml2_file(cell_file).cells[0] # type: neuroml.Cell
# check with channel densities
plot_channel_densities(
cell,
channel_density_ids=["Ih_apical", "Ih_somatic", "Ih_basal", "Ih"],
distance_plots=True,
show_plots_already=False,
target_directory="tests/analysis",
)
plot_channel_densities(
cell,
ion_channels=["Ih"],
distance_plots=True,
show_plots_already=False,
target_directory="tests/analysis",
)
# no channel densities or ion channels, so generate for all ion
# channels
plot_channel_densities(
cell,
distance_plots=True,
show_plots_already=False,
target_directory="tests/analysis",
)