Пример #1
0
def add_electrodes(mesh_filename):
    fwd_dir = os.environ['FWD_DIR']

    electrode_location_file = op.join(fwd_dir, 'etc', 'ElectrodeLocations_TMS007.txt')
    electrode_name_file = op.join(fwd_dir, 'etc', 'ElectrodeNames_BESA256.txt')

    points = np.loadtxt(electrode_location_file, delimiter=',')
    electrode_names = np.loadtxt(electrode_name_file, dtype='str')

    write_electrode_labels(points, electrode_names, out_file="BESA256.geo")
    mesh_id = 1005

    out_file = rewrite_mesh_with_electrodes(electrode_location_file, electrode_name_file, mesh_filename, mesh_id)
    return out_file
Пример #2
0
def add_electrodes(mesh_filename):
    fwd_dir = os.environ['FWD_DIR']

    electrode_location_file = op.join(fwd_dir, 'etc',
                                      'ElectrodeLocations_TMS007.txt')
    electrode_name_file = op.join(fwd_dir, 'etc', 'ElectrodeNames_BESA256.txt')

    points = np.loadtxt(electrode_location_file, delimiter=',')
    electrode_names = np.loadtxt(electrode_name_file, dtype='str')

    write_electrode_labels(points, electrode_names, out_file="BESA256.geo")
    mesh_id = 1005

    out_file = rewrite_mesh_with_electrodes(electrode_location_file,
                                            electrode_name_file, mesh_filename,
                                            mesh_id)
    return out_file
Пример #3
0
def add_sensors(electrode_location_file, mesh_file, radii):
    points = np.loadtxt(electrode_location_file, delimiter=",")
    points = np.max(radii) * points
    new_electrode_location_file = op.abspath("electrode_locations.txt")
    np.savetxt(new_electrode_location_file, points, delimiter=",")
    elec_name_file = op.abspath(
        op.basename(electrode_location_file) + "_names.txt")
    f = open(elec_name_file, "w")
    for idx in range(0, len(points)):
        name = "vertex%03d" % (idx + 1)
        f.write("%s\n" % name)
    f.close()

    print('Rewriting mesh with sensors')
    print(new_electrode_location_file, elec_name_file, mesh_file)
    out_file = rewrite_mesh_with_electrodes(
        new_electrode_location_file,
        electrode_name_file=elec_name_file,
        mesh_file=mesh_file,
        mesh_id=1004)
    return op.abspath(out_file), elec_name_file, new_electrode_location_file
Пример #4
0
electrode_position_file = op.join(data_path, subject_id,
                                  "ElectrodePositions.txt")
electrode_name_file = op.join(data_path, subject_id, "ElectrodeNames.txt")

# If you want to use the structural mesh, rather than the mesh including the conductivity
# tensors, you should uncomment the following line, and comment the one below it.
#mesh_path = op.abspath("structural_datasink/subject/volume_mesh/")
mesh_path = op.abspath("diffusion_datasink/subject/mesh_file/")

assert (op.exists(mesh_path))
search_string = "/*%s/%s*.msh" % (subject_id, subject_id)
try:
    mesh_file = glob.glob(mesh_path + search_string)[0]
except IndexError:
    raise IOError("Mesh file not found. You must run step1 and/or step2 \
        before trying to add electrodes to the mesh.")
'''
We use the element ID for the scalp volume in the Gmsh mesh
'''
mesh_id = 1005

import time
start = time.time()

out_file = rewrite_mesh_with_electrodes(electrode_position_file,
                                        electrode_name_file, mesh_file,
                                        mesh_id)
end = time.time()
print(start)
print(end)
print(end - start)
electrode_position_file = op.join(data_path, subject_id, "ElectrodePositions.txt")
electrode_name_file = op.join(data_path, subject_id, "ElectrodeNames.txt")

# If you want to use the structural mesh, rather than the mesh including the conductivity
# tensors, you should uncomment the following line, and comment the one below it.
#mesh_path = op.abspath("structural_datasink/subject/volume_mesh/")
mesh_path = op.abspath("diffusion_datasink/subject/mesh_file/")

assert(op.exists(mesh_path))
search_string = "/*%s/%s*.msh" % (subject_id, subject_id)
try:
    mesh_file = glob.glob(mesh_path + search_string)[0]
except IndexError:
    raise IOError("Mesh file not found. You must run step1 and/or step2 \
        before trying to add electrodes to the mesh.")

'''
We use the element ID for the scalp volume in the Gmsh mesh
'''
mesh_id = 1005

import time
start = time.time()

out_file = rewrite_mesh_with_electrodes(electrode_position_file, electrode_name_file,
    mesh_file, mesh_id)
end = time.time()
print(start)
print(end)
print(end-start)