Instructor notes
At a glance
How it runs: live coding in Google Colab. Each section starts with a few theory slides, then Together (you live-code, attendees type along in their own copy of the notebook), Your turn (an exercise on their own) and Answer (you show it). Section 5 is a discussion, with no new code. The steps for each part are in the speaker notes of its slide (press S in the deck). The notes have all the code and every answer.
| # | Section | Min | Objective | Theory | Activity |
|---|---|---|---|---|---|
| Introduction and the story | 25 | Cholera, miasma vs water, Snow’s map | Setup | ||
| 1 | Location data | 35 | 1, 2 | Geospatial data, Tobler’s law, vector vs raster, CRSs | Where is pump 0? |
| Break | 10 | ||||
| 2 | Making maps | 25 | 3 | What makes a good map, visual variables | An interactive map |
| 3 | The nearest pump | 30 | 4 | Spatial relationships, spatial joins | Deaths within 100 metres |
| 4 | Pump catchments | 25 | 5 | Voronoi polygons, Snow’s own one, choropleths | A map of catchments |
| 5 | What the map cannot tell us | 20 | 6 | The evidence beyond the map, the MAUP | Question the map |
| Summary | 10 |
By the end, attendees can:
- Load location data into a GeoDataFrame, and describe how it differs from a pandas DataFrame.
- Explain what a coordinate reference system (CRS) is, and check and change the CRS of a dataset.
- Make a static map with a background map, and an interactive map.
- Join datasets by location, for example to find the nearest water pump to each address.
- Divide an area into catchments around points, and summarise data within each one.
- Describe what a map can and cannot tell us, using Snow’s map as an example.
The numbers
For checking attendees’ answers. tests/check_notes.py recalculates them from the data.
| Value | |
|---|---|
Addresses (rows in deaths) |
250 |
Deaths (sum of Count) |
489 |
| Most deaths at one address | 15, about 17 m from the Broad Street pump |
| Pumps | 8 (no attributes in the file; pump 0 is Broad Street) |
| Pump 0 in latitude, longitude | about 51.5133, -0.1367 (Broadwick Street) |
| Deaths nearest each pump | 0: 340, 1: 65, 4: 40, 5: 27, 7: 12, 2: 5, 3: 0, 6: 0 |
| Broad Street’s share | 340 of 489, 69.5% |
| Distance to nearest pump | mean about 105 m, maximum about 316 m |
| Deaths within 100 m of Broad Street | 196 (40.1%) |
Before you start
- Run
uv run python tests/check_notes.py(see the README). It runs the code in the notes and checks the numbers above. - Within a week of the course, run
uv run python tests/check_notes.py --notebook, uploadtests/colab_check.ipynbto Colab and run it. It checks the code works with the packages Colab has that week. - Check that johnsnow.rtwilson.com/data/SnowGIS_SHP.zip still downloads, and keep a backup copy in your own Google Drive. Share it only if the site is down on the day.
- Have the home page link ready to paste in the chat. Open the slides and the notes in separate tabs.
Ground rules
- Theory first, but briefly. The theory slides set up the code. Keep each one to a minute or two.
- Type along slowly. Attendees are new to geospatial, and some are new to pandas. Say each line out loud as you type it.
- Never debug live for long. If something fails, say so, paste the working code from the notes, and move on.
- The course is online: every Your turn is done on their own, and answers go in the chat. Read a few out.
- If running late, skip the optional extra (Snow’s map as a background) and the Extra steps in the exercises first, then shorten the section 5 discussion, not a coding section.
Introduction and the story (25 min)
Activity: setup: open the notebook from the home page, save a copy in Drive, run the two setup cells.
Checkpoints: by 5 min housekeeping, mission and objectives; by 15 the story; by 25 everyone has the data.
Key messages
- Cholera killed fast, and nobody knew the cause.
- Miasma and water predict different patterns on a map: spread out, or clustered round a source. That is why a map can help.
- Our data is Snow’s map, traced into modern software.
Don’t forget
- Pose the mission (“find the source, using a map”) and leave it hanging.
- On Snow’s map, let people say “they cluster” before you point to Broad Street.
Watch out for: Colab’s “not authored by Google” warning: click Run anyway. If the download fails for everyone, share the backup copy and have them upload it with the folder icon.
1. Location data (35 min)
Theory: what makes data geospatial; Tobler’s first law; vector vs raster; points, lines and polygons; coordinate reference systems (geographic vs projected, distortion, EPSG codes).
Together: read both files; head(), type(), len(), Count.sum(), value_counts(); add pump_id; deaths.plot(); .crs; set_crs(27700, allow_override=True); to_crs(4326); distance in both CRSs.
Your turn: Where is pump 0? Answer: about 51.5133, -0.1367, Broadwick Street (Broad Street in 1854).
Checkpoints: by 10 min theory; by 20 data loaded and explored; by 27 CRS done; by 32 Your turn; finish at 35.
Key messages
- Geospatial data is where plus what. Near things tend to be alike, so clusters need explaining.
- Vector stores shapes, raster stores a grid. Today is vector.
- A GeoDataFrame is a DataFrame with a geometry column. All of pandas still works.
- A CRS says what the numbers mean. Every flat map distorts something.
set_crs()labels,to_crs()converts. - Measure distances in metres (British National Grid), not degrees.
Don’t forget
- Ask “what are these numbers?” before showing
.crs. - Show the warning geopandas gives when measuring in degrees.
- Point out that
POINT (x y)puts longitude first.
Watch out for: latitude and longitude swapped in the web map (they land in the Indian Ocean). People expecting the pumps to have names: the file has none, which is why we add pump_id.
Break (10 min)
About 1 hour in. Colab can disconnect if left idle. If it does, attendees click Runtime → Run before in the first cell of section 2, or rerun the notebook from the top.
2. Making maps (25 min)
Theory: what makes a good map (data, context, key, credit); visual variables (size, colour, shape), compared with Snow’s map.
Together: build the static map a step at a time (deaths, size by Count, pumps with ax=ax), add a background map with contextily, then explore().
Your turn: An interactive map. Answer: the address with 15 deaths is about 17 m from the Broad Street pump.
Checkpoints: by 5 min theory; by 12 the layered map; by 15 the background map; by 18 explore(); by 23 Your turn; finish at 25.
Key messages
- Maps are built in layers.
ax=axdraws on the same map. - Size and colour show values from the table.
.plot()for static maps,.explore()for interactive ones.- Keep the map attribution.
Don’t forget
- Compare the sized dots to Snow’s stacked bars.
- If time, show Snow’s original map as the background (the optional extra in the notes). It is a raster, which links back to section 1.
Watch out for: a background map in the wrong place, usually because crs=deaths.crs is missing. People trying other cx.providers: OpenStreetMap’s own tiles return “Access blocked” images to contextily, and CartoDB now needs an API key.
3. The nearest pump (30 min)
Theory: spatial relationships (intersects, contains, distance); joining by a column vs by location vs to the nearest.
Together: sjoin_nearest(pumps, distance_col="distance"); explain the new columns; groupby("pump_id")["Count"].sum(); percentages; distance.describe(); map coloured by pump_id with categorical=True.
Your turn: Deaths within 100 metres. Answer: 196 deaths, 40%.
Checkpoints: by 5 min theory; by 12 the join; by 20 deaths per pump and the map; by 27 Your turn; finish at 30.
Key messages
- A spatial join links datasets that share nothing but location.
- After the join, it is a normal table: use pandas.
- 340 of 489 deaths (70%) were nearest the Broad Street pump.
- Straight-line distance is not walking distance (back to this in section 5).
Don’t forget
- Explain
groupby()slowly: some attendees will not have used pandas. - Point out that pumps 3 and 6 are missing from the groupby result, not zero.
Watch out for: index_right confusing people: it is the row of the pump, added by every spatial join.
4. Pump catchments (25 min)
Theory: Voronoi polygons; Snow’s own dotted line, by walking distance; choropleths, and counts vs rates.
Together: the study area box, voronoi_polygons(), label with sjoin(predicate="contains"), clip(), plot; count deaths with sjoin().
Your turn: A map of catchments. Answer: pumps 3 and 6 had no deaths.
Checkpoints: by 5 min theory; by 13 the catchments; by 17 deaths per catchment; by 22 Your turn; finish at 25.
Key messages
- Each Voronoi polygon is the area nearest one pump. Snow drew an early one.
- The polygons are not in the order of the pumps, so a spatial join labels them.
- The totals match section 3, by definition. The polygons show the areas.
- Map rates rather than counts where you can.
Don’t forget
- Ask “why are the totals the same?” and wait for answers in the chat.
Watch out for: an AttributeError for voronoi_polygons: the geopandas version is older than 1.0. The install cell asks for 1.0 or later, so check it ran. Running the exercise’s catchments["deaths"] line before the totals line.
5. What the map cannot tell us (20 min)
Theory: the evidence beyond the map (straight lines, the brewery, the Hampstead widow, the first case); the limits of the data; the modifiable areal unit problem.
Your turn: Question the map, in the chat.
Checkpoints: by 7 min the evidence; by 12 limits and the MAUP; by 17 Your turn; finish at 20.
Key messages
- A map shows where deaths were recorded, not why they happened.
- Snow’s case was persuasive because the map fitted with other evidence.
- The outbreak was already slowing when the handle was removed.
- The areas you count in can change the pattern.
Don’t forget
- Draw out the point about rates: without the population at each address, a crowded street looks worse.
- Link to today: health data is released for areas, not addresses, and the boundaries change the pattern.
If running late: take one or two answers from the chat, not more.
Summary (10 min)
- Go through “What you can now do”.
- Go back to the six objectives and tick them off.
- Point to “Where next?”, and remind people the notes have everything.
- Ask people to fill in the feedback form.