Пример #1
0
def test_draw_filter_neurite():
    for mode in ['2d', '3d']:
        viewer.draw(nrn, mode=mode, neurite_type=NeuriteType.basal_dendrite)
        assert_allclose(common.plt.gca().get_ylim(),
                        [-30., 78], atol=5)

    common.plt.close('all')
Пример #2
0
def test_draw_filter_neurite():
    for mode in ['2d', '3d']:
        viewer.draw(nrn, mode=mode, neurite_type=NeuriteType.basal_dendrite)
        assert_allclose(common.plt.gca().get_ylim(),
                        [-30., 78], atol=5)

    common.plt.close('all')
Пример #3
0
def test_draw_neuron3d():
    viewer.draw(nrn, mode='3d')
    common.plt.close('all')

    nt.assert_raises(NotImplementedError,
                     viewer.draw,
                     nrn,
                     mode='3d',
                     realistic_diameters=True)
Пример #4
0
def visualize(file_path):
    """ Code to visualize the neuron """
    nrn = nm.load_neuron(file_path)
    fig, ax = viewer.draw(nrn)
    fig.show()
    input()
    fig, ax = viewer.draw(nrn, mode='3d')
    fig.show()
    input()
Пример #5
0
def test_writing_output():
    fig_name = 'Figure.png'

    tempdir = tempfile.mkdtemp('test_viewer')
    try:
        old_dir = os.getcwd()
        os.chdir(tempdir)
        viewer.draw(nrn, mode='2d', output_path='subdir')
        nt.ok_(os.path.isfile(os.path.join(tempdir, 'subdir', fig_name)))
    finally:
        os.chdir(old_dir)
        shutil.rmtree(tempdir)
        common.plt.close('all')
Пример #6
0
def test_writing_output():
    fig_name = 'Figure.png'

    tempdir = tempfile.mkdtemp('test_viewer')
    try:
        old_dir = os.getcwd()
        os.chdir(tempdir)
        viewer.draw(nrn, mode='2d', output_path='subdir')
        nt.ok_(os.path.isfile(os.path.join(tempdir, 'subdir', fig_name)))
    finally:
        os.chdir(old_dir)
        shutil.rmtree(tempdir)
        common.plt.close('all')
Пример #7
0
def draw_neuron(neuron, cut_plane_position, cut_leaves=None):
    '''Draw the neuron in the xy, yz and xz planes.

    Parameters:
        neuron: a Neuron
        cut_plane_position: a tuple (plane, position) like ('Z', 27)
                            that can be specified to add the cut plane on
                            the relevant plots
        cut_leaves: leaves to be highlighted by blue circles
    '''
    figures = dict()
    for draw_plane in ['yz', 'xy', 'xz']:
        fig, axes = viewer.draw(neuron, plane=draw_plane)
        figures[draw_plane] = (fig, axes)

        if cut_leaves is not None:
            import matplotlib
            slice_index = {'yz': [1, 2], 'xy': [0, 1], 'xz': [0, 2]}
            for point in cut_leaves:
                point_2d = point[slice_index[draw_plane]]
                axes.add_artist(matplotlib.patches.Circle(point_2d, radius=2))

        if cut_plane_position:
            cut_plane, position = cut_plane_position
            for axis, line_func in zip(draw_plane, ['axvline', 'axhline']):
                if axis == cut_plane.lower():
                    getattr(axes, line_func)(position)
    return figures
