def test_multiroot(self): morphology = (MorphologyBuilder().root(0, 0, 0).axon(0, 0, 1).root( 1, 1, 1, AXON).child(2, 1, 1, AXON).build()) roots = morphology.get_roots() self.assertEqual(roots[1]["parent"], -1) self.assertEqual(morphology.nodes()[-1]["parent"], 2)
def data(): """ S > A > A > A v P > P > P v P """ morphology = ( MorphologyBuilder().root().axon().axon().axon().up(3).apical_dendrite( ).apical_dendrite().apical_dendrite().up().apical_dendrite().build()) reference_depths = { "1": ReferenceLayerDepths(0, 100), "2": ReferenceLayerDepths(100, 200), "wm": ReferenceLayerDepths(200, 300, False) } # in this example specimen, layer transitions are universally at # 50 250 350 point_depths = LayeredPointDepths( ids=np.arange(8), layer_name=["2", "2", "wm", "wm", "2", "1", "1", "1"], depth=[200, 230, 260, 290, 60, 40, 30, 20], local_layer_pia_side_depth=[50, 50, 250, 250, 50, 0, 0, 0], local_layer_wm_side_depth=[250, 250, np.nan, np.nan, 250, 50, 50, 50], point_type=[node["type"] for node in morphology.nodes()]) return morphology, reference_depths, point_depths
def setUp(self): # we are not actually going to use this - but it must be argued to the # Data constructor self.morphology = (MorphologyBuilder().root().build()) class AMark(Mark): @classmethod def validate(cls, data): return hasattr(data, "a") and data.a == 2 self.amark = AMark class BMark(Mark): @classmethod def validate(cls, data): return hasattr(data, "b") and data.b == 3 self.bmark = BMark @marked(AMark) def foo(data): return data.a == 2 self.foo = foo @marked(BMark) def baz(data): return data.b == 3 self.baz = baz
def setUp(self): # 180 deg at soma # axon - 90 deg local, 60 deg remote # basal - 90 deg local, 90 deg remote self.morphology = ( MorphologyBuilder() .root(0, 0, 0) .axon(0, 0, 1) .axon(0, 1, 2) .axon(0, 1, 1 + np.sqrt(3)).up(2) .axon(0, -1, 2) .axon(0, -1, 1 + np.sqrt(3)).up(3) .basal_dendrite(0, 0, -1) .basal_dendrite(0, 1, -2).up() .basal_dendrite(0, -1, -2) .build() ) nodes = self.morphology.nodes() for node in nodes: print(node) self.data = Data(self.morphology) self.local_specialized = specialize( bf.mean_bifurcation_angle_local, {AxonSpec, ApicalDendriteSpec, BasalDendriteSpec} ) self.remote_specialized = specialize( bf.mean_bifurcation_angle_remote, {AxonSpec, ApicalDendriteSpec, BasalDendriteSpec} )
def setUp(self): # input gradient in xarray format # up is negative x, so expected rotation is - pi / 2 dx = -np.ones((6, 6)) dy = np.zeros((6, 6)) x = np.array([-35, -20, -5, 5, 20, 35]) y = np.array([-35, -20, -5, 5, 20, 35]) grad_data = np.empty((6, 6, 2)) grad_data[:, :, 0] = dx grad_data[:, :, 1] = dy self.morphology = (MorphologyBuilder().root(1, 2, 3).axon(0, 2, 3).build()) self.gradient = xr.DataArray(grad_data, dims=['x', 'y', 'dim'], coords={ 'x': x, 'y': y, 'dim': ['dx', 'dy'] }) self.test_dir = tempfile.mkdtemp() self.gradient_path = os.path.join(self.test_dir, 'gradient.nc') self.gradient.to_netcdf(self.gradient_path) self.swc_path = os.path.join(self.test_dir, '123.swc') morphology_to_swc(self.morphology, self.swc_path) self.output_json_path = os.path.join(self.test_dir, 'output.json')
def setUp(self): """ y+ | P ^ P ^ S > A > A - x+ """ self.morphology = ( MorphologyBuilder() .root(0, 0, 0) .axon(1, 0, 0) .axon(2, 0, 0).up(2) .apical_dendrite(0, 1, 0) .apical_dendrite(0, 2, 0) .build() ) self.point = [0, 1, 0] self.vector = [[0, 0, 0], [1, 0, 0], [2, 0, 0], [0, 1, 0], [0, 2, 0]] """ [[tvr_00 tvr_01 tvr_02 tvr_09] [tvr_03 tvr_04 tvr_05 tvr_10] [tvr_06 tvr_07 tvr_08 tvr_11] [0 0 0 1]] """ rad = 60 * np.pi / 180 self.rad = rad self.array = [[np.cos(rad), -np.sin(rad), 0, 0], [np.sin(rad), np.cos(rad), 0, 10], [0, 0, 1, 0], [0, 0, 0, 1]] self.translation = [0, 10, 0] self.list = [np.cos(rad), -np.sin(rad), 0, np.sin(rad), np.cos(rad), 0, 0, 0, 1, 0, 10, 0] self.dict = {'tvr_00': np.cos(rad), 'tvr_01': -np.sin(rad), 'tvr_02': 0, 'tvr_03': np.sin(rad), 'tvr_04': np.cos(rad), 'tvr_05': 0, 'tvr_06': 0, 'tvr_07': 0, 'tvr_08': 1, 'tvr_09': 0, 'tvr_10': 10, 'tvr_11': 0, } self.transformed_vector = [[0, 10, 0], [0.5, 10 + np.sqrt(3) / 2, 0], [1, 10 + np.sqrt(3), 0], [-np.sqrt(3)/2, 10.5, 0], [-np.sqrt(3), 11, 0]]
def test_branching(self): morphology = (MorphologyBuilder().root(0, 0, 0).axon(0, 0, 1).axon( 0, 0, 2).axon(0, 0, 3).up().axon(0, 0, 4).axon(0, 0, 5).up().axon( 0, 0, 6).up(4).basal_dendrite().basal_dendrite().build()) obtained = morphology.get_branching_nodes() self.assertEqual(obtained[0]["z"], 2) self.assertEqual(obtained[1]["z"], 4) self.assertEqual(len(obtained), 2)
def setUp(self): self.morphology = (MorphologyBuilder().root(1, 2, 3, radius=1.3).axon( 0, 2, 100, radius=0.4).build()) self.max_morphology = (MorphologyBuilder().root(1, 2, 3).axon(0, 2, 353).build()) self.soma_depth = 1.0 self.cut_thickness = 350 self.test_dir = tempfile.mkdtemp() self.swc_path = os.path.join(self.test_dir, '123.swc') morphology_to_swc(self.morphology, self.swc_path) self.marker_path = os.path.join(self.test_dir, '123.marker') with open(self.marker_path, 'w') as f: f.write( "##x,y,z,radius,shape,name,comment, color_r,color_g,color_b\n" "1.0,2.0,3.5,0.0,0,30,0,255, 255, 255\n" "0.0,2.0,3.0,0.0,0,20,0,255, 255, 255") self.soma_marker_z = 3.5 self.output_json_path = os.path.join(self.test_dir, 'output.json')
def setUp(self): self.morphology = (MorphologyBuilder().root(1, 2, 3).axon(0, 2, 3).build()) self.test_dir = tempfile.mkdtemp() self.swc_path = os.path.join(self.test_dir, '123.swc') morphology_to_swc(self.morphology, self.swc_path) self.marker_path = os.path.join(self.test_dir, '123.marker') with open(self.marker_path, 'w') as f: f.write( "##x,y,z,radius,shape,name,comment, color_r,color_g,color_b\n" "1.0,2.0,2.5,0.0,0,30,0,255, 255, 255\n" "0.0,2.0,3.0,0.0,0,20,0,255, 255, 255") self.slice_transform_list = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0] self.slice_transform = AffineTransform.from_list( self.slice_transform_list) self.slice_image_flip = True self.soma_marker = {'x': 1, 'y': 2, 'z': 0} self.soma_voxel = (400, 400, 1120) self.ccf_soma_location = [ self.soma_voxel[0] * CCF_RESOLUTION, self.soma_voxel[1] * CCF_RESOLUTION, self.soma_voxel[2] * CCF_RESOLUTION ] self.csl_dict = dict(zip(['x', 'y', 'z'], self.ccf_soma_location)) # Streamline is on z+, so should result in tilt of np.pi / 2 self.closest_path = np.asarray([ 400 * np.ones((20, ), dtype='i'), 400 * np.ones((20, ), dtype='i'), np.arange(1120, 1140, dtype='i') ]) self.ccf_path = os.path.join(self.test_dir, 'paths.h5') path = np.ravel_multi_index(self.closest_path, CCF_SHAPE) with h5py.File(self.ccf_path, 'w') as f: f.create_dataset("view lookup", (1, ), dtype='i', data=0) f.create_dataset("paths", (1, 20), dtype='i', data=path) self.output_json_path = os.path.join(self.test_dir, 'output.json')
def setUp(self): # Create an axon that branches once, # and a basal dendrite that has a bifurcation and a trifurcation self.morphology = (MorphologyBuilder( ).root().axon().axon().axon().axon().up().axon().up(4).basal_dendrite( ).basal_dendrite().basal_dendrite().up().basal_dendrite( ).basal_dendrite().up().basal_dendrite().up().basal_dendrite().build()) self.data = Data(self.morphology) self.num_nodes = specialize(ic.num_nodes, NEURITE_SPECIALIZATIONS) self.num_tips = specialize(ic.num_tips, NEURITE_SPECIALIZATIONS) self.num_branches = specialize(ic.num_branches, NEURITE_SPECIALIZATIONS) self.mean_fragmentation = specialize(ic.mean_fragmentation, NEURITE_SPECIALIZATIONS) self.max_branch_order = specialize(ic.max_branch_order, NEURITE_SPECIALIZATIONS)
def setUp(self): """ y+ | P ^ P ^ S > A > A - x+ """ self.morphology = (MorphologyBuilder().root(0, 0, 0).axon( 1, 0, 0).axon(2, 0, 0).up(2).apical_dendrite(0, 1, 0).apical_dendrite(0, 2, 0).build()) self.transformed_vector = [[0, 0, 0], [0.5, np.sqrt(3) / 2, 0], [1, np.sqrt(3), 0], [-np.sqrt(3) / 2, 0.5, 0], [-np.sqrt(3), 1, 0]] self.test_dir = tempfile.mkdtemp() self.input_swc_name = 'input.swc' self.output_swc_name = 'transformed.swc' morphology_to_swc(self.morphology, os.path.join(self.test_dir, self.input_swc_name)) rad = 60 * np.pi / 180 c = np.cos(rad) s = np.sin(rad) self.input = { 'affine_list': f'[{c},{-s},0,{s},{c},0,0,0,1,0,0,0]', 'input_swc': os.path.join(self.test_dir, self.input_swc_name), 'output_swc': os.path.join(self.test_dir, self.output_swc_name), 'output_json': os.path.join(self.test_dir, 'output.json') } self.output = { 'input': self.input, 'transformed_swc': os.path.join(self.test_dir, self.output_swc_name), }
def setUp(self): self.morphology = ( MorphologyBuilder().root().axon().axon().axon().build())
def nodes(): return ( MorphologyBuilder().root().axon().axon().axon().up(3).apical_dendrite( ).apical_dendrite().apical_dendrite().up().apical_dendrite().nodes)