Skip to content

Commit c38e6cd

Browse files
Merge pull request #182 from AnthonyAndroulakis/complex
Add complex.ipynb notebook example
2 parents a25ed63 + a497179 commit c38e6cd

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed

examples/complex.ipynb

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "ed7fbf9d-3501-42a4-b921-5b52d8f03ed1",
6+
"metadata": {},
7+
"source": [
8+
"# Import necessary modules"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": null,
14+
"id": "d3a59e62-a3df-4e47-b6d5-53fd79a9d959",
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"import pathlib\n",
19+
"\n",
20+
"import ipywidgets as widgets\n",
21+
"from IPython.display import display\n",
22+
"\n",
23+
"import ipyniivue\n",
24+
"from ipyniivue import NiiVue, download_dataset"
25+
]
26+
},
27+
{
28+
"cell_type": "markdown",
29+
"id": "8e9962f5-1c8f-4b23-bbec-7799dedcc36d",
30+
"metadata": {},
31+
"source": [
32+
"# Download required data"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": null,
38+
"id": "51551acf-1252-4bd9-837a-e5322f4458d5",
39+
"metadata": {},
40+
"outputs": [],
41+
"source": [
42+
"DATA_FOLDER = pathlib.Path(ipyniivue.__file__).parent / \"images\"\n",
43+
"\n",
44+
"download_dataset(\n",
45+
" \"https://niivue.com/demos/images/\",\n",
46+
" dest_folder=DATA_FOLDER,\n",
47+
" files=[\n",
48+
" \"complex.nii.gz\",\n",
49+
" ],\n",
50+
")"
51+
]
52+
},
53+
{
54+
"cell_type": "markdown",
55+
"id": "e41d20b2-cb78-4593-ab04-27f62d866762",
56+
"metadata": {},
57+
"source": [
58+
"# Setup NiiVue instance"
59+
]
60+
},
61+
{
62+
"cell_type": "code",
63+
"execution_count": null,
64+
"id": "1fcb1f7a-fdbf-4fdc-b59d-ce18e53a8f04",
65+
"metadata": {},
66+
"outputs": [],
67+
"source": [
68+
"nv = NiiVue()\n",
69+
"\n",
70+
"intensity_output = widgets.HTML(\" \")\n",
71+
"\n",
72+
"\n",
73+
"@nv.on_location_change\n",
74+
"def handle_intensity_change(location):\n",
75+
" \"\"\"Handle location change.\"\"\"\n",
76+
" intensity_output.value = location[\"string\"]\n",
77+
"\n",
78+
"\n",
79+
"nv.load_volumes(\n",
80+
" [\n",
81+
" {\"path\": DATA_FOLDER / \"complex.nii.gz\"},\n",
82+
" ]\n",
83+
")"
84+
]
85+
},
86+
{
87+
"cell_type": "markdown",
88+
"id": "9fb4ad15-2f7c-41cd-9444-dc9792ff621a",
89+
"metadata": {},
90+
"source": [
91+
"# Create other widget"
92+
]
93+
},
94+
{
95+
"cell_type": "code",
96+
"execution_count": null,
97+
"id": "a238bbe0-efaa-402b-8242-00a40b4494fa",
98+
"metadata": {},
99+
"outputs": [],
100+
"source": [
101+
"slice_type_dropdown = widgets.Dropdown(\n",
102+
" options=[\n",
103+
" (\"Axial\", 0),\n",
104+
" (\"Coronal\", 1),\n",
105+
" (\"Sagittal\", 2),\n",
106+
" (\"Render\", 4),\n",
107+
" (\"A+C+S+R\", 3),\n",
108+
" ],\n",
109+
" value=3,\n",
110+
" description=\"Slice Type:\",\n",
111+
")\n",
112+
"\n",
113+
"\n",
114+
"def on_slice_type_change(change):\n",
115+
" \"\"\"Set slice type.\"\"\"\n",
116+
" nv.set_slice_type(change[\"new\"])\n",
117+
"\n",
118+
"\n",
119+
"slice_type_dropdown.observe(on_slice_type_change, names=\"value\")"
120+
]
121+
},
122+
{
123+
"cell_type": "markdown",
124+
"id": "a0c433b8-9e9c-4c8c-881b-2785b5c2da64",
125+
"metadata": {},
126+
"source": [
127+
"# Display all"
128+
]
129+
},
130+
{
131+
"cell_type": "code",
132+
"execution_count": null,
133+
"id": "1c5c0e07-9729-41b2-ab33-9d04163a392d",
134+
"metadata": {},
135+
"outputs": [],
136+
"source": [
137+
"display(widgets.VBox([slice_type_dropdown, nv, intensity_output]))"
138+
]
139+
}
140+
],
141+
"metadata": {},
142+
"nbformat": 4,
143+
"nbformat_minor": 5
144+
}

0 commit comments

Comments
 (0)