def get_list_of_diff_section_types(morphology, apical_point_sections):

    morph = morphology

    _, ax = draw(morph)

    apical_trunk_sections = []

    for apical_point_section in apical_point_sections:
        some_trunk_sections = list(apical_point_section.iupstream())
        apical_trunk_sections = list(
            set(apical_trunk_sections) | set(some_trunk_sections))

    apical_trunk_ids = [section.id for section in apical_trunk_sections]
    apical_trunk_points = [
        section.points[-1, :2] for section in apical_trunk_sections
    ]
    for point in apical_trunk_points:
        ax.plot(point[0], point[1], 'bo', ms=5)

    apical_tuft_sections = []

    for apical_point_section in apical_point_sections:
        some_tuft_sections = list(apical_point_section.ipreorder())
        #print some_tuft_sections
        apical_tuft_sections = apical_tuft_sections + some_tuft_sections
    """!!!!!!"""
    apical_tuft_sections = [
        sec for sec in apical_tuft_sections if sec not in apical_point_sections
    ]
    """!!!!!!"""

    apical_tuft_ids = [section.id for section in apical_tuft_sections]
    apical_tuft_points = [
        section.points[-1, :2] for section in apical_tuft_sections
    ]
    for point in apical_tuft_points:
        ax.plot(point[0], point[1], 'go', ms=5)

    filter1 = lambda n: n.type == nm.APICAL_DENDRITE
    all_sections = list(nm.iter_sections(morph, neurite_filter=filter1))
    all_ids = [section.id for section in all_sections]
    oblique_ids = set(all_ids) - (set(apical_trunk_ids) | set(apical_tuft_ids))
    oblique_sections = [
        section for section in all_sections if section.id in oblique_ids
    ]
    oblique_points = [section.points[-1, :2] for section in oblique_sections]
    for point in oblique_points:
        ax.plot(point[0], point[1], 'yo', ms=5)

    plt.show()

    section_types = {
        'tuft': apical_tuft_sections,
        'trunk': apical_trunk_sections,
        'obliques': oblique_sections
    }

    return section_types
Пример #9
0
def view(input_file, plane, backend):
    '''A simple neuron viewer'''
    if backend == 'matplotlib':
        from neurom.viewer import draw
        kwargs = {
            'mode': '3d' if plane == '3d' else '2d',
        }
        if plane != '3d':
            kwargs['plane'] = plane
        draw(load_neuron(input_file), **kwargs)
    else:
        from neurom.view.plotly import draw
        draw(load_neuron(input_file), plane=plane)

    if backend == 'matplotlib':
        import matplotlib.pyplot as plt
        plt.show()
Пример #10
0
def view(input_file, plane, backend):
    '''A simple neuron viewer'''
    if backend == 'matplotlib':
        from neurom.viewer import draw
        kwargs = {
            'mode': '3d' if plane == '3d' else '2d',
        }
        if plane != '3d':
            kwargs['plane'] = plane
        draw(load_neuron(input_file), **kwargs)
    else:
        from neurom.view.plotly import draw
        draw(load_neuron(input_file), plane=plane)

    if backend == 'matplotlib':
        import matplotlib.pyplot as plt
        plt.show()
Пример #11
0
def show_nrn(neuron):
    ds.save_to_swc(filename, gid=neuron)
    import neurom as nm
    from neurom import viewer
    nrn = nm.load_neuron(filename)

    fig, ax = viewer.draw(nrn)
    plt.axis('off')
    fig.suptitle("")
    ax.set_title("")
    plt.tight_layout()
    plt.show()
Пример #12
0
def test_draw_dendrogram():
    viewer.draw(pt_nrn, mode='dendrogram')
    plt.close('all')
Пример #13
0
def test_draw_soma3d():
    viewer.draw(pt_nrn.soma, mode='3d')
    viewer.draw(nrn.soma, mode='3d')
    plt.close('all')
Пример #14
0
def test_draw_dendrogram():
    viewer.draw(nrn, mode='dendrogram')
    common.plt.close('all')
Пример #15
0
def test_invalid_object_raises():
    class Dummy(object):
        pass

    viewer.draw(Dummy())
Пример #16
0
def test_invalid_combo_raises():
    with pytest.raises(viewer.NotDrawableError):
        viewer.draw(nrn.soma, mode='dendrogram')
Пример #17
0
def test_draw_soma():
    viewer.draw(nrn.soma)
    common.plt.close('all')
Пример #18
0
def test_draw_tree():
    viewer.draw(pt_nrn.neurites[0])
    viewer.draw(nrn.neurites[0])
    plt.close('all')
Пример #19
0
def test_invalid_draw_mode_raises():
    with pytest.raises(viewer.InvalidDrawModeError):
        viewer.draw(nrn, mode='4d')
Пример #20
0
def test_invalid_object_raises():
    class Dummy(object):
        pass
    viewer.draw(Dummy())
Пример #21
0
def test_invalid_combo_raises():
    viewer.draw(nrn.soma, mode='dendrogram')
Пример #22
0
def test_invalid_draw_mode_raises():
    viewer.draw(nrn, mode='4d')
Пример #23
0
def test_draw_dendrogram():
    viewer.draw(nrn, mode='dendrogram')
    common.plt.close('all')

    viewer.draw(nrn.neurites[0], mode='dendrogram')
    common.plt.close('all')
