Skip to content

Commit

Permalink
Provide a whole-brain pre-processing process
Browse files Browse the repository at this point in the history
  • Loading branch information
OneMore1 authored Nov 12, 2024
1 parent a438748 commit 0660897
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions convert.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"# 1. only GM, use default lfm code from https://simnibs.github.io/simnibs/build/html/documentation/sim_struct/tdcsleadfield.html#tdcsleadfield\n",
"f = h5py.File('hcp4_leadfield_EEG10-10_UI_Jurak_2007.hdf5','r') \n",
"\n"
]
Expand Down Expand Up @@ -66,12 +66,46 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"# 2. for GM and WM\n",
"# modify the lfm code.\n",
"import simnibs\n",
"from simnibs import sim_struct\n",
"tdcs_lf = sim_struct.TDCSLEADFIELD()\n",
"tdcs_lf.fnamehead = #[your path to msh]\n",
"tdcs_lf.subpath = #[your path to m2m folder]\n",
"tdcs_lf.pathfem = #[output path]\n",
"tdcs_lf.interpolation = None\n",
"tdcs_lf.map_to_surf = False\n",
"tdcs_lf.tissues = [1,2]\n",
"simnibs.run_simnibs(tdcs_lf)\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#generate lfm and pos matrix\n",
"f = h5py.File([your path to hdf5])\n",
"\n",
"pos = f['mesh_leadfield']['nodes']['node_coord']\n",
"lfm = f['mesh_leadfield']['leadfields']['tdcs_leadfield']\n",
"index = f['mesh_leadfield']['elm']['node_number_list']\n",
"newpos = np.zeros([lfm.shape[1],3])\n",
"for i in range(newpos.shape[0]): # The midpoint of the tetrahedron\n",
" newpos[i]=(pos[index[i,0]-1]+pos[index[i,1]-1]+pos[index[i,2]-1]+pos[index[i,3]-1])/4\n",
"np.save('lfm_hcp4.npy',lfm)\n",
"np.save('pos_hcp4.npy',newpos)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "simnibs",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -85,7 +119,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.16"
"version": "3.10.12"
},
"orig_nbformat": 4
},
Expand Down

0 comments on commit 0660897

Please sign in to comment.