From cb6103a7c13445b005163070bc8ffa0211e9dde7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Hendrik=20M=C3=BCller?= <44469195+kolibril13@users.noreply.github.com> Date: Wed, 7 Aug 2024 22:04:05 +0200 Subject: [PATCH 1/2] add notebooks --- examples/01_download_all_data.ipynb | 228 ++++++++++++++++++ examples/additive_voxels.ipynb | 92 +++---- examples/basic_multiplanar.ipynb | 73 +++--- examples/mesh_and_volume.ipynb | 62 +++++ examples/mesh_layers.ipynb | 70 ++---- ...eeSurfer, MZ3, OBJ, STL, legacy VTK).ipynb | 57 +++++ examples/trajectory.ipynb | 46 ++++ 7 files changed, 494 insertions(+), 134 deletions(-) create mode 100644 examples/01_download_all_data.ipynb create mode 100644 examples/mesh_and_volume.ipynb create mode 100644 examples/meshes_(GIfTI, FreeSurfer, MZ3, OBJ, STL, legacy VTK).ipynb create mode 100644 examples/trajectory.ipynb diff --git a/examples/01_download_all_data.ipynb b/examples/01_download_all_data.ipynb new file mode 100644 index 0000000..cf24b64 --- /dev/null +++ b/examples/01_download_all_data.ipynb @@ -0,0 +1,228 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Fetching contents from https://api.github.com/repos/niivue/niivue/contents/demos/images?ref=main...\n", + "Downloading AIL.nii.gz...\n", + "Downloading BrainMesh_ICBM152.lh.curv...\n", + "Downloading BrainMesh_ICBM152.lh.motor.mz3...\n", + "Downloading BrainMesh_ICBM152.lh.mz3...\n", + "Downloading CIT168.mz3...\n", + "Downloading ColumnMajorOrder.gii...\n", + "Downloading Conte69.L.inflated.32k_fs_LR.surf.gii...\n", + "Downloading Conte69.MyelinAndCorrThickness.32k_fs_LR.dtseries.nii...\n", + "Downloading Conte69.R.inflated.32k_fs_LR.surf.gii...\n", + "Downloading DoG.png...\n", + "Downloading FA.nii.gz...\n", + "Downloading FLAIR.nii.gz...\n", + "Downloading FLAIR.nrrd...\n", + "Downloading FreeSurferControlPoints.json...\n", + "Downloading Human.colin.Cerebral.R.VERY_INFLATED.71723.surf.gii...\n", + "Downloading Human.colin.R.FUNCTIONAL.71723.func.gii...\n", + "Downloading MNI152_2009_template.nii.gz...\n", + "Downloading MolView-sticks-color_38.x3d...\n", + "Downloading TR_S_R.tt.gz...\n", + "Downloading V1.nii.gz...\n", + "Downloading aal.json...\n", + "Downloading aal.mz3...\n", + "Downloading aal.nii.gz...\n", + "Entering directory afni...\n", + "Fetching contents from https://api.github.com/repos/niivue/niivue/contents/demos/images/afni?ref=main...\n", + "Downloading DT_FA+orig.BRIK.gz...\n", + "Downloading DT_FA+orig.HEAD...\n", + "Downloading DT_V1+orig.BRIK.gz...\n", + "Downloading DT_V1+orig.HEAD...\n", + "Downloading anat_final.FT+tlrc.BRIK...\n", + "Downloading anat_final.FT+tlrc.HEAD...\n", + "Downloading avg152T1_RL_nifti.nii.gz...\n", + "Downloading boggle.lh.annot...\n", + "Downloading cactus.nii.gz...\n", + "Downloading colby.trk...\n", + "Downloading colby.trx...\n", + "Downloading complex.nii.gz...\n", + "Downloading connectome.jcon...\n", + "Downloading connectome2.jcon...\n", + "Downloading cope1.nii.gz...\n", + "Downloading ct_perfusion.nii.gz...\n", + "Downloading dpsv.trx...\n", + "Downloading draw.nii.gz...\n", + "Downloading dsistudio.fib.gz...\n", + "Downloading dsistudio.src.gz...\n", + "Downloading enh.dcm...\n", + "Downloading example4d+orig.BRIK.gz...\n", + "Downloading example4d+orig.HEAD...\n", + "Entering directory fs...\n", + "Fetching contents from https://api.github.com/repos/niivue/niivue/contents/demos/images/fs?ref=main...\n", + "Downloading brainmask.mgz...\n", + "Downloading lh.pial...\n", + "Downloading lh.white...\n", + "Downloading rh.pial...\n", + "Downloading rh.white...\n", + "Downloading wm.mgz...\n", + "Downloading fs_LR.32k.L.inflated.surf.gii...\n", + "Downloading fs_LR.32k.LR.curvature.dscalar.nii...\n", + "Downloading fslmean.nii.gz...\n", + "Downloading fslt.nii.gz...\n", + "Downloading hippo.nii.gz...\n", + "Downloading hippolr.nii.gz...\n", + "Downloading inia19-NeuroMaps.json...\n", + "Downloading inia19-NeuroMaps.nii.gz...\n", + "Downloading inia19-t1-brain.nii.gz...\n", + "Downloading labels256.nii.gz...\n", + "Downloading lesion.nii.gz...\n", + "Downloading lh.Yeo2011.gii...\n", + "Downloading lh.Yeo2011.mgz...\n", + "Downloading lh.curv...\n", + "Downloading lh.pial...\n", + "Downloading low_res.nii.gz...\n", + "Downloading mean_func.nii.gz...\n", + "Downloading minimal.nii.gz...\n", + "Downloading mni152.SLF1_R.tsf...\n", + "Downloading mni152.nii.gz...\n", + "Downloading mni152_pveseg.nii.gz...\n", + "Downloading mni_format.obj.gz...\n", + "Downloading motor_4t95mesh.rh.mz3...\n", + "Entering directory mz3...\n", + "Fetching contents from https://api.github.com/repos/niivue/niivue/contents/demos/images/mz3?ref=main...\n", + "Downloading 11ScalarMesh.mz3...\n", + "Downloading 16DoubleOverlay_5124x2.mz3...\n", + "Downloading 3Mesh.mz3...\n", + "Downloading README.md...\n", + "Downloading cortex_5124.mz3...\n", + "Downloading narps-4735_50GV-hypo1_unthresh.nii.gz...\n", + "Downloading narps-4965_9U7M-hypo1_unthresh.nii.gz...\n", + "Downloading niivue-drawing.nvd...\n", + "Downloading niivue-with-clip-plane.nvd...\n", + "Downloading niivue.basic.nvd...\n", + "Downloading niivue.drawing.nvd...\n", + "Downloading niivue.mesh.nvd...\n", + "Downloading niivue1-no-hippo.nvd...\n", + "Downloading niivue1.nvd...\n", + "Downloading otsu.nii.gz...\n", + "Downloading pcasl.nii.gz...\n", + "Downloading pcasl.png...\n", + "Downloading pval.LH.nii.gz...\n", + "Downloading scaled+tlrc.BRIK.gz...\n", + "Downloading scaled+tlrc.HEAD...\n", + "Downloading shear.nii.gz...\n", + "Downloading simplify_brain.obj...\n", + "Downloading spmMotor.nii.gz...\n", + "Downloading stats.FT+tlrc.BRIK...\n", + "Downloading stats.FT+tlrc.HEAD...\n", + "Downloading stats.nv_demo_mskd.nii.gz...\n", + "Downloading sub-01_ses-01_dwi_desc-b0_dwi.nii.gz...\n", + "Downloading sub-01_ses-01_dwi_space-RASMM_model-probCSD_algo-AFQ_tractography.trx...\n", + "Downloading sub-test02_left_hemisphere.srf.gz...\n", + "Downloading sub-test02_left_hemisphere_4_curvature_maps.smp.gz...\n", + "Downloading template.mif.gz...\n", + "Downloading torso.nii.gz...\n", + "Downloading torsoLabel.nii.gz...\n", + "Downloading tract.FAT_R.vtk...\n", + "Downloading tract.IFOF_R.trk...\n", + "Downloading tract.SLF1_R.tck...\n", + "Entering directory trix...\n", + "Fetching contents from https://api.github.com/repos/niivue/niivue/contents/demos/images/trix?ref=main...\n", + "Downloading fa.mif...\n", + "Downloading mask_1bit.mif...\n", + "Downloading tensors.mif...\n", + "Downloading v1.mif...\n", + "Downloading tstat1.nii.gz...\n", + "Downloading vr_base_min_outlier+orig.BRIK...\n", + "Downloading vr_base_min_outlier+orig.HEAD...\n", + "Downloading wm.mgz...\n", + "Downloading xd.mz3...\n", + "Downloading yd.mz3...\n", + "Downloading yeh2022.trx...\n", + "Downloading zd.mz3...\n", + "All files and subdirectories have been downloaded to images.\n" + ] + } + ], + "source": [ + "# Import necessary libraries\n", + "import os\n", + "import requests\n", + "import json\n", + "\n", + "# GitHub API URL for the base folder\n", + "BASE_API_URL = \"https://api.github.com/repos/niivue/niivue/contents\"\n", + "FOLDER_PATH = \"demos/images\"\n", + "REF = \"main\"\n", + "\n", + "# Folder where files will be saved\n", + "DEST_FOLDER = \"images\"\n", + "\n", + "# Function to fetch and download files recursively\n", + "def fetch_and_download(api_url, dest_folder):\n", + " print(f\"Fetching contents from {api_url}...\")\n", + " os.makedirs(dest_folder, exist_ok=True)\n", + " response = requests.get(api_url)\n", + " if response.status_code != 200:\n", + " print(f\"Failed to fetch {api_url}: {response.status_code}\")\n", + " return\n", + " \n", + " file_list = response.json()\n", + " for item in file_list:\n", + " item_type = item['type']\n", + " download_url = item.get('download_url', '') if item_type == 'file' else ''\n", + " name = item['name']\n", + " path = item['path']\n", + " html_url = item['html_url']\n", + "\n", + " if item_type == 'file':\n", + " print(f\"Downloading {name}...\")\n", + " file_response = requests.get(download_url)\n", + " if file_response.status_code == 200:\n", + " with open(os.path.join(dest_folder, name), 'wb') as f:\n", + " f.write(file_response.content)\n", + " else:\n", + " print(f\"Failed to download {name}: {file_response.status_code}\")\n", + " elif item_type == 'dir':\n", + " print(f\"Entering directory {name}...\")\n", + " subfolder = os.path.join(dest_folder, name)\n", + " sub_api_url = f\"{BASE_API_URL}/{path}?ref={REF}\"\n", + " fetch_and_download(sub_api_url, subfolder)\n", + "\n", + "# Start the recursive downloading\n", + "fetch_and_download(f\"{BASE_API_URL}/{FOLDER_PATH}?ref={REF}\", DEST_FOLDER)\n", + "\n", + "print(f\"All files and subdirectories have been downloaded to {DEST_FOLDER}.\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/examples/additive_voxels.ipynb b/examples/additive_voxels.ipynb index a12d0c8..62df99a 100644 --- a/examples/additive_voxels.ipynb +++ b/examples/additive_voxels.ipynb @@ -2,35 +2,39 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], - "source": [ - "!mkdir -p ../images/\n", - "!wget https://github.com/niivue/niivue/raw/main/demos/images/narps-4735_50GV-hypo1_unthresh.nii.gz -P ../images/\n", - "!wget https://github.com/niivue/niivue/raw/main/demos/images/narps-4965_9U7M-hypo1_unthresh.nii.gz -P ../images/\n", - "!wget https://github.com/niivue/niivue/raw/main/demos/images/mni152.nii.gz -P ../images/" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "8e77b0fab1204e5191dbca06414c09a4", + "version_major": 2, + "version_minor": 1 + }, + "text/plain": [ + "NiiVue(height=300)" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "from ipyniivue import NiiVue, SliceType\n", "# based on https://niivue.github.io/niivue/features/additive.voxels.html\n", "\n", "volumes = [\n", - " { \"path\": \"../images/mni152.nii.gz\" },\n", + " { \"path\": \"images/mni152.nii.gz\" },\n", " {\n", - " \"path\": \"../images/narps-4965_9U7M-hypo1_unthresh.nii.gz\",\n", + " \"path\": \"images/narps-4965_9U7M-hypo1_unthresh.nii.gz\",\n", " \"colormap\": \"red\",\n", " \"cal_min\": 2,\n", " \"cal_max\": 4,\n", " },\n", " {\n", - " \"path\": \"../images/narps-4735_50GV-hypo1_unthresh.nii.gz\",\n", + " \"path\": \"images/narps-4735_50GV-hypo1_unthresh.nii.gz\",\n", " \"colormap\": \"green\",\n", " \"cal_min\": 2,\n", " \"cal_max\": 4,\n", @@ -47,9 +51,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "cb5b42ba9d774dd69a613e644326eb2f", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(FloatSlider(value=0.2, max=0.4, min=0.1, step=0.01), FloatSlider(value=0.2, max=0.4, min=0.1, s…" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import ipywidgets\n", "\n", @@ -60,34 +80,16 @@ "ipywidgets.link((sgreen, \"value\"), (nv.volumes[2], \"cal_min\"))\n", "ipywidgets.HBox([sred, sgreen])" ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.9" - }, - "widgets": { - "application/vnd.jupyter.widget-state+json": { - "state": {}, - "version_major": 2, - "version_minor": 0 - } + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } - }, + ], + "metadata": {}, "nbformat": 4, "nbformat_minor": 4 } diff --git a/examples/basic_multiplanar.ipynb b/examples/basic_multiplanar.ipynb index 5408122..acf8a4d 100644 --- a/examples/basic_multiplanar.ipynb +++ b/examples/basic_multiplanar.ipynb @@ -2,27 +2,32 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], - "source": [ - "!mkdir -p ../images/\n", - "!wget https://github.com/niivue/niivue/raw/main/demos/images/mni152.nii.gz -P ../images/\n", - "!wget https://github.com/niivue/niivue/raw/main/demos/images/hippo.nii.gz -P ../images/" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "2f34ccf232f34ed784a01d32e5ae570a", + "version_major": 2, + "version_minor": 1 + }, + "text/plain": [ + "NiiVue(height=300)" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "from ipyniivue import NiiVue, SliceType\n", "# based on https://niivue.github.io/niivue/features/basic.multiplanar.html\n", "\n", "volumes = [\n", - " { \"path\": \"../images/mni152.nii.gz\", \"colormap\": \"gray\", \"visible\": True, \"opacity\": 1.0 },\n", - " { \"path\": \"../images/hippo.nii.gz\", \"colormap\": \"red\", \"visible\": True, \"opacity\": 1 },\n", + " { \"path\": \"images/mni152.nii.gz\", \"colormap\": \"gray\", \"visible\": True, \"opacity\": 1.0 },\n", + " { \"path\": \"images/hippo.nii.gz\", \"colormap\": \"red\", \"visible\": True, \"opacity\": 1 },\n", "\n", "]\n", "nv = NiiVue(slice_type=SliceType.MULTIPLANAR)\n", @@ -32,7 +37,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -42,7 +47,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -53,34 +58,16 @@ "nv.is_colorbar = True\n", "nv.view_mode_hot_key = \"KeyN\"" ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.12.3" - }, - "widgets": { - "application/vnd.jupyter.widget-state+json": { - "state": {}, - "version_major": 2, - "version_minor": 0 - } + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } - }, + ], + "metadata": {}, "nbformat": 4, "nbformat_minor": 4 } diff --git a/examples/mesh_and_volume.ipynb b/examples/mesh_and_volume.ipynb new file mode 100644 index 0000000..5ffb515 --- /dev/null +++ b/examples/mesh_and_volume.ipynb @@ -0,0 +1,62 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "id": "71c2f1ec-fdbf-4aae-8d09-77fd5988e11c", + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "b19c2298162e4e06b73f44b43f747ba9", + "version_major": 2, + "version_minor": 1 + }, + "text/plain": [ + "NiiVue(height=300)" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from ipyniivue import NiiVue, SliceType\n", + "# based on https://github.com/niivue/ipyniivue/blob/main/original_gallery.md#tractography-tck-trk-trx-vtk\n", + "\n", + "volumes = [\n", + " { \"path\": \"images/mni152.nii.gz\", \"colormap\": \"gray\", \"visible\": True, \"opacity\": 1.0 },\n", + "\n", + "]\n", + "\n", + "nv = NiiVue(slice_type=SliceType.MULTIPLANAR)\n", + "nv.load_volumes(volumes)\n", + "\n", + "nv.load_meshes(\n", + " [\n", + " {\n", + " \"path\": \"images/BrainMesh_ICBM152.lh.mz3\",\n", + " \"rgba255\": [255, 255, 255, 255],\n", + " }\n", + " ]\n", + ")\n", + "\n", + "\n", + "nv" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "593d466e-6bf6-47df-ba63-23b627f41da0", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/examples/mesh_layers.ipynb b/examples/mesh_layers.ipynb index baa2f05..f545c5d 100644 --- a/examples/mesh_layers.ipynb +++ b/examples/mesh_layers.ipynb @@ -2,23 +2,26 @@ "cells": [ { "cell_type": "code", - "execution_count": null, - "id": "6606a337-3243-4041-a7b7-ec64136f245c", - "metadata": {}, - "outputs": [], - "source": [ - "!mkdir -p ../images/\n", - "!wget https://github.com/niivue/niivue/raw/main/demos/images/BrainMesh_ICBM152.lh.mz3 -P ../images/\n", - "!wget https://github.com/niivue/niivue/raw/main/demos/images/CIT168.mz3 -P ../images/\n", - "!wget https://github.com/niivue/niivue/raw/main/demos/images/BrainMesh_ICBM152.lh.motor.mz3 -P ../images/" - ] - }, - { - "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "36d80248-e8a6-4f27-92c5-98dabf2aec81", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "17ebee0428a44ef5a75fb9f9319c8764", + "version_major": 2, + "version_minor": 1 + }, + "text/plain": [ + "NiiVue(height=300)" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "from ipyniivue import NiiVue\n", "\n", @@ -27,7 +30,7 @@ ")\n", "\n", "mesh_layer = {\n", - " \"path\": \"../images/BrainMesh_ICBM152.lh.motor.mz3\",\n", + " \"path\": \"images/BrainMesh_ICBM152.lh.motor.mz3\",\n", " \"cal_min\": 0.5,\n", " \"cal_max\": 5.5,\n", " \"useNegativeCmap\": True,\n", @@ -37,11 +40,11 @@ "nv.load_meshes(\n", " [\n", " {\n", - " \"path\": \"../images/BrainMesh_ICBM152.lh.mz3\",\n", + " \"path\": \"images/BrainMesh_ICBM152.lh.mz3\",\n", " \"rgba255\": [255, 255, 255, 255],\n", " \"layers\": [mesh_layer],\n", " },\n", - " {\"path\": \"../images/CIT168.mz3\", \"rgba255\": [0, 0, 255, 255]},\n", + " {\"path\": \"images/CIT168.mz3\", \"rgba255\": [0, 0, 255, 255]},\n", " ]\n", ")\n", "\n", @@ -50,7 +53,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "956fe2ef-3180-44cc-a81e-05efc783ee05", "metadata": {}, "outputs": [], @@ -61,38 +64,13 @@ { "cell_type": "code", "execution_count": null, - "id": "9b204adc-74a2-4091-be4f-2e0dd888d4c6", + "id": "69a4c0b3", "metadata": {}, "outputs": [], "source": [] } ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.9" - }, - "widgets": { - "application/vnd.jupyter.widget-state+json": { - "state": {}, - "version_major": 2, - "version_minor": 0 - } - } - }, + "metadata": {}, "nbformat": 4, "nbformat_minor": 5 } diff --git a/examples/meshes_(GIfTI, FreeSurfer, MZ3, OBJ, STL, legacy VTK).ipynb b/examples/meshes_(GIfTI, FreeSurfer, MZ3, OBJ, STL, legacy VTK).ipynb new file mode 100644 index 0000000..f05a4cd --- /dev/null +++ b/examples/meshes_(GIfTI, FreeSurfer, MZ3, OBJ, STL, legacy VTK).ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "05bb313319804b9fa0dd2166c1526597", + "version_major": 2, + "version_minor": 1 + }, + "text/plain": [ + "NiiVue(height=300)" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from ipyniivue import NiiVue\n", + "# based on https://github.com/niivue/ipyniivue/blob/main/original_gallery.md#meshes-gifti-freesurfer-mz3-obj-stl-legacy-vtk\n", + "nv = NiiVue(\n", + " show_3d_crosshair=True, back_color=(1, 1, 1, 1), mesh_x_ray=0.3, is_colorbar=True\n", + ")\n", + "\n", + "nv.load_meshes(\n", + " [\n", + " {\n", + " \"path\": \"images/BrainMesh_ICBM152.lh.mz3\",\n", + " \"rgba255\": [222, 164, 164, 255],\n", + " },\n", + " { \"path\": \"images/CIT168.mz3\", \"rgba255\": [0, 0, 255, 255] },\n", + " ]\n", + ")\n", + "\n", + "nv\n", + "\n", + "# nv1.setMeshShader(nv1.meshes[0].id, \"Outline\"); does not seem to exist yet." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/examples/trajectory.ipynb b/examples/trajectory.ipynb new file mode 100644 index 0000000..612b676 --- /dev/null +++ b/examples/trajectory.ipynb @@ -0,0 +1,46 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from ipyniivue import NiiVue, SliceType\n", + "# based on https://github.com/niivue/ipyniivue/blob/main/original_gallery.md#tractography-tck-trk-trx-vtk\n", + "\n", + "volumes = [\n", + " { \"path\": \"images/mni152.nii.gz\", \"colormap\": \"gray\", \"visible\": True, \"opacity\": 1.0 },\n", + "\n", + "]\n", + "\n", + "nv = NiiVue(slice_type=SliceType.MULTIPLANAR)\n", + "#nv.load_volumes(volumes)\n", + "\n", + "\n", + "nv.load_meshes(\n", + " [\n", + " {\n", + " \"path\": \"images/dpsv.trx\", # this does currently not load\n", + " \"rgba255\": [0, 142, 0, 255],\n", + " }\n", + " ]\n", + ")\n", + "\n", + "\n", + "\n", + "nv" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 2 +} From dbc249887db9c21b603466b3ac5b2bd85a0dddd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Hendrik=20M=C3=BCller?= <44469195+kolibril13@users.noreply.github.com> Date: Wed, 14 Aug 2024 15:34:10 +0200 Subject: [PATCH 2/2] add torso notebook --- examples/torso_regions.ipynb | 70 ++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 examples/torso_regions.ipynb diff --git a/examples/torso_regions.ipynb b/examples/torso_regions.ipynb new file mode 100644 index 0000000..8523244 --- /dev/null +++ b/examples/torso_regions.ipynb @@ -0,0 +1,70 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "id": "71c2f1ec-fdbf-4aae-8d09-77fd5988e11c", + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "fb1fdbd65e0845118d7955f94e149b24", + "version_major": 2, + "version_minor": 1 + }, + "text/plain": [ + "NiiVue(height=300)" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from ipyniivue import NiiVue, SliceType\n", + "# based on https://github.com/niivue/ipyniivue/blob/main/original_gallery.md#torso-regions\n", + "\n", + "volumes = [\n", + " { \"path\": \"images/torso.nii.gz\", \"colormap\": \"gray\", \"visible\": True, \"opacity\": 1.0 },\n", + "\n", + "]\n", + "\n", + "nv = NiiVue(slice_type=SliceType.MULTIPLANAR)\n", + "nv.load_volumes(volumes)\n", + "\n", + "nv" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "593d466e-6bf6-47df-ba63-23b627f41da0", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}