Skip to content

Commit

Permalink
Merge pull request #152 from spinal-cord-7t/mb/jb
Browse files Browse the repository at this point in the history
Convert notebook to jupyter books with outputs and host on GitHub pages
  • Loading branch information
mathieuboudreau authored Nov 4, 2024
2 parents a7e540f + 647befb commit 7c0dbea
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 65 deletions.
57 changes: 12 additions & 45 deletions .github/workflows/run_notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ on:
push:
branches:
- main # Trigger the action on the main branch
- mb/jb

permissions:
id-token: write
pages: write

jobs:
# Run the notebooks
Expand Down Expand Up @@ -46,51 +51,13 @@ jobs:
# Make sure SCT can be called from within the environment
sct_check_dependencies
- name: Run Jupyter Notebooks
- name: Run Jupyter Notebooks and build book
continue-on-error: true # Allow workflow to continue even if notebook execution fails
run: |
echo $PATH
mkdir -p executed_notebooks
for notebook in $(find . -name "*.ipynb"); do
echo "Executing $notebook"
jupyter nbconvert --to notebook --execute --allow-errors --inplace \
--output executed_notebooks/$(basename $notebook) $notebook \
2>&1 | tee -a notebook_execution.log || exit 1
done
- name: Check Execution Log
run: cat notebook_execution.log

- name: Upload Executed Notebooks
uses: actions/upload-artifact@v3
run: jupyter-book build .
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
name: executed-notebooks
path: executed_notebooks/

# Deploy to GitHub Pages (depends on run-notebooks)
deploy:
runs-on: ubuntu-latest
needs: run-notebooks # Ensure this job runs after 'run-notebooks'

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Download Executed Notebooks
uses: actions/download-artifact@v3
with:
name: executed-notebooks
path: executed_notebooks/

- name: Copy Executed Notebooks to Pages Directory
run: |
COMMIT_SHA=$(git rev-parse --short HEAD)
mkdir -p gh-pages/$COMMIT_SHA
cp executed_notebooks/*.ipynb gh-pages/$COMMIT_SHA/
path: './_build/html'
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: gh-pages
publish_branch: gh-pages
id: deployment
uses: actions/deploy-pages@v4
26 changes: 26 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Book settings
# Learn more at https://jupyterbook.org/customize/config.html

title: "Multi-center benchmarking of cervical spinal cord RF coils at 7 T: A traveling spines study"
author: NeuroPoly Lab

# Force re-execution of notebooks on each build.
# See https://jupyterbook.org/content/execute.html
execute:
execute_notebooks: force

launch_buttons:
notebook_interface: jupyterlab
binderhub_url: https://mybinder.org


# Information about where the book exists on the web
repository:
url: https://github.com/coil-qc-code/coil-qc-code # Online location of your book
branch: mb/jb # Which branch of the repository should be used when creating links (optional)

only_build_toc_files: true

execute:
timeout: 36000

8 changes: 8 additions & 0 deletions _toc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Table of contents
# Learn more at https://jupyterbook.org/customize/toc.html

format: jb-book
root: README.md
chapters:
- file: data_processing-human.ipynb
- file: data_processing-phantom.ipynb
80 changes: 68 additions & 12 deletions data_processing-human.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "86a25f63",
"metadata": {},
"source": [
"# 7T coil comparison: processing of human data"
]
},
{
"cell_type": "markdown",
"id": "0",
Expand Down Expand Up @@ -57,7 +65,11 @@
"cell_type": "code",
"execution_count": null,
"id": "3",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"# Download data from OpenNeuro ⏳\n",
Expand Down Expand Up @@ -97,7 +109,11 @@
"cell_type": "code",
"execution_count": null,
"id": "6",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"# Run segmentation on MP2RAGE scan ⏳\n",
Expand All @@ -121,7 +137,11 @@
"cell_type": "code",
"execution_count": null,
"id": "7",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"# Label vertebrae\n",
Expand All @@ -144,7 +164,11 @@
"cell_type": "code",
"execution_count": null,
"id": "8",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"# Crop MP2RAGE for faster processing and better registration results\n",
Expand Down Expand Up @@ -178,7 +202,11 @@
"cell_type": "code",
"execution_count": null,
"id": "10",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"# Segment spinal cord on TFL data (B1+ mapping) ⏳\n",
Expand Down Expand Up @@ -216,7 +244,11 @@
"cell_type": "code",
"execution_count": null,
"id": "11",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"# Register TFL data (B1+ mapping) to the MP2RAGE scan ⏳\n",
Expand Down Expand Up @@ -244,7 +276,11 @@
"cell_type": "code",
"execution_count": null,
"id": "12",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"# Register DREAM data (B1+ mapping) to the MP2RAGE scan ⏳\n",
Expand All @@ -266,7 +302,11 @@
"cell_type": "code",
"execution_count": null,
"id": "13",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"# Segment spinal cord on SNR data\n",
Expand Down Expand Up @@ -304,7 +344,11 @@
"cell_type": "code",
"execution_count": null,
"id": "14",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"# Register Rx coilQA data (SNR, g-factor) to the MP2RAGE scan ⏳\n",
Expand All @@ -326,7 +370,11 @@
"cell_type": "code",
"execution_count": null,
"id": "15",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"# Warping vertebral level to each flip angle and SNR map\n",
Expand Down Expand Up @@ -582,7 +630,11 @@
"cell_type": "code",
"execution_count": null,
"id": "21",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"# Extract B1+ and SNR along the spinal cord between levels C1 and T2 (included) and save data to CSV files\n",
Expand Down Expand Up @@ -952,7 +1004,11 @@
"cell_type": "code",
"execution_count": null,
"id": "34",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"# Co-register subjects across sites for better visualisation\n",
Expand Down
42 changes: 35 additions & 7 deletions data_processing-phantom.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@
"cell_type": "code",
"execution_count": null,
"id": "3",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"# Download data from OpenNeuro ⏳\n",
Expand Down Expand Up @@ -91,7 +95,11 @@
"cell_type": "code",
"execution_count": null,
"id": "6",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"# Convert the TFL flip angle maps to B1+ efficiency maps [nT/V] (inspired by code from Kyle Gilbert)\n",
Expand Down Expand Up @@ -142,7 +150,11 @@
"cell_type": "code",
"execution_count": null,
"id": "7",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"# load DREAM FA maps acquired with different reference voltages\n",
Expand Down Expand Up @@ -244,7 +256,11 @@
"cell_type": "code",
"execution_count": null,
"id": "8",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"# Split SNR data across multiple volumes. The first volume corresponds to the SoS SNR reconstruction, which is\n",
Expand All @@ -270,7 +286,11 @@
"cell_type": "code",
"execution_count": null,
"id": "10",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"os.chdir(os.path.join(path_data, \"sub-CRMBM\", \"fmap\"))\n",
Expand Down Expand Up @@ -301,7 +321,11 @@
"cell_type": "code",
"execution_count": null,
"id": "12",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"# Create dictionary of labels across sites\n",
Expand Down Expand Up @@ -377,7 +401,11 @@
"cell_type": "code",
"execution_count": null,
"id": "15",
"metadata": {},
"metadata": {
"tags": [
"scroll-output"
]
},
"outputs": [],
"source": [
"# Extract B1+ and SNR along the spinal cord mask and save data to CSV files\n",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jupyter-book==0.13.0
jupyter-book
lxml_html_clean
plotly
seaborn
Expand Down

0 comments on commit 7c0dbea

Please sign in to comment.