-
Notifications
You must be signed in to change notification settings - Fork 7
ENH: Factor tutorial dataset access into helper #43
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
Merged
oesteban
merged 4 commits into
main
from
codex/update-book.yml-and-tutorial-markdown-files
Oct 8, 2025
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| """Utilities for accessing shared tutorial datasets.""" | ||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| from pathlib import Path | ||
| from typing import Final | ||
|
|
||
| import requests | ||
|
|
||
| from nifreeze.data.dmri import DWI | ||
|
|
||
| __all__ = ["ensure_tutorial_dwi_path", "load_tutorial_dmri_dataset"] | ||
|
|
||
| _DATA_URL: Final[str] = ( | ||
| "https://files.osf.io/v1/resources/8k95s/providers/osfstorage/68e5464a451cf9cf1fc51a53" | ||
| ) | ||
| _DEFAULT_FILENAME: Final[str] = "dwi_full_brainmask.h5" | ||
| _ENV_VAR: Final[str] = "NIPREPS_TUTORIAL_DATA" | ||
|
|
||
|
|
||
| def _resolve_data_path(filename: str = _DEFAULT_FILENAME) -> Path: | ||
| env_path = os.environ.get(_ENV_VAR) | ||
| return Path(env_path) if env_path else Path("data") / filename | ||
|
|
||
|
|
||
| def ensure_tutorial_dwi_path(filename: str = _DEFAULT_FILENAME) -> Path: | ||
| """Return the path to the cached tutorial DWI dataset, downloading it if needed.""" | ||
| datapath = _resolve_data_path(filename) | ||
| if not datapath.exists(): | ||
| datapath.parent.mkdir(parents=True, exist_ok=True) | ||
| response = requests.get(_DATA_URL, allow_redirects=True, timeout=60) | ||
| response.raise_for_status() | ||
| datapath.write_bytes(response.content) | ||
| return datapath | ||
|
|
||
|
|
||
| def load_tutorial_dmri_dataset(filename: str = _DEFAULT_FILENAME) -> DWI: | ||
| """Load the tutorial DWI dataset from disk, ensuring it is available.""" | ||
| return DWI.from_filename(ensure_tutorial_dwi_path(filename)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The notebooks now rely on
from tutorial_data import load_tutorial_dmri_dataset, buttutorial_data.pylives in the repository root and is neither installed nor added toPYTHONPATH. When the pages are executed fromdocs/tutorial(the default working directory forjupyter-bookand for users running a single notebook), only that directory is onsys.path, so the import raisesModuleNotFoundErrorand the build fails before any cells run. Consider moving the helper into the docs tree or explicitly adding the repo root tosys.pathbefore the import.Useful? React with 👍 / 👎.