Skip to main content

dartbrains-tools

Helper library and interactive anywidgets for the DartBrains fMRI course. Extracted from the book repo so the widgets and helpers can be installed standalone — including in molab and pyodide/WASM marimo notebooks.

Install

pip install dartbrains-tools

# Optional: include marimo for notebook_utils.youtube()
pip install "dartbrains-tools[notebook]"

Modules

  • dartbrains_tools.data.localizer — load the Pinel Localizer dataset from the Hugging Face Hub. The same API is re-exported at dartbrains_tools.data for back-compat.
  • dartbrains_tools.data.sherlock — load the Sherlock naturalistic-fMRI dataset (Chen et al. 2017).
  • dartbrains_tools.data.paranoia — load the Paranoia naturalistic-fMRI dataset (Finn et al. 2018).
  • dartbrains_tools.data.salary — the salary tables the pandas, polars and plotting tutorials use (get_file("salary.csv")).
  • dartbrains_tools.mr_simulations — Bloch equation solvers, signal generators, HRF, and Plotly visualization helpers.
  • dartbrains_tools.mr_widgets — 10 anywidgets for interactive MR physics teaching (PrecessionWidget, SpinEnsembleWidget, KSpaceWidget, ConvolutionWidget, EncodingWidget, CompassWidget, NetMagnetizationWidget, TransformCubeWidget, CostFunctionWidget, SmoothingWidget).
  • dartbrains_tools.storage — course storage behind Dartmouth sign-in: the class copy of the data, each student's private space, assignment data released on a schedule, and a durable cache. A thin wrapper over marimo_grader_client.storage that sets DartBrains' grader as the default and adds dataset() for the public Hugging Face repos. Falls back to a local directory (GRADER_STORAGE_ROOT) for builds and tests.
  • dartbrains_tools.notebook_utils — marimo helpers: youtube(), image() (the book's figures wherever the notebook runs, including molab), assignment_card() (links to a chapter's assignment on the grader).

Quick start

from dartbrains_tools.mr_widgets import PrecessionWidget

w = PrecessionWidget(b0=3.0, flip_angle=90.0)
w  # Interactive 3D Three.js animation in any anywidget host.
# Localizer (default; back-compat — also works as dartbrains_tools.data.localizer)
from dartbrains_tools.data import get_subjects, get_file, load_events

subjects = get_subjects()
bold = get_file("S01", scope="derivatives", suffix="bold")
events = load_events("S01")

# Sherlock
from dartbrains_tools.data import sherlock

bold = sherlock.get_file("sub-01", task="sherlockPart1", suffix="bold")
onsets = sherlock.load_onsets("watch")

# Paranoia
from dartbrains_tools.data import paranoia

# Salary tables (pandas / polars / plotting)
from dartbrains_tools.data import salary
import pandas as pd

df = pd.read_csv(salary.get_file("salary.csv"))

bold = paranoia.get_file("sub-tb2994", run=1, suffix="bold")
participants = paranoia.load_participants()
# Course storage (needs a Dartmouth sign-in; public datasets above need none)
from dartbrains_tools import storage

signin = storage.signin_button(); signin                       # in a marimo cell: never blocks
course = storage.course() if storage.connect(signin) else None  # else: public data

path = course.local_path("localizer/sub-S01/func/sub-S01_task-localizer_events.tsv")
storage.private().put("week3/betas.pkl", betas)                # pickle/npy/csv/json/nii.gz by extension
storage.private().get("week3/betas.pkl")
storage.assignment("midterm")                                  # NotReleased before release_at

@storage.cache                                                 # local -> shared cache -> private cache -> compute
def fit(subject): ...

# Outside marimo (scripts, the instructor uploading data):
storage.signin()                                               # device sign-in, cached afterwards
storage.course().sync("~/data/localizer", "localizer")         # instructors: course() is read-write

The notebook's # /// script block tells the library which grader, course and term it belongs to ([tool.grader], written by marimo-book's sync-deps); GRADER_SERVER, GRADER_COURSE, GRADER_TERM and GRADER_OFFERING_ID override it (the 0.2.x DARTBRAINS_* names still work).

Development

git clone https://github.com/ljchang/dartbrains-tools
cd dartbrains-tools
uv sync
uv run pytest
uv build

License

MIT. The parent course materials at dartbrains remain CC-BY-SA-4.0; this companion library is permissive so it can be reused in any downstream project.

Metadata

Release files for dartbrains-tools 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dartbrains-tools 0.3.1
File Size Uploaded Provenance
dartbrains_tools-0.3.1.tar.gz 70.5 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for dartbrains-tools 0.3.1
File Interpreter ABI Platform
dartbrains_tools-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 139.8 kB

Release files / dartbrains_tools-0.3.1.tar.gz

Download URL dartbrains_tools-0.3.1.tar.gz
Size 70.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9b96f389071d33b3eecab03da5098e2bffbb5df0a738c8fa80396b995e96ae53
BLAKE2b-256 checksum
How to use checksums
ce75974d052a66c03cd9ea63effe785d2585b13247666480d7b5bbef8ba9e636
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / dartbrains_tools-0.3.1-py3-none-any.whl

Download URL dartbrains_tools-0.3.1-py3-none-any.whl
Size 69.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b219c5647b39ef1aec58958943235f5e294f1467a31c48be57009471bdeb67b7
BLAKE2b-256 checksum
How to use checksums
f9a7905e768de6b32c3628ef84eeb9468e5276025e7daa7e2bf797a1c60d0359
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Security for dartbrains-tools 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for dartbrains_tools-0.3.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page