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]"

# Optional: native-Python JIT for repeated cluster simulations
pip install "dartbrains-tools[simulation]"

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.bids — find and load files in a BIDS dataset (get_subjects, get_tr, get_file, load_events, load_confounds). The root is a folder or a storage mount such as storage.assignment("<slug>"); from a mount each file is downloaded the first time it is asked for, so a notebook fetches only the subjects and files it uses.
  • dartbrains_tools.mr_simulations — Bloch equation solvers, signal generators, HRF, and Plotly visualization helpers.
  • dartbrains_tools.simulations — seeded maximum-t experiments and four-connected cluster simulations. NumPy computes t statistics without unused p-values; optional Numba accelerates cluster labeling, with SciPy as the default fallback. These finite, synthetic 2D examples are teaching tools, not whole-brain inference.
  • dartbrains_tools.mr_widgets — 11 anywidgets for interactive teaching (PrecessionWidget, SpinEnsembleWidget, KSpaceWidget, ConvolutionWidget, EncodingWidget, CompassWidget, NetMagnetizationWidget, TransformCubeWidget, CostFunctionWidget, SmoothingWidget, and EqualizerWidget — a looping audio player whose graphic EQ is drawn as a filter's frequency response).
  • 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.4

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.4
File Size Uploaded Provenance
dartbrains_tools-0.3.4.tar.gz 84.3 kB With provenance Details

Built distribution (wheel)

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

Total release size: 166.3 kB

Release files / dartbrains_tools-0.3.4.tar.gz

Download URL dartbrains_tools-0.3.4.tar.gz
Size 84.3 kB
Tags Source
SHA-256 checksum
How to use checksums
dccd949662204d3f4236d1ed55f211a04f1d83f3c554a8ad9037144f40af81fc
BLAKE2b-256 checksum
How to use checksums
b13575c52c7f7bcdb9af577f4e3ebe452024147dee0d400ec8811d417632a3c0
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 Oct 19, 2026.

Transparency log

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

Download URL dartbrains_tools-0.3.4-py3-none-any.whl
Size 82.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e807accfb8195f48d38190dcc52930c4bd396859a5941f9eea3236a63c29c23f
BLAKE2b-256 checksum
How to use checksums
c7add50858202d7c86cbf89db41eb7ade34492d2db0683cf110d12b5724944f5
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 Oct 19, 2026.

Transparency log

Security for dartbrains-tools 0.3.4

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.4.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 Oct 19, 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