Skip to slides

NEUROTRAILBLAZERS · TEACHING MATERIALS

Python and Jupyter for Neuroscience

Reading version. Text reflows with your screen and zoom. Figures retain their available captions. Expand teaching notes for additional context and, where supplied, visual descriptions.

Contents · 19 slides
  1. 1. Python and Jupyter for Neuroscience
  2. 2. Learning Objectives
  3. 3. Capability Target
  4. 4. Concept Focus
  5. 5. Concept Focus (continued)
  6. 6. Core Workflow
  7. 7. Core Workflow (continued)
  8. 8. Run of Show (90 min)
  9. 9. Run of Show (90 min) (continued)
  10. 10. Misconceptions to Watch
  11. 11. A notebook is a repeatable chain
  12. 12. A tiny result you can verify by hand
  13. 13. Studio Activity
  14. 14. Activity Output Checklist
  15. 15. Assessment Rubric
  16. 16. Exit Ticket
  17. 17. References (Instructor)
  18. 18. Teaching Materials
  19. 19. Read, review, or teach

Slide 1 of 19

H01 electron microscopy with object segmentation and original 2 µm scale bar Nanoscale · Module 03

Python and Jupyter for Neuroscience

Teaching Deck

Human cortex · H01
Object segmentation over electron microscopy

H01 release · Lichtman Lab / Harvard & Connectomics at Google · CC BY 4.0
Shapson-Coe et al. (2024) · doi:10.1126/science.adk4858

Slide 2 of 19

Learning Objectives

Slide 3 of 19

Capability Target

Create a reproducible Jupyter notebook that ingests a connectomics dataset slice, performs one analysis, and exports documented outputs. Demonstrate familiarity with the core Python libraries used in connectomics research: CAVEclient, CloudVolume, NetworkX, pandas, and matplotlib.

Slide 4 of 19

Concept Focus

1) Python as the lingua franca of connectomics

Figure description and teaching notes

Further teaching detail from the module:
**Technical:** the connectomics ecosystem is built on Python. CAVEclient queries the CAVE database for synapses, segments, and annotations. CloudVolume accesses volumetric data (EM images, segmentation volumes). NetworkX and igraph construct and analyze circuit graphs. NumPy and pandas handle numerical and tabular data. Matplotlib and Plotly produce publication-quality visualizations. Familiarity with these libraries is not optional --- it is the baseline for participation.

Slide 5 of 19

Concept Focus (continued)

Slide 6 of 19

Core Workflow

Slide 7 of 19

Core Workflow (continued)

Slide 8 of 19

Run of Show (90 min)

Figure description and teaching notes

Block 1: Notebook anatomy (00:00-12:00)
Instructor script: "Open the sample notebook I have shared. Before we write any code, let's understand the structure." Walk through the five sections of a well-organized notebook:
Header: title, author, date, dataset version, materialization version.
Setup: imports and environment configuration.
Data loading: queries and schema validation.
Analysis: computation cells with markdown explanations.
Export: saving outputs with metadata.
Show a bad notebook (out-of-order cells, no markdown, hidden state) and a good notebook side by side. Ask: "Which one would you trust for a paper?"

Block 2: Environment setup and library tour (12:00-28:00)
Instructor script: "Let's set up our environment. Everyone run the first cell." Walk through installing and importing the core libraries:
`pip install caveclient cloud-volume networkx pandas matplotlib`
Demonstrate `pip freeze > requirements.txt` for version pinning.
Live demo of each library (2-3 minutes each):
CAVEclient: initialize client, query a synapse table, show resulting DataFrame.
CloudVolume: open a volume, download a small image cutout, display it.
NetworkX: build a tiny graph from 10 synapses, visualize it.
pandas: filter the synapse DataFrame by brain region, compute mean synapse count per cell type.
matplotlib: plot a histogram of synapse counts.

