示例#1
0
def createSim(coil_center, coil_direction, dir_name, cpus=1):
    # General Infoarmation
    S = sim_struct.SESSION()
    abPath = '/home/wq/下载/simnibs_examples/ernie/'
    S.fnamehead = abPath + 'ernie.msh'  # head mesh
    S.pathfem = dir_name  # Directory for the simulation
    # 定义线圈类型
    tms = S.add_tmslist()
    tms.fnamecoil = 'Magstim_70mm_Fig8.nii.gz'  # Choose a coil from the ccd-files folder

    # 定义线圈位置
    pos = tms.add_position()
    # Place coil over the hand knob
    # Here, the hand knob is defined in MNI coordinates (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2034289/)
    # And transformed to subject coordinates
    # We can use positions in the cortex. SimNIBS will automatically project them to the skin surface
    # and add the specified distance
    pos.centre = simnibs.mni2subject_coords(coil_center, abPath + 'm2m_ernie')
    # Point the coil handle posteriorly, we just add 10 mm to the original M1 y coordinate
    pos.pos_ydir = simnibs.mni2subject_coords(coil_direction, abPath + 'm2m_ernie')
    pos.distance = 4  # 4 mm distance from coil surface to head surface

    # Run Simulation
    out = S.run(cpus, False, True)
    re = simnibs.read_msh(S.pathfem + '/ernie_TMS_1-0001_Magstim_70mm_Fig8_nii_scalar.msh')
    return re
示例#2
0
from simnibs import opt_struct, mni2subject_coords

# Initialize structure
tms_opt = opt_struct.TMSoptimize()
# Select the head mesh
tms_opt.fnamehead = 'ernie.msh'
# Select output folder
tms_opt.pathfem = 'tms_optimization/'
# Select the coil model
# The ADM method requires a '.ccd' coil model
tms_opt.fnamecoil = 'Magstim_70mm_Fig8.ccd'
# Select a target for the optimization
tms_opt.target = mni2subject_coords([-37, -21, 58], 'm2m_ernie')
# Use the ADM method
tms_opt.method = 'ADM'
# Run optimization
tms_opt.run()
示例#3
0
import simnibs

## Load simulation result

# Read the simulation result
head_mesh = simnibs.read_msh(os.path.join('tdcs', 'ernie_TDCS_1_scalar.msh'))

# Crop the mesh so we only have gray matter volume elements (tag 2 in the mesh)
gray_matter = head_mesh.crop_mesh(2)

## Define the ROI

# Define M1 from MNI coordinates (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2034289/)
# the first argument is the MNI coordinates
# the second argument is the subject "m2m" folder
ernie_coords = simnibs.mni2subject_coords([-37, -21, 58], 'm2m_ernie')
# we will use a sphere of radius 10 mm
r = 10.

# Electric fields are defined in the center of the elements
# get element centers
elm_centers = gray_matter.elements_baricenters()[:]
# determine the elements in the ROI
roi = np.linalg.norm(elm_centers - ernie_coords, axis=1) < r
# get the element volumes, we will use those for averaging
elm_vols = gray_matter.elements_volumes_and_areas()[:]

## Plot the ROI
gray_matter.add_element_field(roi, 'roi')
gray_matter.view(visible_fields='roi').show()
示例#4
0
'''
Transform coordinates from MNI space to subject space and back

Please run with the command

simnibs_python transform_coordinates.py

from the "ernie" directory of the example dataset
visit www.simnibs.org for more information
'''

import simnibs


# MNI position for M1 (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2034289/)
mni_M1 = [-37, -21, 58]

# Calculate the M1 position in the "ernie" model
# we need to provide the path to the segmentation output folder
ernie_M1 = simnibs.mni2subject_coords(mni_M1, 'm2m_ernie/')
print('Ernie M1 corrdinates:', ernie_M1)
# You can open the ernie_T1fs_conform.nii.gz and check if the coordinates match

# You can also do the inverse transformation (from subject to MNI)
mni_M1 = simnibs.subject2mni_coords(ernie_M1, 'm2m_ernie/')
print('Transforming coordinates back to MNI space:', mni_M1)
# Because SimNIBS uses non-linear transformations, you will not recover the
# original coordinates exactly
示例#5
0
''' Example of an optimization punishing more the field in the eyes

    Copyright (C) 2019 Guilherme B Saturnino
'''
import simnibs

opt = simnibs.opt_struct.TDCSoptimize()
opt.leadfield_hdf = 'leadfield/ernie_leadfield_EEG10-10_UI_Jurak_2007.hdf5'
opt.name = 'optimization/avoid'

opt.max_total_current = 2e-3
opt.max_individual_current = 1e-3
opt.max_active_electrodes = 8

target = opt.add_target()
target.positions = simnibs.mni2subject_coords([-37, -21, 58], 'm2m_ernie')
target.intensity = 0.2

avoid = opt.add_avoid()
avoid.tissues = 1006  # 1006 corresponds to the eye surface

# Run optimization
simnibs.run_simnibs(opt)
示例#6
0
import simnibs
from simnibs import sim_struct

### General Infoarmation
S = sim_struct.SESSION()
S.fnamehead = 'ernie.msh'  # head mesh
S.pathfem = 'tms_hand'  # Directory for the simulation

## Define the TMS simulation
tms = S.add_tmslist()
tms.fnamecoil = 'Magstim_70mm_Fig8.nii.gz'  # Choose a coil from the ccd-files folder

# Define the coil position
pos = tms.add_position()
# Place coil over the hand knob
# Here, the hand knob is defined in MNI coordinates (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2034289/)
# And transformed to subject coordinates
# We can use positions in the cortex. SimNIBS will automatically project them to the skin surface
# and add the specified distance
pos.centre = simnibs.mni2subject_coords([-37, -21, 58], 'm2m_ernie')
# Point the coil handle posteriorly, we just add 10 mm to the original M1 y coordinate
pos.pos_ydir = simnibs.mni2subject_coords([-37, -21 - 10, 58], 'm2m_ernie')
pos.distance = 4  #  4 mm distance from coil surface to head surface

# Run Simulation
simnibs.run_simnibs(S)