From 06608972c7a19be09548f3a0498183ac8d9a8226 Mon Sep 17 00:00:00 2001 From: OneMore1 <129330534+OneMore1@users.noreply.github.com> Date: Tue, 12 Nov 2024 10:01:01 +0000 Subject: [PATCH] Provide a whole-brain pre-processing process --- convert.ipynb | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/convert.ipynb b/convert.ipynb index cd17475..3596418 100644 --- a/convert.ipynb +++ b/convert.ipynb @@ -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" ] @@ -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" }, @@ -85,7 +119,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.16" + "version": "3.10.12" }, "orig_nbformat": 4 },