예제 #1
0
def test_get_closest_vertex_to_vertex_0_coordinate():
    try:
        from scipy.spatial.distance import cdist
    except ImportError:
        pytest.skip("Optional dependency scipy not installed, skipping tests which require scipy.")
    vert_coords, faces, _ = bl.subject_mesh('subject1', TEST_DATA_DIR, surf='white', hemi='both')
    locator = loc.BrainLocate(vert_coords, faces)
    known_vertex_0_coord = (-1.85223234, -107.98274994, 22.76972961)    # coordinate for vertex 0 in the test data.
    assert_allclose(vert_coords[0], np.array(known_vertex_0_coord))
    query_coords = np.array([known_vertex_0_coord])
    res = locator.get_closest_vertex_and_distance(query_coords)
    assert res.shape == (1, 2)
    assert res[0, 0] == 0    # vertex index of closest vertex. The query coordinate is the known coordinate of vertex 0, so this must be 0.
    assert abs(res[0, 1]) <= 0.001   # distance to closest vertex. The query coordinate is the known coordinate of vertex 0, so this must be very close to 0.0
예제 #2
0
def test_vertices_to_label():
    vert_coords, faces, meta_data = bl.subject_mesh('subject1',
                                                    TEST_DATA_DIR,
                                                    surf='white',
                                                    hemi='both')
    selected_vert_indices = [0, 1, 2, 4]
    label_str = an.vertices_to_label(selected_vert_indices, vert_coords)
    expected = """#!ascii label
4
0 -1.852232 -107.982750 22.769730 0.0000000000
1 -2.139076 -108.102333 22.826056 0.0000000000
2 -3.120585 -108.130928 22.830750 0.0000000000
4 -4.798367 -108.059784 22.777563 0.0000000000"""
    assert label_str == expected
예제 #3
0
def test_closest_vertex_to_very_close_point():
    try:
        from scipy.spatial.distance import cdist
    except ImportError:
        pytest.skip("Optional dependency scipy not installed, skipping tests which require scipy.")
    vert_coords, faces, _ = bl.subject_mesh('subject1', TEST_DATA_DIR, surf='white', hemi='both')
    locator = loc.BrainLocate(vert_coords, faces)
    query_coords = np.array([[58.0 , -45.0, 75.0]])
    res = locator.get_closest_vertex(query_coords)
    assert res.shape == (1, )
    assert res[0] == 210683     # the vertex index in the mesh
    expected_vert_210683_coords = (58.005173, -44.736935,  74.418076)
    assert_allclose(vert_coords[210683], np.array(expected_vert_210683_coords))
    dist = cdist(np.array([expected_vert_210683_coords]), query_coords)
    assert dist[0][0] == pytest.approx(0.6386434810831467, 0.001)
예제 #4
0
def test_get_closest_vertex_and_distance_to_far_away_point():
    try:
        from scipy.spatial.distance import cdist
    except ImportError:
        pytest.skip("Optional dependency scipy not installed, skipping tests which require scipy.")
    vert_coords, faces, _ = bl.subject_mesh('subject1', TEST_DATA_DIR, surf='white', hemi='both')
    locator = loc.BrainLocate(vert_coords, faces)
    query_coords = np.array([[134.37332 , -57.259495, 149.267631], [134.37332 , -57.259495, 149.267631], [134.37332 , -57.259495, 149.267631]])  # just query 3 times for the same coord to see whether results and consistent
    res = locator.get_closest_vertex_and_distance(query_coords)
    assert res.shape == (3, 2)
    assert res[0,0] == 209519              # the vertex index in the mesh
    assert res[1,0] == 209519
    assert res[2,0] == 209519
    assert res[0,1] == 107.47776120258028  # the distance
    assert res[1,1] == 107.47776120258028
    assert res[2,1] == 107.47776120258028
예제 #5
0
def test_closest_vertex_to_far_away_point():
    try:
        from scipy.spatial.distance import cdist
    except ImportError:
        pytest.skip("Optional dependency scipy not installed, skipping tests which require scipy.")
    vert_coords, faces, _ = bl.subject_mesh('subject1', TEST_DATA_DIR, surf='white', hemi='both')
    locator = loc.BrainLocate(vert_coords, faces)
    query_coords = np.array([[134.37332 , -57.259495, 149.267631], [134.37332 , -57.259495, 149.267631], [58.0 , -45.0, 75.0]])
    res = locator.get_closest_vertex(query_coords)
    assert res.shape == (3, )
    assert res[0] == 209519     # the vertex index in the mesh
    assert res[1] == 209519
    assert res[2] == 210683
    assert_allclose(vert_coords[209519], np.array((58.258751, -45.213722,  74.348068)))
    dist = cdist(np.array([[58.258751, -45.213722,  74.348068]]), np.array([[134.37332 , -57.259495, 149.267631]]))
    assert dist[0][0] == pytest.approx(107.47776133, 0.001)
예제 #6
0
def test_surface_graph():
    try:
        import networkx as nx
        import brainload.surfacegraph as sg
    except ImportError:
        pytest.skip(
            "Optional dependency networkx not installed, skipping tests which require it."
        )
    vert_coords, faces, meta_data = bl.subject_mesh('subject1',
                                                    TEST_DATA_DIR,
                                                    surf='white',
                                                    hemi='lh')
    surface_graph = sg.SurfaceGraph(vert_coords, faces)
    g = surface_graph.graph
    assert len(g) == SUBJECT1_SURF_LH_WHITE_NUM_VERTICES
    assert g.number_of_nodes() == SUBJECT1_SURF_LH_WHITE_NUM_VERTICES
    # now for some neighborhood queries
    source_vertex = 100
    neighbors_dist_1 = surface_graph.get_neighbors_up_to_dist(source_vertex, 1)
    assert len(neighbors_dist_1) == 9
    neighbors_dist_2 = surface_graph.get_neighbors_up_to_dist(source_vertex, 2)
    assert len(neighbors_dist_2) == 25
    neighbors_dist_3 = surface_graph.get_neighbors_up_to_dist(source_vertex, 3)
    assert len(neighbors_dist_3) == 48