Skip to content

Commit 7c7acea

Browse files
committed
add another notebook
1 parent df6a3a7 commit 7c7acea

File tree

6 files changed

+201
-22
lines changed

6 files changed

+201
-22
lines changed

.github/workflows/test_with_tox.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
pull_request:
99
branches:
1010
- '*'
11+
schedule:
12+
- cron: 0 8 1 * *
13+
workflow_dispatch:
1114

1215
concurrency:
1316
group: ${{ github.workflow }}-${{ github.ref }}
@@ -27,7 +30,7 @@ jobs:
2730
strategy:
2831
fail-fast: true
2932
matrix:
30-
py: ['3.13', '3.12', '3.11']
33+
py: ['3.13', '3.12', '3.11', '3.10', '3.9']
3134
os: [ubuntu-latest]
3235
steps:
3336
- uses: actions/checkout@v4
@@ -43,11 +46,4 @@ jobs:
4346
run: tox c
4447
- name: Run test suite
4548
run: |
46-
tox run --list-dependencies -e test -- poia/poia.py
47-
48-
- name: Upload coverage to CodeCov
49-
uses: codecov/codecov-action@v5
50-
with:
51-
flags: ${{ matrix.os }}_${{ matrix.py }}
52-
token: ${{ secrets.CODECOV_TOKEN }}
53-
if: success()
49+
tox run --list-dependencies -e test

.pre-commit-config.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@ repos:
4646
hooks:
4747
# Run the linter.
4848
- id: ruff
49-
# args: [--statistics]
5049
args: [--fix, --show-fixes]
5150
# Run the formatter.
5251
- id: ruff-format
53-
# args: [--diff]
5452

5553
- repo: https://github.com/pre-commit/mirrors-mypy
5654
rev: v1.15.0

notebooks/nilearn_notebooks_stable.py

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# /// script
2+
# requires-python = ">=3.9"
3+
# dependencies = [
4+
# "marimo",
5+
# "matplotlib",
6+
# "nilearn==0.11.1",
7+
# "numpy==2.2.4",
8+
# ]
9+
# ///
10+
11+
import marimo
12+
13+
__generated_with = "0.12.0"
14+
app = marimo.App(width="medium", app_title="nilearn stable")
15+
16+
17+
@app.cell(hide_code=True)
18+
def _(mo):
19+
mo.md(
20+
r"""
21+
# Using nilearn in a marimo notebook
22+
23+
This notebook is mostly for nilearn developpers
24+
to make sure nilearn functionalities run well
25+
in a marimo notebook.
26+
27+
But this can serve as an starting point
28+
for anyone to start using nilearn
29+
in a marimo notebook.
30+
"""
31+
)
32+
return
33+
34+
35+
@app.cell(hide_code=True)
36+
def _(mo):
37+
mo.md(r"""## Volume plotting""")
38+
return
39+
40+
41+
@app.cell
42+
def _(mo):
43+
from nilearn.datasets import load_mni152_template
44+
from nilearn.plotting import plot_img, show
45+
46+
template = load_mni152_template()
47+
img_fig = plot_img(template)
48+
show()
49+
50+
mo.md("Basic plotting of template.")
51+
return img_fig, load_mni152_template, plot_img, show, template
52+
53+
54+
@app.cell
55+
def _(mo, show):
56+
from nilearn.datasets import load_sample_motor_activation_image
57+
from nilearn.plotting import plot_stat_map
58+
59+
motor_activation_image = load_sample_motor_activation_image()
60+
stat_map_fig = plot_stat_map(motor_activation_image)
61+
show()
62+
63+
mo.md("Basic plotting of statistical map.")
64+
return (
65+
load_sample_motor_activation_image,
66+
motor_activation_image,
67+
plot_stat_map,
68+
stat_map_fig,
69+
)
70+
71+
72+
@app.cell
73+
def _(mo, motor_activation_image, show):
74+
from nilearn.plotting import plot_glass_brain
75+
76+
plot_glass_brain(motor_activation_image, threshold=3)
77+
show()
78+
79+
mo.md("Basic plotting of a glass brain.")
80+
return (plot_glass_brain,)
81+
82+
83+
@app.cell(hide_code=True)
84+
def _(mo):
85+
mo.md(r"""Interactive image ⬇️""")
86+
return
87+
88+
89+
@app.cell
90+
def _(motor_activation_image):
91+
from nilearn.plotting import view_img
92+
html_fig = view_img(motor_activation_image)
93+
html_fig
94+
return html_fig, view_img
95+
96+
97+
@app.cell(hide_code=True)
98+
def _(mo):
99+
mo.md(r"""## Surface plotting""")
100+
return
101+
102+
103+
@app.cell
104+
def _(mo, motor_activation_image, show):
105+
from nilearn.datasets import load_fsaverage
106+
from nilearn.surface import SurfaceImage
107+
import numpy as np
108+
from nilearn.plotting import plot_surf_stat_map
109+
from nilearn.datasets import load_fsaverage_data
110+
111+
fsaverage_meshes = load_fsaverage()
112+
113+
surface_image = SurfaceImage.from_volume(
114+
mesh=fsaverage_meshes["pial"],
115+
volume_img=motor_activation_image,
116+
)
117+
118+
curv_sign = load_fsaverage_data(data_type="curvature")
119+
120+
fig = plot_surf_stat_map(
121+
stat_map=surface_image,
122+
surf_mesh=fsaverage_meshes["inflated"],
123+
title="Surface with matplotlib",
124+
threshold=1.0,
125+
bg_map=curv_sign,
126+
)
127+
show()
128+
129+
mo.md("Basic surface plotting.")
130+
return (
131+
SurfaceImage,
132+
curv_sign,
133+
fig,
134+
fsaverage_meshes,
135+
load_fsaverage,
136+
load_fsaverage_data,
137+
np,
138+
plot_surf_stat_map,
139+
surface_image,
140+
)
141+
142+
143+
@app.cell(hide_code=True)
144+
def _(mo):
145+
mo.md(r"""Interactive surface viewing""")
146+
return
147+
148+
149+
@app.cell
150+
def _(curv_sign, fsaverage_meshes, surface_image):
151+
from nilearn.plotting import view_surf
152+
153+
view_surf(
154+
surf_mesh=fsaverage_meshes["inflated"],
155+
surf_map=surface_image,
156+
threshold="90%",
157+
bg_map=curv_sign,
158+
title="3D visualization in a web browser",
159+
)
160+
return (view_surf,)
161+
162+
163+
@app.cell
164+
def _(motor_activation_image):
165+
from nilearn.plotting import view_img_on_surf
166+
167+
view_img_on_surf(motor_activation_image, threshold="90%")
168+
return (view_img_on_surf,)
169+
170+
171+
@app.cell
172+
def _():
173+
import marimo as mo
174+
return (mo,)
175+
176+
177+
if __name__ == "__main__":
178+
app.run()