Пример #24
0
def test_draw_soma3d():
    viewer.draw(nrn.soma, mode='3d')
    common.plt.close('all')
Пример #25
0
    axon = " (axon) " if i == neurite and "starbust" not in filename else ""
    print("Asymmetry{}:".format(axon), np.average(asyms) / max_asym(num_tips))

# Sholl analysis

sholl = nm.get("sholl_frequency", nrn, step_size=10.)
print(sholl)

x = np.arange(10., (len(sholl) + 1) * 10, 10)

fig, ax = plt.subplots()

ax.bar(x, sholl, width=10)
ax.set_xlim(x.min() - 5, x[np.where(sholl > 0)[0][-1]] + 5)
ax.set_xlabel("Sholl radius ($\mu$m)")
ax.set_ylabel("Intersections")
plt.tight_layout()

fig, _ = viewer.draw(nrn)
fig, _ = viewer.draw(nrn.neurites[neurite])

for ax in fig.axes:
    ax.set_title("")

import matplotlib.pyplot as plt
plt.axis('off')
fig.suptitle("")
plt.tight_layout()
plt.show()
Пример #26
0
    pca.fit(data)
    return pca


pca = doPCA(PcaData)

files2 = glob.glob(os.curdir + '/*edit.swc')  #load all Filenames of SWC files

for item in files2:
    nrn = nm.load_neuron(item)

#nrn = nm.load_neuron(os.curdir + '/Image001-007-01.CNG.swc')

from neurom import viewer

fig, ax = viewer.draw(nrn)
fig.show()
fig, ax = viewer.draw(nrn, mode='3d')  # valid modes '2d', '3d', 'dendrogram'
fig.show()


def sec_len(sec):
    '''Return the length of a section'''
    return mm.section_length(sec.points)


print('Total neurite length (sections):',
      sum(sec_len(s) for s in nm.iter_sections(nrn)))

# Get length of all neurites in cell by iterating over segments,
# and summing the segment lengths.
Пример #27
0
def test_draw_neuron3d():
    viewer.draw(nrn, mode='3d')
    common.plt.close('all')

    with pytest.raises(NotImplementedError):
        viewer.draw(nrn, mode='3d', realistic_diameters=True)
Пример #28
0
def test_draw_dendrogram_empty_segment():
    neuron = load_neuron(os.path.join(DATA_PATH, 'empty_segments.swc'))
    viewer.draw(neuron, mode='dendrogram')
    common.plt.close('all')
Пример #29
0
def test_invalid_object_raises():
    with pytest.raises(viewer.NotDrawableError):
        class Dummy:
            pass
        viewer.draw(Dummy())
Пример #30
0
def test_invalid_object_raises():
    viewer.draw(Dummy())
Пример #31
0
def test_writing_output():
    with tempfile.TemporaryDirectory() as folder:
        output_dir = Path(folder, 'subdir')
        viewer.draw(nrn, mode='2d', output_path=output_dir)
        assert (output_dir / 'Figure.png').is_file()
        common.plt.close('all')
Пример #32
0
def test_draw_tree3d():
    viewer.draw(nrn.neurites[0], mode='3d')
    common.plt.close('all')
Пример #33
0
def test_draw_neuron():
    viewer.draw(nrn)
    common.plt.close('all')
Пример #34
0
def test_draw_tree3d():
    viewer.draw(pt_nrn.neurites[0], mode='3d')
    viewer.draw(nrn.neurites[0], mode='3d')
    plt.close('all')
