-
Notifications
You must be signed in to change notification settings - Fork 1
/
CA1_volume.py
110 lines (71 loc) · 2.83 KB
/
CA1_volume.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
import sys
import numpy as np
from neural_geometry.geometry import transform_volume, make_alpha_shape
from neural_geometry.linear_volume import LinearVolume
max_u = 6000.
max_v = 2500.
def CA1_volume_transform(u, v, l):
return u, v, l
def CA1_volume(u, v, l, rotate=None):
"""Parametric equations of the CA1 volume."""
return transform_volume(CA1_volume_transform, u, v, l, rotate=rotate)
def CA1_meshgrid(extent_u, extent_v, extent_l, resolution=[3, 3, 3], rotate=None, return_uvl=False):
ures, vres, lres = resolution
obs_u = np.linspace(extent_u[0], extent_u[1], num=ures)
obs_v = np.linspace(extent_v[0], extent_v[1], num=vres)
obs_l = np.linspace(extent_l[0], extent_l[1], num=lres)
u, v, l = np.meshgrid(obs_u, obs_v, obs_l, indexing='ij')
xyz = CA1_volume(u, v, l, rotate=rotate)
if return_uvl:
return xyz, obs_u, obs_v, obs_l
else:
return xyz
def make_CA1_volume(extent_u, extent_v, extent_l, rotate=None, resolution=[3, 3, 3], return_xyz=False):
"""Creates an linear volume based on the parametric equations of the CA1 volume."""
xyz, obs_u, obs_v, obs_l = CA1_meshgrid(extent_u, extent_v, extent_l, \
rotate=rotate, resolution=resolution,
return_uvl=True)
vol = LinearVolume(obs_u, obs_v, obs_l, xyz)
if return_xyz:
return vol, xyz
else:
return vol
def test_mplot_volume():
extent_u = [0.0, 4000.0]
extent_v = [0.0, 1250.0]
extent_l = [0.0, 100.0]
vol = make_CA1_volume(extent_u, extent_v, extent_l, resolution=[3, 3, 3])
from mayavi import mlab
vol.mplot_volume(color=(0, 1, 0), opacity=1.0, ures=1, vres=1)
mlab.show()
def test_tri():
extent_u = [0.0, 4000.0]
extent_v = [0.0, 1250.0]
extent_l = [0.0, 100.0]
vol = make_CA1_volume(extent_u, extent_v, extent_l, resolution=[3, 3, 3])
tri = vol.create_triangulation(ures=1, vres=1, lres=1)
return vol, tri
def test_alpha_shape():
extent_u = [0.0, 4000.0]
extent_v = [0.0, 1250.0]
extent_l = [0.0, 100.0]
vol = make_CA1_volume(extent_u, extent_v, extent_l, resolution=[3, 3, 3])
alpha = make_alpha_shape(vol, alpha_radius=1200.)
return vol, alpha
if __name__ == '__main__':
test_alpha_shape()
# test_mplot_volume()
# vol, tri = test_tri()
# points = tri.points
# simplices = tri.simplices
# import matplotlib.pyplot as plt
# import mpl_toolkits.mplot3d as plt3d
# axes = plt3d.Axes3D(plt.figure())
# vts = points[simplices, :]
# poly = plt3d.art3d.Poly3DCollection(vts)
# poly.set_alpha(0.2)
# poly.set_color('grey')
# axes.add_collection3d(poly)
# axes.plot(points[:,0], points[:,1], points[:,2], 'ko')
# axes.set_aspect('equal')
# plt.show()