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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 228 additions & 0 deletions examples/01_download_all_data.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
92 changes: 47 additions & 45 deletions examples/additive_voxels.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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
}
Loading