Пример #1
0
def sphere_el_msh():
    fn = os.path.join(os.path.dirname(os.path.realpath(
        __file__)), '..', 'testing_files', 'sphere_w_electrodes.msh')
    return gmsh.read_msh(fn)
Пример #2
0
def cube_lr():
    fn = os.path.join(os.path.dirname(os.path.realpath(
        __file__)), '..', 'testing_files', 'cube.msh')
    return gmsh.read_msh(fn)
Пример #3
0
def sphere3_msh():
    return gmsh.read_msh(
        os.path.join(os.path.dirname(os.path.realpath(__file__)), '..',
                     'testing_files', 'sphere3.msh'))
Пример #4
0
        "-ev",
        action="store_true",
        help="If the NifTI contains a tensor, save only the maximum "
        "eigenvector in brain tissue")
    parser.add_argument('--version', action='version', version=simnibs_version)
    return parser.parse_args(argv)


if __name__ == '__main__':
    args = parseArguments(sys.argv[1:])
    if not os.path.isfile(args.fn_nifti):
        raise IOError('Could not find file: {0}'.format(args.fn_nifti))
    if not os.path.isfile(args.fn_mesh):
        raise IOError('Could not find file: {0}'.format(args.fn_mesh))
    image = nibabel.load(args.fn_nifti)
    mesh = gmsh.read_msh(args.fn_mesh)
    vol = image.dataobj
    affine = image.affine
    if args.ev:
        logger.info('Creating tensor visualization')
        mesh = mesh.crop_mesh([1, 2, 1001, 1002])
        cond_list = [c.value for c in cond.standard_cond()]
        sigma = cond.cond2elmdata(mesh,
                                  cond_list,
                                  anisotropy_volume=vol,
                                  affine=affine,
                                  aniso_tissues=[1, 2])
        views = cond.TensorVisualization(sigma)
        mesh.nodedata = []
        mesh.elmdata = views
        gmsh.write_msh(mesh, args.fn_out)
Пример #5
0
if len(sys.argv) not in [3, 5]:
    print("Incorrect number of arguments")
    usage()
    sys.exit(1)

# check extension
if os.path.splitext(sys.argv[1])[1] != '.msh':
    print('1st argument must have a .msh extension')
    sys.exit(1)

if os.path.splitext(sys.argv[2])[1] != '.msh':
    print('2nd argument must have a .msh extension')
    sys.exit(1)

m = gmsh.read_msh(sys.argv[1])

m.fn = sys.argv[2]
logger.info("Relabeled ventricle regions to CSF and cerebellum regions to WM")
m.elm.tag1[m.elm.tag1 == 6] = 1
m.elm.tag1[m.elm.tag1 == 7] = 3
m.elm.tag2[m.elm.tag2 == 6] = 1
m.elm.tag2[m.elm.tag2 == 7] = 3

logger.info("Fixing surface labeling")
m.fix_surface_labels()
logger.info("Fixing thin tetrahedra")
m.fix_thin_tetrahedra()
logger.info("Fixing tetrahedra node ordering")
m.fix_th_node_ordering()
logger.info("Fixing triangle node ordering")
Пример #6
0
            raise ValueError('.csv-file has to contain all four fiducials')
        name = [name[i] for i in p]
        coordinates = [list(coordinates[i]) for i in p]

        args.Iz = coordinates[name.index('Iz')]
        args.Nz = coordinates[name.index('Nz')]
        args.LPA = coordinates[name.index('LPA')]
        args.RPA = coordinates[name.index('RPA')]

    return args


if __name__ == '__main__':
    args = parseArguments(sys.argv)
    print "Reading Mesh"
    mesh = gmsh.read_msh(args.m)
    print "Calculating EEG Electrode Positions"
    print "Reference points:"
    print "Nz:", args.Nz
    print "Iz:", args.Iz
    print "LPA:", args.LPA
    print "RPA:", args.RPA
    surface = surface.Surface(mesh, [5, 1005])
    eeg = FindPositions(args.Nz, args.Iz, args.LPA, args.RPA, surface,
                        args.NE_cap)
    print "Printing positions to file", args.o + '.csv'
    eeg.print2csv(args.o + '.csv')
    eeg.print2geo(args.o + '.geo')
    # mesh = gmsh.read_msh('almi5-head2-fix.msh')
# surface = surface.Surface(mesh,[5,5000])
# Nz = [8,85.5,-40.5]
Пример #7
0
    parser.add_argument('--out_fill',
                        help=out_descrip,
                        type=check_out_fill,
                        default='nan')
    parser.add_argument('--method',
                        help=type_descrip,
                        default='linear',
                        choices=['linear', 'assign'])

    parser.add_argument('--version', action='version', version=simnibs_version)
    return parser.parse_args(argv)


if __name__ == '__main__':
    args = parse_arguments(sys.argv[1:])
    msh = gmsh.read_msh(
        os.path.abspath(os.path.realpath(os.path.expanduser(args.mesh))))
    fn_csv = os.path.expanduser(args.csv)
    if args.l is not None:
        labels = [int(n) for n in args.l[0].split(',')]
        msh = msh.crop_mesh(tags=labels)

    points = np.atleast_2d(np.loadtxt(fn_csv, delimiter=',', dtype=float))
    if points.shape[1] != 3:
        raise IOError('CSV file should have 3 columns')

    csv_basename, _ = os.path.splitext(fn_csv)
    for ed in msh.elmdata:
        c = ed.field_name in ['normJ', 'J']
        fn_out = '{0}_{1}.csv'.format(csv_basename, ed.field_name)
        logger.info('Interpolating field: {0} and writing to file: {1}'.format(
            ed.field_name, fn_out))