def test_axon_dist_from_soma():
# A small grid
xg, yg = np.meshgrid([-1, 0, 1], [-1, 0, 1], indexing='xy')
# When axon locations are snapped to the grid, a really short axon should
# have zero distance to the soma:
for x_soma in [-1.0, -0.2, 0.51]:
axon = np.array([[i, i] for i in np.linspace(x_soma, x_soma + 0.01)])
_, dist = p2p.retina.axon_dist_from_soma(axon, xg, yg)
npt.assert_almost_equal(dist, 0.0)
# On this simple grid, a diagonal axon should have dist [0, sqrt(2), 2]:
for sign in [-1.0, 1.0]:
for num in [10, 20, 50]:
axon = np.array([[i, i] for i in np.linspace(sign, -sign, num)])
_, dist = p2p.retina.axon_dist_from_soma(axon, xg, yg)
npt.assert_almost_equal(dist, np.array([0.0, np.sqrt(2), 2.0]))
# An axon that does not live near the grid should return infinite distance
axon = np.array([[i, i] for i in np.linspace(1000.0, 1500.0)])
_, dist = p2p.retina.axon_dist_from_soma(axon, xg, yg)
npt.assert_equal(np.isinf(dist), True)
评论列表
文章目录