Skip to content

Commit 8e7a7bf

Browse files
committed
update
1 parent 750a192 commit 8e7a7bf

File tree

4 files changed

+28
-137
lines changed

4 files changed

+28
-137
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Nilearn Marimo notebooks
2+
3+
The structure of this repository is mostly adapted from
4+
the [marimo template repo](https://github.com/marimo-team/marimo-gh-pages-template).

notebooks/intro_to_marimo.py

Lines changed: 21 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
import marimo
44

55
__generated_with = "0.12.0"
6-
app = marimo.App(
7-
width="medium",
8-
app_title="Intro to Marimo notebooks",
9-
layout_file="layouts/mo_intro.slides.json",
10-
)
6+
app = marimo.App(width="medium", app_title="Intro to Marimo notebooks")
117

128

139
@app.cell(hide_code=True)
1410
def _(mo):
15-
mo.md(r"""# Marimo notebooks""")
11+
mo.md(r"""# Introduction to marimo notebooks""")
1612
return
1713

1814

@@ -89,6 +85,8 @@ def _(mo):
8985
### Side effect
9086
9187
Variables cannot be redefined.
88+
89+
Try renaming the following variable from `_a` to `a` and run the cell.
9290
"""
9391
)
9492
return
@@ -114,7 +112,7 @@ def _(mo, show_intro_nb):
114112

115113
@app.cell(hide_code=True)
116114
def _(mo):
117-
mo.md(r"""All cells are just function with app.cell()app.cell() decorator.""")
115+
mo.md(r"""All cells are just function with `app.cell()` decorator.""")
118116
return
119117

120118

@@ -209,7 +207,7 @@ def test_function(function_to_test):
209207
def _(mo):
210208
mo.md(
211209
r"""
212-
Name cells that contain a test_..."test_..." and run pytest on your notebook.
210+
Name cells that contain a "test_..." and run pytest on your notebook.
213211
214212
```bash
215213
$ pytest notebooks/mo_intro.py
@@ -261,16 +259,17 @@ def _(mo):
261259

262260

263261
@app.cell
264-
def _(mo):
265-
import pandas as pd
262+
def _():
263+
from nilearn.glm.tests._testing import modulated_event_paradigm
266264

267-
nilearn_repos = pd.read_csv(mo.notebook_location() / "public" / "nilearn_repos.csv")
268-
return nilearn_repos, pd
265+
events = modulated_event_paradigm()
266+
events
267+
return events, modulated_event_paradigm
269268

270269

271270
@app.cell
272-
def _(mo, nilearn_repos):
273-
transformed_df = mo.ui.dataframe(nilearn_repos)
271+
def _(events, mo):
272+
transformed_df = mo.ui.dataframe(events)
274273
transformed_df
275274
return (transformed_df,)
276275

@@ -283,88 +282,27 @@ def _(mo):
283282

284283
@app.cell
285284
def _(mo):
286-
options = ["", "extracted_version"]
287-
radio = mo.ui.radio(options=options)
288-
return options, radio
285+
slider = mo.ui.slider(start=0, stop=7, step=1, label="Thresold", value=2)
286+
return (slider,)
289287

290288

291-
@app.cell(hide_code=True)
292-
def _(mo, nilearn_repos, plot_repos, radio):
293-
repo_fig = plot_repos(nilearn_repos, color=radio.value)
294-
repo_fig.show()
295-
296-
mo.hstack(
297-
[
298-
mo.vstack([mo.md("color"), radio]),
299-
],
300-
align="center",
301-
)
302-
return (repo_fig,)
289+
@app.cell
290+
def _(slider):
291+
slider
292+
return
303293

304294

305295
@app.cell
306-
def _():
296+
def _(slider):
307297
from nilearn.datasets import load_sample_motor_activation_image
308298
from nilearn.plotting import view_img
309299

310300
stat_map = load_sample_motor_activation_image()
311301

312-
view_img(stat_map, threshold=3)
302+
view_img(stat_map, threshold=slider.value)
313303
return load_sample_motor_activation_image, stat_map, view_img
314304

315305

316-
@app.cell
317-
def _(mo):
318-
def foo(a):
319-
a
320-
321-
mo.md(
322-
r"""
323-
## Qualite of life improvements
324-
325-
- tab completion
326-
- type 'aware'
327-
"""
328-
)
329-
return (foo,)
330-
331-
332-
@app.cell(hide_code=True)
333-
def _(mo):
334-
mo.md(
335-
r"""
336-
## Personal remarks
337-
338-
### ➕
339-
340-
- impossibility to dynamically reuse variables,
341-
nudge users to create functions to encapsulate things
342-
- automatic execution of cells that are resource intensive
343-
is annoying, so it nudges users to have save data at bottlenecks.
344-
345-
### ➖
346-
347-
- sometimes when stopping a notebook execution,
348-
you have to reexcute some cells manually
349-
for the notebook execution to continue.
350-
"""
351-
)
352-
return
353-
354-
355-
@app.cell(hide_code=True)
356-
def _(mo):
357-
mo.md(
358-
r"""
359-
## Not mentioned
360-
361-
- code snippets
362-
- deploy to github pages and other places
363-
"""
364-
)
365-
return
366-
367-
368306
@app.cell
369307
def _():
370308
import marimo as mo
@@ -406,57 +344,5 @@ def show_intro_nb(break_condition: str = "def cell_2(") -> str:
406344
return (show_intro_nb,)
407345

408346

409-
@app.cell(hide_code=True)
410-
def _(pd):
411-
import matplotlib.colors as mcolors
412-
import matplotlib.pyplot as plt
413-
import plotly.express as px
414-
from packaging.version import Version
415-
416-
def plot_repos(df: pd.DataFrame, color: str | None = None):
417-
if color == "":
418-
color = None
419-
420-
df.drop_duplicates(subset=["name"])
421-
df = df[df["include"]]
422-
423-
category_orders = None
424-
color_map = None
425-
if color:
426-
df = df.dropna(subset=[color])
427-
428-
# Sort version labels naturally
429-
category_orders = {color: sorted(df[color].unique())}
430-
if color == "extracted_version":
431-
ordered_versions = sorted(df[color].unique(), key=Version)
432-
category_orders = {color: ordered_versions}
433-
434-
# Get Jet colors for each version using matplotlib
435-
cmap = plt.get_cmap("jet", len(ordered_versions))
436-
color_map = [mcolors.to_hex(cmap(i)) for i in range(len(ordered_versions))]
437-
438-
start_date = df["last_commit"].min()
439-
end_date = df["last_commit"].max()
440-
441-
fig = px.histogram(
442-
df,
443-
x="last_commit",
444-
color=color,
445-
category_orders=category_orders,
446-
color_discrete_sequence=color_map,
447-
title=f"Analysis of {len(df)} repositories",
448-
)
449-
450-
fig.update_layout(xaxis_title="Last Commit Date", yaxis_title="Usage Count")
451-
452-
fig.update_xaxes(tickformat="%Y-%m")
453-
454-
# Update the x-axis bin size to 3 months
455-
fig.update_traces(xbins={"start": start_date, "end": end_date, "size": "M3"})
456-
457-
return fig
458-
return Version, mcolors, plot_repos, plt, px
459-
460-
461347
if __name__ == "__main__":
462348
app.run()

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
builtin = "clear,rare,en-GB_to_en-US"
33
skip = "./.git,*.cff,*/tmp,.mypy_cache,env,venv"
44

5-
65
[tool.mypy]
76
allow_redefinition = false
87
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
@@ -14,6 +13,7 @@ module = [
1413
"plotly.*",
1514
"matplotlib.*",
1615
"marimo.*",
16+
"nilearn.*"
1717
]
1818

1919
[tool.ruff]
@@ -92,7 +92,7 @@ max-complexity = 29
9292

9393
[tool.ruff.lint.per-file-ignores]
9494
"notebooks/**/*.py" = ["E501", "E741"]
95-
"scripts/build.py" = ["E501"]
95+
"scripts/build.py" = ["E501", "PTH118", "PTH103", "PTH123", "PTH120"]
9696

9797
[tool.ruff.lint.pydocstyle]
9898
convention = "numpy"

scripts/build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python3
2+
"""Build notebooks into deployable HTML."""
23

34
import argparse
45
import os

0 commit comments

Comments
 (0)