Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more examples to the gallery #80

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
33 changes: 23 additions & 10 deletions examples/additive_voxels.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,26 @@
"metadata": {},
"outputs": [],
"source": [
"!mkdir -p ../images/\n",
"path = \"https://github.com/niivue/niivue/raw/main/demos/images/\"\n",
"!wget {path}narps-4735_50GV-hypo1_unthresh.nii.gz -P ../images/\n",
"!wget {path}narps-4965_9U7M-hypo1_unthresh.nii.gz -P ../images/\n",
"!wget {path}mni152.nii.gz -P ../images/"
"from pathlib import Path\n",
"\n",
"import ipyniivue\n",
"from ipyniivue import NiiVue, download_dataset\n",
"\n",
"# GitHub API URL for the base folder\n",
"BASE_API_URL = (\n",
" \"https://api.github.com/repos/niivue/niivue/contents/packages/niivue/demos/images\"\n",
")\n",
"DATA_FOLDER = Path(ipyniivue.__file__).parent / \"images\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Downloads all data for examples\n",
"download_dataset(f\"{BASE_API_URL}\", DATA_FOLDER)"
]
},
{
Expand All @@ -19,20 +34,18 @@
"metadata": {},
"outputs": [],
"source": [
"from ipyniivue import NiiVue\n",
"\n",
"# based on https://niivue.github.io/niivue/features/additive.voxels.html\n",
"\n",
"volumes = [\n",
" {\"path\": \"../images/mni152.nii.gz\"},\n",
" {\"path\": DATA_FOLDER / \"mni152.nii.gz\"},\n",
" {\n",
" \"path\": \"../images/narps-4965_9U7M-hypo1_unthresh.nii.gz\",\n",
" \"path\": DATA_FOLDER / \"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\": DATA_FOLDER / \"narps-4735_50GV-hypo1_unthresh.nii.gz\",\n",
" \"colormap\": \"green\",\n",
" \"cal_min\": 2,\n",
" \"cal_max\": 4,\n",
Expand Down
39 changes: 23 additions & 16 deletions examples/basic_multiplanar.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,26 @@
"metadata": {},
"outputs": [],
"source": [
"!mkdir -p ../images/\n",
"path = \"https://github.com/niivue/niivue/raw/main/demos/images/\"\n",
"!wget {path}mni152.nii.gz -P ../images/\n",
"!wget {path}hippo.nii.gz -P ../images/"
"from pathlib import Path\n",
"\n",
"import ipyniivue\n",
"from ipyniivue import NiiVue, SliceType, download_dataset\n",
"\n",
"# GitHub API URL for the base folder\n",
"BASE_API_URL = (\n",
" \"https://api.github.com/repos/niivue/niivue/contents/packages/niivue/demos/images\"\n",
")\n",
"DATA_FOLDER = Path(ipyniivue.__file__).parent / \"images\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Downloads all data for examples\n",
"download_dataset(f\"{BASE_API_URL}\", DATA_FOLDER)"
]
},
{
Expand All @@ -18,19 +34,17 @@
"metadata": {},
"outputs": [],
"source": [
"from ipyniivue import NiiVue, SliceType\n",
"\n",
"# based on https://niivue.github.io/niivue/features/basic.multiplanar.html\n",
"\n",
"volumes = [\n",
" {\n",
" \"path\": \"../images/mni152.nii.gz\",\n",
" \"path\": DATA_FOLDER / \"mni152.nii.gz\",\n",
" \"colormap\": \"gray\",\n",
" \"visible\": True,\n",
" \"opacity\": 1.0,\n",
" },\n",
" {\n",
" \"path\": \"../images/hippo.nii.gz\",\n",
" \"path\": DATA_FOLDER / \"hippo.nii.gz\",\n",
" \"colormap\": \"red\",\n",
" \"visible\": True,\n",
" \"opacity\": 1,\n",
Expand Down Expand Up @@ -89,14 +103,7 @@
"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
}
"version": "3.11.6"
}
},
"nbformat": 4,
Expand Down
97 changes: 97 additions & 0 deletions examples/mesh_and_volume.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "593d466e-6bf6-47df-ba63-23b627f41da0",
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"\n",
"import ipyniivue\n",
"from ipyniivue import NiiVue, SliceType, download_dataset\n",
"\n",
"# GitHub API URL for the base folder\n",
"BASE_API_URL = (\n",
" \"https://api.github.com/repos/niivue/niivue/contents/packages/niivue/demos/images\"\n",
")\n",
"DATA_FOLDER = Path(ipyniivue.__file__).parent / \"images\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a09b7f2a-d0f7-4337-bfcc-ce5152fa9e79",
"metadata": {},
"outputs": [],
"source": [
"# Downloads all data for examples\n",
"download_dataset(f\"{BASE_API_URL}\", DATA_FOLDER)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "71c2f1ec-fdbf-4aae-8d09-77fd5988e11c",
"metadata": {},
"outputs": [],
"source": [
"# based on https://github.com/niivue/ipyniivue/blob/main/original_gallery.md#tractography-tck-trk-trx-vtk\n",
"\n",
"volumes = [\n",
" {\n",
" \"path\": DATA_FOLDER / \"mni152.nii.gz\",\n",
" \"colormap\": \"gray\",\n",
" \"visible\": True,\n",
" \"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\": DATA_FOLDER / \"BrainMesh_ICBM152.lh.mz3\",\n",
" \"rgba255\": [255, 255, 255, 255],\n",
" }\n",
" ]\n",
")\n",
"\n",
"\n",
"nv"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "851a559d-59e8-40bc-b1f0-9380f9844855",
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
46 changes: 26 additions & 20 deletions examples/mesh_layers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,31 @@
{
"cell_type": "code",
"execution_count": null,
"id": "6606a337-3243-4041-a7b7-ec64136f245c",
"id": "69a4c0b3",
"metadata": {},
"outputs": [],
"source": [
"!mkdir -p ../images/\n",
"path = \"https://github.com/niivue/niivue/raw/main/demos/images/\"\n",
"!wget {path}BrainMesh_ICBM152.lh.mz3 -P ../images/\n",
"!wget {path}CIT168.mz3 -P ../images/\n",
"!wget {path}BrainMesh_ICBM152.lh.motor.mz3 -P ../images/"
"from pathlib import Path\n",
"\n",
"import ipyniivue\n",
"from ipyniivue import NiiVue, download_dataset\n",
"\n",
"# GitHub API URL for the base folder\n",
"BASE_API_URL = (\n",
" \"https://api.github.com/repos/niivue/niivue/contents/packages/niivue/demos/images\"\n",
")\n",
"DATA_FOLDER = Path(ipyniivue.__file__).parent / \"images\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "eaca0a33-87c7-437f-b9b5-a0c967a44faf",
"metadata": {},
"outputs": [],
"source": [
"# Downloads all data for examples\n",
"download_dataset(f\"{BASE_API_URL}\", DATA_FOLDER)"
]
},
{
Expand All @@ -21,14 +37,12 @@
"metadata": {},
"outputs": [],
"source": [
"from ipyniivue import NiiVue\n",
"\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",
"mesh_layer = {\n",
" \"path\": \"../images/BrainMesh_ICBM152.lh.motor.mz3\",\n",
" \"path\": DATA_FOLDER / \"BrainMesh_ICBM152.lh.motor.mz3\",\n",
" \"cal_min\": 0.5,\n",
" \"cal_max\": 5.5,\n",
" \"useNegativeCmap\": True,\n",
Expand All @@ -38,11 +52,11 @@
"nv.load_meshes(\n",
" [\n",
" {\n",
" \"path\": \"../images/BrainMesh_ICBM152.lh.mz3\",\n",
" \"path\": DATA_FOLDER / \"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\": DATA_FOLDER / \"CIT168.mz3\", \"rgba255\": [0, 0, 255, 255]},\n",
" ]\n",
")\n",
"\n",
Expand All @@ -56,16 +70,8 @@
"metadata": {},
"outputs": [],
"source": [
"nv.meshes[0].rgba255 = [0, 0, 0, 0]"
"nv.meshes[0].rgba255 = [200, 200, 200, 0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "811a654f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ab4d7045b8204843842d751f2bfe810f",
"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",
"\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": {
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading
Loading