pyproject.toml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,9 @@ warn_unreachable = false
99

1010
[[tool.mypy.overrides]]
1111
ignore_missing_imports = true
12-
module = [
13-
"plotly.*",
14-
"matplotlib.*",
15-
"marimo.*",
16-
"nilearn.*"
17-
]
12+
module = ["plotly.*", "matplotlib.*", "marimo.*", "nilearn.*"]
1813

1914
[tool.ruff]
20-
include = ["pyproject.toml", "poia"]
2115
indent-width = 4
2216
line-length = 100
2317

@@ -30,7 +24,6 @@ quote-style = "double"
3024
skip-magic-trailing-comma = false
3125

3226
[tool.ruff.lint]
33-
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
3427
fixable = ["ALL"]
3528
ignore = [
3629
"B018",
@@ -88,7 +81,7 @@ select = [
8881
unfixable = []
8982

9083
[tool.ruff.lint.mccabe]
91-
max-complexity = 29
84+
max-complexity = 15
9285

9386
[tool.ruff.lint.per-file-ignores]
9487
"notebooks/**/*.py" = ["E501", "E741"]
@@ -101,7 +94,7 @@ convention = "numpy"
10194
# https://docs.astral.sh/ruff/settings/#lint_pylint_max-args
10295
max-args = 15
10396
# https://docs.astral.sh/ruff/settings/#lint_pylint_max-branches
104-
max-branches = 33
97+
max-branches = 15
10598
# https://docs.astral.sh/ruff/settings/#lint_pylint_max-returns
10699
max-returns = 10
107100
# https://docs.astral.sh/ruff/settings/#lint_pylint_max-statements

scripts/build.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ def generate_index(all_notebooks: list[str], output_dir: str) -> None:
9191

9292
def main() -> None:
9393
parser = argparse.ArgumentParser(description="Build marimo notebooks")
94-
parser.add_argument("--output-dir", default="_site", help="Output directory for built files")
94+
parser.add_argument(
95+
"--output-dir",
96+
default="_site",
97+
help="Output directory for built files",
98+
)
9599
args = parser.parse_args()
96100

97101
all_notebooks: list[str] = []

tox.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,13 @@ deps =
3939
commands =
4040
python scripts/build.py
4141

42+
[testenv:test]
43+
description = Run tests on latest version of all dependencies.
44+
passenv = {[global_var]passenv}
45+
deps =
46+
marimo
47+
nilearn[plotly]
48+
pytest
49+
commands =
50+
python notebooks/intro_to_marimo.py
51+
python notebooks/nilearn_notebooks_stable.py

0 commit comments

Comments
 (0)