def multiple_apical_points(morphology):

    morph = morphology

    apical = [
        neurite for neurite in morph.neurites
        if nm.NeuriteType.apical_dendrite == neurite.type
    ]

    if not apical:
        L.warning('No apical found')
        return None
    elif 1 < len(apical):
        L.warning('Too many apical dendrites')
        return None

    apical = apical[0]

    dist_apical_point = []
    apical_points_and_distances = []

    closer_apical_points = []

    point = get_apical_point(apical, morph)

    if point is not None:
        dist = nm.morphmath.point_dist(morph.soma.center,
                                       point.points[-1, COLS.XYZ])

        apical_points_and_distances.append([point, dist])

    while any(point[1] < 200 for point in apical_points_and_distances):
        #point = get_apical_point(apical, morph)
        #apical_point.append(point)
        #dist_apical_point.append(nm.morphmath.point_dist(morph.soma.center, point.points[-1, COLS.XYZ]))
        #a, b = min(point[1] for idx, point in enumerate(apical_points_and_distances))
        mn, idx = min((apical_points_and_distances[i][1], i)
                      for i in range(len(apical_points_and_distances)))
        #print mn, idx
        #print apical_points_and_distances
        new_apical_points = []
        new_apical_point_added = []

        for child in apical_points_and_distances[idx][0].children:

            root_node = child
            tree = nm.core._neuron.Neurite(root_node)
            point = get_apical_point(tree, morph)
            if point is not None:

                dist = nm.morphmath.point_dist(morph.soma.center,
                                               point.points[-1, COLS.XYZ])

                new_apical_point_added.append(True)

                apical_points_and_distances.append([point, dist])
            else:
                new_apical_point_added.append(False)
        """ avoid infinite loop"""
        #print new_apical_point_added
        if any(added == True for added in new_apical_point_added):
            del apical_points_and_distances[idx]
        else:
            closer_apical_points.append(apical_points_and_distances[idx])
            del apical_points_and_distances[idx]

    apical_points_and_distances = apical_points_and_distances + closer_apical_points
    #print apical_points_and_distances

    apical_points = []

    for point in apical_points_and_distances:
        apical_points.append(point[0])

    _, ax = draw(morph)
    for point in apical_points:
        pos = point.points[-1, COLS.XYZ]
        ax.scatter([
            pos[0],
        ], [
            pos[1],
        ])
    plt.show()

    return apical_points
Пример #36
0
def test_draw_neuron3d():
    viewer.draw(nrn, mode='3d')
    common.plt.close('all')
Пример #37
0
ds.set_object_properties(n, dendrites_params=dend_params, axon_params=vp_axon)

ds.simulate(70000 * minute)
print(ds.get_kernel_status()["time"])

ds.plot.plot_neurons(show=True)

n.to_swc("pyramidal-cell.swc")
n.to_neuroml("bipolar_cell.nml")

import neurom as nm
from neurom import viewer
nrn = nm.load_neuron("pyramidal-cell.swc")

fig, _ = viewer.draw(nrn)

for ax in fig.axes:
    ax.set_title("")

tree = n[0].axon.get_tree()

import matplotlib.pyplot as plt
plt.axis('off')
fig.suptitle("")
plt.tight_layout()
plt.show()
#~ tree.show_dendrogram()

print("Asymmetry of axon:", ds.structure.tree_asymmetry(n[0].axon))
Пример #38
0
def test_draw_tree():
    viewer.draw(nrn.neurites[0])
    common.plt.close('all')
Пример #39
0
def test_draw_soma3d():
    viewer.draw(nrn.soma, mode='3d')
    common.plt.close('all')
Пример #40
0
def test_draw_neuron3d():
    viewer.draw(nrn, mode='3d')
    common.plt.close('all')
Пример #41
0
def test_invalid_draw_mode_raises():
    viewer.draw(nrn, mode='4d')
Пример #42
0
def test_draw_tree3d():
    viewer.draw(nrn.neurites[0], mode='3d')
    common.plt.close('all')
Пример #43
0
def test_invalid_combo_raises():
    viewer.draw(nrn.soma, mode='dendrogram')
Пример #44
0
def test_draw_neuron3d():
    viewer.draw(pt_nrn, mode='3d')
    viewer.draw(nrn, mode='3d')
    plt.close('all')
Пример #45
0
def test_draw_neuron():
    viewer.draw(nrn)
    common.plt.close('all')
Пример #46
0
def test_draw_soma():
    viewer.draw(pt_nrn.soma)
    viewer.draw(nrn.soma)
    plt.close('all')
Пример #47
0
def test_draw_tree():
    viewer.draw(nrn.neurites[0])
    common.plt.close('all')
Пример #48
0
import neurom as nm
from neurom import viewer
nrn = nm.load_neuron('test.swc')
print nrn
fig, ax = viewer.draw(nrn)
fig.show()
Пример #49
0
def test_draw_soma():
    viewer.draw(nrn.soma)
    common.plt.close('all')
Пример #50
0
def test_draw_neuron():
    viewer.draw(pt_nrn)
    viewer.draw(nrn)
    plt.close('all')