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

Add new tutorials to how to page in docs #1972

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion docs/demos-template.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
Tutorials
*********

Load and visualise data
=======================

.. nbgallery::
${notebooks_load}

Geometry
=======================

.. nbgallery::
${notebooks_geometry}

Advanced topics
===============

.. nbgallery::
${notebooks}
${notebooks_advanced}
44 changes: 32 additions & 12 deletions docs/mkdemos.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,46 @@
from tqdm import tqdm

# URLS of the notebooks to render
NOTEBOOKS = (
"https://github.com/TomographicImaging/CIL-Demos/raw/main/demos/1_Introduction/00_CIL_geometry.ipynb",
NOTEBOOKS_load = [
"https://tomography.stfc.ac.uk/how-tos/ZeissDataReader.ipynb",
"https://tomography.stfc.ac.uk/how-tos/NikonDataReader.ipynb"
]

NOTEBOOKS_geometry = [
"https://github.com/TomographicImaging/CIL-Demos/raw/main/demos/1_Introduction/00_CIL_geometry.ipynb"
]

NOTEBOOKS_advanced = [
"https://github.com/TomographicImaging/CIL-User-Showcase/raw/main/003_1D_integral_inverse_problem/deriv2_cgls.ipynb",
"https://github.com/TomographicImaging/CIL-Demos/raw/main/misc/callback_demonstration.ipynb"
)
]

SOURCE = Path(__file__).parent / "source" # sphinx documentation dir
NBDIR = "demos" # notebook subdir to create
(SOURCE / NBDIR).mkdir(parents=True, exist_ok=True)

# download the notebooks
notebooks = []
with tqdm(NOTEBOOKS, unit="ipynb") as urls:
for url in urls:
notebook = Path(urlparse(url).path)
urls.set_description(notebook.stem)
with urlopen(url) as response:
(SOURCE / NBDIR / notebook.name).write_bytes(response.read())
notebooks.append(f" {NBDIR}/{notebook.stem}")
def download_notebooks(urls):
notebooks = []
with tqdm(urls, unit="ipynb") as nb_urls:
for url in nb_urls :
notebook = Path(urlparse(url).path)
print(notebook)
nb_urls.set_description(notebook.stem)
with urlopen(url) as response:
(SOURCE / NBDIR / notebook.name).write_bytes(response.read())
notebooks.append(f" {NBDIR}/{notebook.stem}")
return "\n".join(notebooks)

notebooks_load = download_notebooks(NOTEBOOKS_load)
notebooks_geometry = download_notebooks(NOTEBOOKS_geometry)
notebooks_advanced = download_notebooks(NOTEBOOKS_advanced)

# load template
tmp = Template((SOURCE / '..' / 'demos-template.rst').read_text())
# write to demos.rst
(SOURCE / 'demos.rst').write_text(tmp.safe_substitute(notebooks="\n".join(notebooks)))
(SOURCE / 'demos.rst').write_text(tmp.safe_substitute(
notebooks_load=notebooks_load,
notebooks_geometry=notebooks_geometry,
notebooks_advanced=notebooks_advanced
))
Loading