Exemple #1
0
    def build(nr_vertices=10, valid_for_simulation=True, cortical=False):
        if cortical:
            return CorticalSurface(
                vertices=numpy.zeros((nr_vertices, 3)),
                triangles=numpy.zeros((3, 3), dtype=int),
                vertex_normals=numpy.zeros((nr_vertices, 3)),
                triangle_normals=numpy.zeros((3, 3)),
                number_of_vertices=nr_vertices,
                number_of_triangles=3,
                edge_mean_length=1.0,
                edge_min_length=0.0,
                edge_max_length=2.0,
                zero_based_triangles=False,
                bi_hemispheric=False,
                valid_for_simulations=True
            )

        return Surface(
            vertices=numpy.zeros((nr_vertices, 3)),
            triangles=numpy.zeros((3, 3), dtype=int),
            vertex_normals=numpy.zeros((nr_vertices, 3)),
            triangle_normals=numpy.zeros((3, 3)),
            number_of_vertices=nr_vertices,
            number_of_triangles=3,
            edge_mean_length=1.0,
            edge_min_length=0.0,
            edge_max_length=2.0,
            zero_based_triangles=False,
            bi_hemispheric=False,
            surface_type=SurfaceTypesEnum.CORTICAL_SURFACE.value,
            valid_for_simulations=valid_for_simulation)
Exemple #2
0
    def sensors_to_surface(self, sensors_gid, surface_to_map_gid):
        """
        Map EEG sensors onto the head surface (skin-air).

        EEG sensor locations are typically only given on a unit sphere, that is,
        they are effectively only identified by their orientation with respect
        to a coordinate system. This method is used to map these unit vector
        sensor "locations" to a specific location on the surface of the skin.

        Assumes coordinate systems are aligned, i.e. common x,y,z and origin.

        """
        # Normalize sensor and vertex locations to unit vectors
        sensors_h5_class, sensors_h5_path = self._load_h5_of_gid(sensors_gid)
        sensors_dt = Sensors()
        with sensors_h5_class(sensors_h5_path) as sensors_h5:
            sensors_h5.load_into(sensors_dt)

        surface_h5_class, surface_h5_path = self._load_h5_of_gid(
            surface_to_map_gid)
        surface_dt = Surface()
        with surface_h5_class(surface_h5_path) as surface_h5:
            surface_h5.load_into(surface_dt)

        return sensors_dt.sensors_to_surface(surface_dt).tolist()
def test_store_load_complete_region_mapping(tmph5factory, connectivity_factory, surface_factory, region_mapping_factory):
    connectivity = connectivity_factory(2)
    surface = surface_factory(5)
    region_mapping = region_mapping_factory(surface, connectivity)

    with ConnectivityH5(tmph5factory('Connectivity_{}.h5'.format(connectivity.gid))) as conn_h5:
        conn_h5.store(connectivity)
        conn_stored = Connectivity()
        conn_h5.load_into(conn_stored)

    with SurfaceH5(tmph5factory('Surface_{}.h5'.format(surface.gid))) as surf_h5:
        surf_h5.store(surface)
        surf_stored = Surface()
        surf_h5.load_into(surf_stored)

    with RegionMappingH5(tmph5factory('RegionMapping_{}.h5'.format(region_mapping.gid))) as rm_h5:
        rm_h5.store(region_mapping)
        rm_stored = RegionMapping()
        rm_h5.load_into(rm_stored)

    # load_into will not load dependent datatypes. connectivity and surface are undefined
    with pytest.raises(TraitAttributeError):
        rm_stored.connectivity
    with pytest.raises(TraitAttributeError):
        rm_stored.surface

    rm_stored.connectivity = conn_stored
    rm_stored.surface = surf_stored
    assert rm_stored.connectivity is not None
    assert rm_stored.surface is not None
