def test_tree(): with get_fig_2d() as (fig, ax): tree = fst_neuron.neurites[0] view.plot_tree(ax, tree, color='black', diameter_scale=None, alpha=1., linewidth=1.2) collection = ax.collections[0] nt.eq_(collection.get_linewidth()[0], 1.2) np.testing.assert_allclose(collection.get_color(), np.array([[0., 0., 0., 1.]])) with get_fig_2d() as (fig, ax): nt.assert_raises(AssertionError, view.plot_tree, ax, tree, plane='wrong') with get_fig_2d() as (fig, ax): tree = simple_neuron.neurites[0] view.plot_tree(ax, tree) np.testing.assert_allclose(ax.dataLim.bounds, (-5., 0., 11., 5.), atol=1e-10)
def plot_neuron_on_density( population, # pylint: disable=too-many-arguments bins=100, new_fig=True, subplot=111, levels=None, plane='xy', colorlabel='Nodes per unit area', labelfontsize=16, color_map='Reds', no_colorbar=False, threshold=0.01, neurite_type=NeuriteType.basal_dendrite, **kwargs): """Plots the 2d histogram of the center coordinates of segments in the selected plane and superimposes the view of the first neurite of the collection. """ _, ax = common.get_figure(new_fig=new_fig) view.plot_tree(ax, population.neurites[0]) return plot_density(population, plane=plane, bins=bins, new_fig=False, subplot=subplot, colorlabel=colorlabel, labelfontsize=labelfontsize, levels=levels, color_map=color_map, no_colorbar=no_colorbar, threshold=threshold, neurite_type=neurite_type, **kwargs)
def test_tree(): neuron = load_neuron( os.path.join(SWC_PATH, 'simple-different-section-types.swc')) expected_colors = { 'black': np.array([[0., 0., 0., 1.] for _ in range(3)]), None: [[1., 0., 0., 1.], [1., 0., 0., 1.], [0.501961, 0., 0.501961, 1.]] } for input_color, expected_colors in expected_colors.items(): with get_fig_2d() as (fig, ax): tree = neuron.neurites[0] view.plot_tree(ax, tree, color=input_color, diameter_scale=None, alpha=1., linewidth=1.2) collection = ax.collections[0] eq_(collection.get_linewidth()[0], 1.2) assert_array_almost_equal(collection.get_colors(), expected_colors) with get_fig_2d() as (fig, ax): assert_raises(AssertionError, view.plot_tree, ax, tree, plane='wrong') with get_fig_2d() as (fig, ax): tree = simple_neuron.neurites[0] view.plot_tree(ax, tree) assert_allclose(ax.dataLim.bounds, (-5., 0., 11., 5.), atol=1e-10)
def test_one_point_branch(): test_section = Section(points=np.array([[1., 1., 1., 0.5, 2, 1, 0]])) for diameter_scale, linewidth in it.product((1.0, None), (0.0, 1.2)): with get_fig_2d() as (fig, ax): view.plot_tree(ax, test_section, diameter_scale=diameter_scale, linewidth=linewidth) with get_fig_3d() as (fig, ax): view.plot_tree3d(ax, test_section, diameter_scale=diameter_scale, linewidth=linewidth)
def test_one_point_branch(): test_section = Neurite(Section(points=np.array([[1., 1., 1., 0.5, 2, 1, 0]]))) for diameter_scale, linewidth in it.product((1.0, None), (0.0, 1.2)): with get_fig_2d() as (fig, ax): view.plot_tree(ax, test_section, diameter_scale=diameter_scale, linewidth=linewidth) with get_fig_3d() as (fig, ax): view.plot_tree3d(ax, test_section, diameter_scale=diameter_scale, linewidth=linewidth)
def test_neuron(get_fig_2d): fig, ax = get_fig_2d view.plot_neuron(ax, fst_neuron) assert ax.get_title() == fst_neuron.name assert_allclose(ax.dataLim.get_points(), [ [-40.32853516, -57.600172], [64.74726272, 48.51626225], ]) with pytest.raises(AssertionError): view.plot_tree(ax, fst_neuron, plane='wrong')
def test_tree_diameter_real(get_fig_2d): fig, ax = get_fig_2d tree = neuron_different.neurites[0] for input_color, expected_colors in tree_colors.items(): view.plot_tree(ax, tree, color=input_color, alpha=1., linewidth=1.2, realistic_diameters=True) collection = ax.collections[0] assert collection.get_linewidth()[0] == 1.0 assert_array_almost_equal(collection.get_facecolors(), expected_colors) fig.clear()
def test_tree(): with get_fig_2d() as (fig, ax): tree = fst_neuron.neurites[0] view.plot_tree(ax, tree, color='black', diameter_scale=None, alpha=1., linewidth=1.2) collection = ax.collections[0] nt.eq_(collection.get_linewidth()[0], 1.2) np.testing.assert_allclose(collection.get_color(), np.array([[0., 0., 0., 1.]])) with get_fig_2d() as (fig, ax): nt.assert_raises(AssertionError, view.plot_tree, ax, tree, plane='wrong') with get_fig_2d() as (fig, ax): tree = simple_neuron.neurites[0] view.plot_tree(ax, tree) np.testing.assert_allclose(ax.dataLim.bounds, (-5., 0., 11., 5.), atol=1e-10)
def plot_neuron_on_density(population, # pylint: disable=too-many-arguments bins=100, new_fig=True, subplot=111, levels=None, plane='xy', colorlabel='Nodes per unit area', labelfontsize=16, color_map='Reds', no_colorbar=False, threshold=0.01, neurite_type=NeuriteType.basal_dendrite, **kwargs): '''Plots the 2d histogram of the center coordinates of segments in the selected plane and superimposes the view of the first neurite of the collection. ''' _, ax = common.get_figure(new_fig=new_fig) view.plot_tree(ax, population.neurites[0]) return plot_density(population, plane=plane, bins=bins, new_fig=False, subplot=subplot, colorlabel=colorlabel, labelfontsize=labelfontsize, levels=levels, color_map=color_map, no_colorbar=no_colorbar, threshold=threshold, neurite_type=neurite_type, **kwargs)
def test_tree_bounds(get_fig_2d): fig, ax = get_fig_2d view.plot_tree(ax, neuron_different.neurites[0]) np.testing.assert_allclose(ax.dataLim.bounds, (-5., 0., 11., 5.))
def test_tree_invalid(get_fig_2d): fig, ax = get_fig_2d with pytest.raises(AssertionError): view.plot_tree(ax, neuron_different.neurites[0], plane='wrong')