Block 3: Guided analysis sprint (28:00-50:00)
Instructor script: "Now you build. Your task: query synapses for a specific brain region, count connections between cell types, and plot the result. I will walk you through step by step, but you write the code."
Step-by-step guided coding:
Initialize CAVEclient and set materialization version (3 min).
Query synapse table filtered by brain region (5 min).
Group by pre/post cell type and count synapses (5 min).
Build a NetworkX graph from the grouped data (5 min).
Plot a bar chart of top 10 connections by synapse count (4 min).
Instructor circulates and helps with errors. Common issues: authentication tokens, version mismatches, column name typos.

Block 4: Visualization and export (50:00-65:00)
Instructor script: "A plot without labels is not a figure --- it is a sketch. Let's make yours publication-ready."
Learners add: axis labels, title, legend, caption in a markdown cell below the figure.
Export figure as PNG and SVG. Export data table as CSV with a header comment recording the query parameters and materialization version.
Demonstrate saving a metadata JSON file: `{"dataset": "...", "materialization_version": ..., "query_date": "...", "parameters": {...}}`.

Block 5: Clean rerun test (65:00-80:00)
Instructor script: "The moment of truth. Restart your kernel and run all cells. If anything breaks, that is a reproducibility bug --- fix it now."
Learners restart kernel and run all cells. Instructor helps debug common issues:
Cells that depend on variables defined out of order.
Cells that depend on interactive state (e.g., widget selections).
Missing imports that were run in a previous session.
Discuss: "Why does this matter? Because six months from now, you will need to regenerate this figure for a revision, and you will not remember what you did."

Block 6: Competency check and exit ticket (80:00-90:00)
Learners submit their completed notebook.
Instructor script: "Your notebook should pass three tests: (1) it runs from clean kernel without errors, (2) every output has a markdown explanation, (3) someone who has never seen your code can understand what it does and reproduce it."
Exit ticket: (1) link to submitted notebook; (2) one sentence describing the most useful library you learned today and why.

Slide 9 of 19

Run of Show (90 min) (continued)

Slide 10 of 19

Misconceptions to Watch

Slide 11 of 19

A notebook is a repeatable chain

Treat the saved result as the output of a declared process.

  1. Inputs

    Table + version + units

  2. Method

    Run code in a stated order

  3. Outputs

    Labeled result + parameters

  4. Clean rerun

    Restart; run all; compare

Discuss: Which link in this chain is missing from your notebook?

Illustrative teaching scenario; see this module’s lesson and worked example.

Figure description and teaching notes

Visual description and discussion guidance:
The sequence represents dependencies, not a guarantee of reproducibility. A clean rerun checks hidden interactive state. A picture alone does not record the inputs or code that produced it.

Slide 12 of 19

A tiny result you can verify by hand

Synthetic counts, not a biological finding. No account or download needed.

Input and code

counts = {"A": 4, "B": 1, "C": 0}
total = sum(counts.values())
print(total)
print(total / len(counts))

Interpret the output

Total: 5
Mean across A, B, C: 1.666…

Discuss: What changes if the zero-count row is omitted?

Synthetic example; arithmetic checked by scripts/check_visual_design.rb.

Figure description and teaching notes

Visual description and discussion guidance:
All three rows give total 5 and mean 5/3. Omitting the zero-count row keeps the total but changes the mean to 5/2 = 2.5. Declare the population represented by the denominator. These are synthetic teaching values.

Slide 13 of 19

Studio Activity

Scenario: Learners produce a complete, reproducible Jupyter notebook that queries a connectomics dataset, performs a descriptive analysis, and exports documented results. The work runs in four parts: setup and data loading (20 minutes), analysis (20 minutes), visualization and export (15 minutes), and a reproducibility check (5 minutes).

Slide 14 of 19

Activity Output Checklist

Slide 15 of 19

Assessment Rubric

Slide 16 of 19

Exit Ticket

Add one markdown cell documenting input version, processing steps, and output files. Then write a code cell that queries a synapse table and computes the mean number of synapses per neuron for one brain region.

Slide 17 of 19

References (Instructor)

Slide 18 of 19

Teaching Materials

Slide 19 of 19

Read, review, or teach

Read these slides as a page

Open the complete lesson

The reading version includes figure descriptions and discussion guidance.

Nanoscale text: CC BY 4.0. Scientific figures retain their individual credits.