Exemple #4
0
def test_store_load_surface(tmph5factory, surface_factory):
    surface = surface_factory(5)
    surf_h5 = SurfaceH5(tmph5factory())
    surf_h5.store(surface)
    surf_h5.close()

    surf_stored = Surface()
    with pytest.raises(AttributeError):
        surf_stored.vertices
    surf_h5.load_into(surf_stored)
    assert surf_stored.vertices.shape[0] == 5
Exemple #5
0
def test_store_load_configured_surf(tmph5factory, surface_factory):
    surface = surface_factory(5)
    # surface.configure()
    assert surface.number_of_vertices == 5
    assert surface.edge_max_length == 2.0

    tmp_path = tmph5factory()
    with SurfaceH5(tmp_path) as f:
        f.store(surface)

    surf_stored = Surface()
    with SurfaceH5(tmp_path) as f:
        f.load_into(surf_stored)
        assert f.get_number_of_split_slices() == 1
        assert f.get_slice_vertex_boundaries(0) == (0, 5)
    assert surf_stored.number_of_vertices == 5
    assert surf_stored.number_of_triangles == 3
    assert surf_stored.edge_max_length == 2.0
Exemple #6
0
    def build(nr_vertices=10, valid_for_simulation=True, cortical=False):
        if cortical:
            return CorticalSurface(
                vertices=numpy.zeros((nr_vertices, 3)),
                triangles=numpy.zeros((3, 3), dtype=int),
                vertex_normals=numpy.zeros((nr_vertices, 3)),
                triangle_normals=numpy.zeros((3, 3)),
                number_of_vertices=nr_vertices,
                number_of_triangles=3,
                edge_mean_length=1.0,
                edge_min_length=0.0,
                edge_max_length=2.0,
                zero_based_triangles=False,
                split_triangles=numpy.arange(0),
                number_of_split_slices=1,
                split_slices=dict(),
                bi_hemispheric=False,
                # surface_type="surface",
                valid_for_simulations=True)

        return Surface(vertices=numpy.zeros((nr_vertices, 3)),
                       triangles=numpy.zeros((3, 3), dtype=int),
                       vertex_normals=numpy.zeros((nr_vertices, 3)),
                       triangle_normals=numpy.zeros((3, 3)),
                       number_of_vertices=nr_vertices,
                       number_of_triangles=3,
                       edge_mean_length=1.0,
                       edge_min_length=0.0,
                       edge_max_length=2.0,
                       zero_based_triangles=False,
                       split_triangles=numpy.arange(0),
                       number_of_split_slices=1,
                       split_slices=dict(),
                       bi_hemispheric=False,
                       surface_type="surface_cortical",
                       valid_for_simulations=valid_for_simulation)
    hemispheres=numpy.array([True, True, True, True]),
    orientations=numpy.zeros((2, 2)),
    areas=numpy.zeros((4, )),
    number_of_regions=2,
    number_of_connections=4,
    # parent_connectivity=""
    saved_selection=["a", "b", "C"])

surface = Surface(vertices=numpy.zeros((5, 3)),
                  triangles=numpy.zeros((3, 3), dtype=int),
                  vertex_normals=numpy.zeros((5, 3)),
                  triangle_normals=numpy.zeros((3, 3)),
                  number_of_vertices=5,
                  number_of_triangles=3,
                  edge_mean_length=1.0,
                  edge_min_length=0.0,
                  edge_max_length=2.0,
                  zero_based_triangles=False,
                  split_triangles=numpy.arange(0),
                  number_of_split_slices=1,
                  split_slices=dict(),
                  bi_hemispheric=False,
                  surface_type="surface",
                  valid_for_simulations=True)

region_mapping = RegionMapping(array_data=numpy.arange(5),
                               connectivity=connectivity,
                               surface=surface)

cortical_surface = CorticalSurface(
    vertices=numpy.zeros((5, 3)),
    triangles=numpy.zeros((3, 3), dtype=int),
Exemple #8
0
 def get_lines_slice(self, slice_number=0):
     """
     Read the gl lines values for the current slice number.
     """
     return Surface._triangles_to_lines(self.get_triangles_slice(slice_number))