/
named_neurites.py
150 lines (107 loc) · 4.23 KB
/
named_neurites.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# -*- coding: utf-8 -*-
#
# 3_space_embedding.py
#
# This file is part of DeNSE.
#
# Copyright (C) 2019 SeNEC Initiative
#
# DeNSE is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# DeNSE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with DeNSE. If not, see <http://www.gnu.org/licenses/>.
"""
This file shows how to create neurites with specific names.
"""
import dense as ds
from dense.units import *
''' Valid commands '''
print("\nValid commands\n==============")
# create neurites with generic parameters but custom names
neuron = ds.create_neurons(num_neurites=3,
neurite_names=["axon", "apical", "basal"])
print(neuron.neurites, "\n")
# create neurites with specfic parameters using the neurite_params entry
# to set the neurite names
axon_params = {"speed_growth_cone": 0.1*um/minute}
apical_params = {"speed_growth_cone": 0.05*um/minute}
basal_params = {"speed_growth_cone": 0.01*um/minute}
neurite_params = {
"axon": axon_params, "basal": basal_params, "apical": apical_params
}
neuron2 = ds.create_neurons(num_neurites=3, neurite_params=neurite_params)
print(neuron2.neurites, "\n")
# set parameters for all dendrites without specifying their names
neurite_params = {
"axon": {"speed_growth_cone": 0.1*um/minute},
"dendrites": {"speed_growth_cone": 0.02*um/minute}
}
neuron3 = ds.create_neurons(num_neurites=4, neurite_params=neurite_params)
for name, neurite in neuron3.neurites.items():
print("Neurite '{}' has speed {}".format(name, neurite.speed_growth_cone))
print("")
# set parameters for all dendrites and specify their names
neurite_params = {
"axon": {"speed_growth_cone": 0.1*um/minute},
"dendrites": {"speed_growth_cone": 0.02*um/minute}
}
neuron4 = ds.create_neurons(num_neurites=3, neurite_params=neurite_params,
neurite_names={"axon", "d1", "d2"})
for name, neurite in neuron4.neurites.items():
print("Neurite '{}' has speed {}".format(name, neurite.speed_growth_cone))
print("")
''' Invalid commands '''
print("Invalid commands\n================")
error_caught = False
try:
# not specifying "num_neurites" (default 0) with several parameter entries
n = ds.create_neurons(neurite_params=neurite_params)
print(n.neurites)
except Exception as e:
print("This invalid command generated the following exception:", e, "\n")
error_caught = True
assert error_caught, "Previous code should have failed " \
"(incompatible `num_neurites`)."
error_caught = False
neurite_params = {
"axon": {"speed_growth_cone": 0.1*um/minute},
"dendrite1": {"speed_growth_cone": 0.02*um/minute},
"dendrite2": {"speed_growth_cone": 0.02*um/minute}
}
try:
# different names in `neurite_names` and `neurite_params`
n = ds.create_neurons(num_neurites=3, neurite_params=neurite_params,
neurite_names=["axon", "d1", "d2"])
except Exception as e:
print("This invalid command generated the following exception:", e, "\n")
error_caught = True
assert error_caught, "Previous code should have failed (incompatible names)."
''' Compare methods '''
angles = {"axon": 90.*deg, "dendrite": 210.*deg}
params = {
"position": (0., 0.)*um,
"neurite_angles": angles,
"random_rotation_angles": False
}
# at neuron creation
neuron = ds.create_neurons(params=params, num_neurites=2,
neurite_names=["axon", "dendrite"])
# after neuron creation
neurons = ds.create_neurons(2)
neurons[5].create_neurites(2, names=["axon", "dendrite"], angles=angles)
ds.create_neurites(neurons[6], num_neurites=2, names=["axon", "dendrite"],
angles=angles)
import numpy as np
for k, v in angles.items():
assert np.isclose(neuron.neurite_angles[k], v)
for n in neurons:
for k, v in angles.items():
assert np.isclose(n.neurite_angles[k], v)