{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Scaling and Transforming Head Models" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2026-05-05T15:39:36.004921Z", "iopub.status.busy": "2026-05-05T15:39:36.004741Z", "iopub.status.idle": "2026-05-05T15:39:36.012345Z", "shell.execute_reply": "2026-05-05T15:39:36.011691Z" } }, "outputs": [], "source": [ "# This cells setups the environment when executed in Google Colab.\n", "try:\n", " import google.colab\n", " !curl -s https://raw.githubusercontent.com/ibs-lab/cedalion/dev/scripts/colab_setup.py -o colab_setup.py\n", " # Select branch with --branch \"branch name\" (default is \"dev\")\n", " %run colab_setup.py\n", "except ImportError:\n", " pass" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2026-05-05T15:39:36.014218Z", "iopub.status.busy": "2026-05-05T15:39:36.014040Z", "iopub.status.idle": "2026-05-05T15:39:38.654575Z", "shell.execute_reply": "2026-05-05T15:39:38.653838Z" } }, "outputs": [], "source": [ "import pyvista as pv\n", "\n", "#pv.set_jupyter_backend('server')\n", "pv.set_jupyter_backend('static')\n", "\n", "import os\n", "\n", "import xarray as xr\n", "\n", "import cedalion\n", "import cedalion.data\n", "import cedalion.dataclasses as cdc\n", "import cedalion.dot\n", "import cedalion.io\n", "import cedalion.vis.anatomy\n", "import cedalion.vis.blocks as vbx\n", "from cedalion import units\n", "import numpy as np\n", "\n", "xr.set_options(display_expand_data=False);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Loading the ICBM-152 head model\n", "\n", "- the `TwoSurfaceHeadModel` holds the segmented MRT image and derived cortex and scalp surfaces\n", "- we provide functionality to derive these surfaces from the masks or to load them from files" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2026-05-05T15:39:38.657197Z", "iopub.status.busy": "2026-05-05T15:39:38.656773Z", "iopub.status.idle": "2026-05-05T15:39:46.511031Z", "shell.execute_reply": "2026-05-05T15:39:46.510314Z" } }, "outputs": [ { "data": { "text/plain": [ "TwoSurfaceHeadModel(\n", " crs: ijk\n", " tissue_types: csf, gm, scalp, skull, wm\n", " brain faces: 49992 vertices: 25000 units: dimensionless\n", " scalp faces: 20040 vertices: 10018 units: dimensionless\n", " landmarks: 73\n", ")" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "head_ijk = cedalion.dot.get_standard_headmodel(\"icbm152\")\n", "head_ijk" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The head model holds segmentation masks for different tissue types:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2026-05-05T15:39:46.551510Z", "iopub.status.busy": "2026-05-05T15:39:46.551305Z", "iopub.status.idle": "2026-05-05T15:39:46.582398Z", "shell.execute_reply": "2026-05-05T15:39:46.581695Z" } }, "outputs": [ { "data": { "text/html": [ "
<xarray.DataArray (segmentation_type: 5, i: 193, j: 239, k: 263)> Size: 61MB\n",
"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"Coordinates:\n",
" * segmentation_type (segmentation_type) <U5 100B 'csf' 'gm' ... 'skull' 'wm'\n",
"Dimensions without coordinates: i, j, k<xarray.DataArray (label: 73, ijk: 3)> Size: 2kB\n",
"[] 96.0 216.0 105.0 96.0 18.0 118.0 ... 133.1 28.43 182.6 145.1 30.85 166.9\n",
"Coordinates:\n",
" * label (label) <U3 876B 'Nz' 'Iz' 'LPA' 'RPA' ... 'PO1' 'PO2' 'PO4' 'PO6'\n",
" type (label) object 584B PointType.LANDMARK ... PointType.LANDMARK\n",
"Dimensions without coordinates: ijk"
],
"text/plain": [
"<xarray.DataArray (mni: 4, ijk: 4)> Size: 128B\n",
"[mm] 1.0 0.0 0.0 -96.0 0.0 1.0 0.0 -132.0 0.0 0.0 1.0 -148.0 0.0 0.0 0.0 1.0\n",
"Dimensions without coordinates: mni, ijk"
],
"text/plain": [
"<xarray.DataArray (label: 346, digitized: 3)> Size: 8kB\n",
"[mm] -77.82 15.68 23.17 -61.91 21.23 56.49 ... 14.23 -38.28 81.95 -0.678 -37.03\n",
"Coordinates:\n",
" type (label) object 3kB PointType.SOURCE ... PointType.LANDMARK\n",
" * label (label) <U6 8kB 'S1' 'S2' 'S3' 'S4' ... 'FFT10h' 'FT10h' 'FTT10h'\n",
"Dimensions without coordinates: digitized| [1] | Fonov2011 | cedalion.data.get_icbm152_headmodel_files | Vladimir Fonov, Alan C. Evans, Kelly Botteron, C. Robert Almli, Robert C. McKinstry, and D. Louis Collins.\n", "Unbiased average age-appropriate atlases for pediatric studies.\n", "NeuroImage, 54(1):313–327, January 2011.\n", "doi:10.1016/j.neuroimage.2010.07.033. |
| [2] | Fischl2012 | cedalion.data.get_icbm152_headmodel_files | Bruce Fischl.\n", "FreeSurfer.\n", "NeuroImage, 62(2):774–781, 2012.\n", "doi:10.1016/j.neuroimage.2012.01.021. |
| [3] | Schaefer2018 | cedalion.data.get_icbm152_headmodel_files | Alexander Schaefer, Ru Kong, Evan M Gordon, Timothy O Laumann, Xi-Nian Zuo, Avram J Holmes, Simon B Eickhoff, and BT Thomas Yeo.\n", "Local-global parcellation of the human cerebral cortex from intrinsic functional connectivity mri.\n", "Cerebral cortex, 28(9):3095–3114, 2018.\n", "doi:10.1093/cercor/bhx179. |
| [4] | Tucker2022 | cedalion.io.snirf.read_snirf | Stephen Tucker, Jay Dubb, Sreekanth Kura, Alexander von Lühmann, Robert Franke, Jörn M. Horschig, Samuel Powell, Robert Oostenveld, Michael Lührs, Édouard Delaire, Zahra M. Aghajan, Hanseok Yun, Meryem A. Yücel, Qianqian Fang, Theodore J. Huppert, Blaise deB. Frederick, Luca Pollonini, David A. Boas, and Robert Luke.\n", "Introduction to the shared near infrared spectroscopy format.\n", "Neurophotonics, 10(1):013507, 2022.\n", "doi:10.1117/1.NPh.10.1.013507. |