def test_zoom(): s = AnatomicalSpace("asl", resolution=(1, 1, 1)) t = AnatomicalSpace("asl", resolution=(1, 1, 2)) m = np.array( [ [[1, 9, 15, 17, 20, 25], [1, 9, 15, 17, 20, 25]], [[2, 18, 30, 34, 40, 50], [2, 18, 30, 34, 40, 50]], ] ).astype(np.float) assert np.allclose( s.map_stack_to(t, m), np.array( [ [[1.0, 16.20454545, 25.0], [1.0, 16.20454545, 25.0]], [[2.0, 32.40909091, 50.0], [2.0, 32.40909091, 50.0]], ] ), ) assert np.allclose( s.map_stack_to(t, m, interp_order=1), np.array( [ [[1.0, 16.0, 25.0], [1.0, 16.0, 25.0]], [[2.0, 32.0, 50.0], [2.0, 32.0, 50.0]], ] ), )
def test_stack_copy(copy_flag): source_stack = np.random.rand(3, 4, 2) source_space = AnatomicalSpace("asl") pre_copy = source_stack.copy() mapped_stack = source_space.map_stack_to( "lsp", source_stack, copy=copy_flag ) mapped_stack[0, 1, 1] = 1 assert np.allclose(source_stack, pre_copy) == copy_flag
def test_stack_flips(src_o, tgt_o, src_shape, tgt_shape): source_stack = create_label_array(src_o, src_shape) target_stack = create_label_array(tgt_o, tgt_shape) source_space = AnatomicalSpace(src_o) # Test both mapping to AnatomicalSpace obj and origin with decorator: for target_space in [tgt_o, AnatomicalSpace(tgt_o)]: # Check all corners of the mapped stack: mapped_stack = source_space.map_stack_to(target_space, source_stack) for indexes in itertools.product([0, -1], repeat=3): assert set(mapped_stack[indexes]) == set(target_stack[indexes])
def test_point_transform(src_o, tgt_o, src_shape, tgt_shape): # Create an array with descriptive space labels: source_stack = create_label_array(src_o, src_shape) # Create spaces objects: source_space = AnatomicalSpace(src_o, shape=[s * 2 for s in src_shape]) # Test both mapping to AnatomicalSpace obj and origin with decorator: for target_space in [tgt_o, AnatomicalSpace(tgt_o)]: # Define grid of points sampling 4 points per axis: grid_positions = [[1, s - 1, s + 1, s * 2 - 1] for s in src_shape] source_pts = np.array(list(itertools.product(*grid_positions))) # Map points and stack to target space: mapped_pts = source_space.map_points_to(target_space, source_pts) mapped_stack = source_space.map_stack_to(target_space, source_stack) # Check that point coordinates keep the same values: for p_source, p_mapped in zip(source_pts, mapped_pts): p_s, p_m = [tuple(p.astype(np.int)) for p in [p_source, p_mapped]] assert source_stack[p_s] == mapped_stack[p_m]
def test_stack_map_offset(s_dict, t_dict, f_in, result): s = AnatomicalSpace(**s_dict) t = AnatomicalSpace(**t_dict) assert np.allclose(t.map_stack_to(s, np.ones((2, 2, 2)), **f_in), result)
) # 1. load the data print("Loading data") data = imio.load.load_any(datafile) # 2. aligned the data to the scene's atlas' axes print("Transforming data") scene = Scene(atlas_name="mpin_zfish_1um") source_space = AnatomicalSpace( "ira" ) # for more info: https://docs.brainglobe.info/bg-space/usage target_space = scene.atlas.space transformed_stack = source_space.map_stack_to(target_space, data) # 3. create a Volume vedo actor and smooth print("Creating volume") vol = Volume(transformed_stack, origin=scene.root.origin()).medianSmooth() # 4. Extract a surface mesh from the volume actor print("Extracting surface") SHIFT = [-20, 15, 30] # fine tune mesh position mesh = ( vol.isosurface(threshold=20).c(blue_grey).decimate().clean().addPos(*SHIFT) ) # 5. render print("Rendering")