def test_eq(self): other = ezy.load_neuron(self.filename) nt.assert_true(self.neuron == other)
def test_construct_neuron_non_consecutive_ids_loads(): filename = os.path.join(SWC_PATH, 'non_sequential_trunk_off_1_16pt.swc') ezy.load_neuron(filename)
def setUp(self): self.filename = os.path.join(SWC_PATH, 'Neuron.swc') #self.filename2 = os.path.join(SWC_PATH, '') self.neuron = ezy.load_neuron(self.filename)
def test_construct_neuron_no_soma_raises_SomaError(): filename = os.path.join(SWC_PATH, 'Single_apical_no_soma.swc') ezy.load_neuron(filename)
def test_construct_neuron_invalid_id_sequence_raises(): filename = os.path.join(SWC_PATH, 'non_increasing_trunk_off_1_16pt.swc') ezy.load_neuron(filename)
def test_construct_neuron(): filename = os.path.join(SWC_PATH, 'Neuron.swc') ezy.load_neuron(filename)
_path = os.path.dirname(os.path.abspath(__file__)) DATA_PATH = os.path.join(_path, '../test_data') SWC_PATH = os.path.join(DATA_PATH, 'swc') def random_color(): '''Random color generation''' return np.random.rand(3, 1) def plot_somas(somas): '''Plot set of somas on same figure as spheres, each with different color''' fig, ax = common.get_figure(new_fig=True, subplot=111, params={'projection': '3d', 'aspect': 'equal'}) for s in somas: center = s.center radius = s.radius common.plot_sphere(fig, ax, center, radius, color=random_color(), alpha=1) plt.show() if __name__ == '__main__': # define set of files containing relevant neurons file_nms = [os.path.join(SWC_PATH, file_nm) for file_nm in ['Soma_origin.swc', 'Soma_translated_1.swc', 'Soma_translated_2.swc']] # load from file and plot sms = [ezy.load_neuron(file_nm).soma for file_nm in file_nms] plot_somas(sms)
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import os from os.path import join as joinp from nose import tools as nt from neurom.core.population import Population from neurom.ezy import Neuron, load_neuron _path = os.path.dirname(os.path.abspath(__file__)) DATA_PATH = joinp(_path, "../../../test_data") NRN1 = load_neuron(joinp(DATA_PATH, "swc/Neuron.swc")) NRN2 = load_neuron(joinp(DATA_PATH, "swc/Single_basal.swc")) NRN3 = load_neuron(joinp(DATA_PATH, "swc/Neuron_small_radius.swc")) NEURONS = [NRN1, NRN2, NRN3] TOT_NEURITES = sum(N.get_n_neurites() for N in NEURONS) def test_population(): pop = Population(NEURONS, name="foo") nt.assert_equal(len(pop.neurons), 3) nt.ok_(pop.neurons[0].name, "Neuron") nt.ok_(pop.neurons[1].name, "Single_basal") nt.ok_(pop.neurons[2].name, "Neuron_small_radius")
def plot_somas(somas): '''Plot set of somas on same figure as spheres, each with different color''' fig, ax = common.get_figure(new_fig=True, subplot=111, params={ 'projection': '3d', 'aspect': 'equal' }) for s in somas: center = s.center radius = s.radius common.plot_sphere(fig, ax, center, radius, color=random_color(), alpha=1) plt.show() if __name__ == '__main__': # define set of files containing relevant neurons file_nms = [ os.path.join(SWC_PATH, file_nm) for file_nm in ['Soma_origin.swc', 'Soma_translated_1.swc', 'Soma_translated_2.swc'] ] # load from file and plot sms = [ezy.load_neuron(file_nm).soma for file_nm in file_nms] plot_somas(sms)
def test_construct_neuron_non_consecutive_ids_raises_NonConsecutiveIDsError(): filename = os.path.join(SWC_PATH, 'non_sequential_trunk_off_1_16pt.swc') ezy.load_neuron(filename)
def test_is_flat(): neu_tree = load_neuron(os.path.join(SWC_PATH, 'Neuron.swc')).neurites[0] nt.assert_false(is_flat(neu_tree, 1e-6, method='tolerance')) nt.assert_false(is_flat(neu_tree, 0.1, method='ratio'))
from __future__ import print_function from itertools import imap from neurom import ezy from neurom.core.tree import isection from neurom.core.tree import ibifurcation_point from neurom.core.dataformat import COLS from neurom.analysis import morphmath as mm from neurom.analysis import morphtree as mt import numpy as np if __name__ == '__main__': filename = 'test_data/swc/Neuron.swc' # load a neuron from an SWC file nrn = ezy.load_neuron(filename) # Some examples of what can be done using iteration # instead of pre-packaged functions that return lists. # The iterations give us a lot of flexibility: we can map # any function that takes a segment or section. # Get length of all neurites in cell by iterating over sections, # and summing the section lengths print('Total neurite length:', sum(nrn.iter_sections(mm.path_distance))) # Get length of all neurites in cell by iterating over segments, # and summing the segment lengths. # This should yield the same result as iterating over sections. print('Total neurite length:', sum(nrn.iter_segments(mm.segment_length)))
centre_mass = neurite_centre_of_mass(neurite) sum_sqr_distance = 0 N = 0 for segment in tree.val_iter(tree.isegment(neurite)): sum_sqr_distance = sum_sqr_distance + distance_sqr(centre_mass, segment) N += 1 return np.sqrt(sum_sqr_distance / N) def mean_rad_of_gyration(neurites): '''Calculate mean radius of gyration for set of neurites.''' return np.mean([radius_of_gyration(n) for n in neurites]) if __name__ == '__main__': # load a neuron from an SWC file filename = 'test_data/swc/Neuron.swc' nrn = ezy.load_neuron(filename) # for every neurite, print (number of segments, radius of gyration, neurite type) print([(sum(1 for _ in tree.isegment(nrte)), radius_of_gyration(nrte), nrte.type) for nrte in nrn.neurites]) # print mean radius of gyration per neurite type print('Mean radius of gyration for axons: ', mean_rad_of_gyration(n for n in nrn.neurites if n.type == ezy.TreeType.axon)) print('Mean radius of gyration for basal dendrites: ', mean_rad_of_gyration(n for n in nrn.neurites if n.type == ezy.TreeType.basal_dendrite)) print('Mean radius of gyration for apical dendrites: ', mean_rad_of_gyration(n for n in nrn.neurites if n.type == ezy.TreeType.apical_dendrite))
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from nose import tools as nt from neurom.core.population import Population from neurom.ezy import Neuron, load_neuron from neurom.analysis.morphtree import i_section_length from neurom.analysis.morphtree import i_segment_length NRN1 = load_neuron('test_data/swc/Neuron.swc') NRN2 = load_neuron('test_data/swc/Single_basal.swc') NRN3 = load_neuron('test_data/swc/Neuron_small_radius.swc') NEURONS = [NRN1, NRN2, NRN3] TOT_NEURITES = sum(N.get_n_neurites() for N in NEURONS) def test_population(): pop = Population(NEURONS, name='foo') nt.assert_equal(len(pop.neurons), 3) nt.ok_(pop.neurons[0].name, 'Neuron') nt.ok_(pop.neurons[1].name, 'Single_basal') nt.ok_(pop.neurons[2].name, 'Neuron_small_radius') nt.assert_equal(len(pop.somata), 3)