Summary and Setup

Case studies bring together the skills from the other modules (finding and collecting data, analysis and visualization) to answer one real social science question from start to finish. Each case study explains the background and the methods, then lets you work through the analysis yourself, in Google Colab or in QGIS.

Case study Question Tools
Food Deserts Where do people have low income and live far from a supermarket? How does the USDA measure this, and can we rebuild its analysis from open data? Python notebooks (Colab)
Grocery Access (two parts) How would a team map grocery stores in the field, and how far must people travel to a supermarket along the road network in Lafayette and West Lafayette, Indiana? QField (demonstration), QGIS

More case studies will be added over time.

Prerequisite

Prerequisites

  • A Google account, to open the notebooks in Google Colab
  • A free Census API key for the Expert notebook (see Setup below)
  • QGIS installed on your computer, for the grocery access case study (see Setup below)
  • Basic Python and pandas. The Data Collection module’s Census notebooks are good preparation: they cover census tracts, GEOIDs and joining tables to maps.
  • For the grocery access case study: basic familiarity with QGIS, for example from the Foundations module’s Getting Started with QGIS episode

This module is part of Enabling the Geospatial Turn in the Social Sciences, a set of training modules developed at Purdue University with support from the National Science Foundation.

The food desert case study runs in Google Colab, a free service that runs Jupyter notebooks in your browser. Nothing needs to be installed on your computer, and every dataset is fetched automatically by the notebooks themselves.

The grocery access case study uses QGIS, a free desktop GIS. See the last section of this page.

Data Sets


There is nothing to download before class. Both food desert notebooks read their data directly from the source URLs while they run:

  • Census tract boundaries (TIGER/Line shapefiles) are read straight from the U.S. Census Bureau.
  • The USDA Food Access Research Atlas spreadsheet is read straight from the USDA ERS website.
  • The Expert notebook additionally fetches data live from the Census API and OpenStreetMap.

The only thing you need is a stable internet connection. The USDA spreadsheet is large, so the cell that reads it can take a couple of minutes on slower connections. This is normal.

The Expert notebook needs a free Census API key, and every learner needs their own. The Census API refuses any request without a key.

  1. Request a key at https://api.census.gov/data/key_signup.html. It arrives by email within a few minutes.
  2. Click the activation link in that email. The key does not work until you do.
  3. In the Expert notebook, paste the key between the quotes in API_KEY = "" in the setup section.

Treat the key like a password: do not post it online or leave it in a notebook you share.

Software Setup


Discussion

Details

The recommended way to follow this lesson is Google Colab, which requires only a web browser and a Google account. If you prefer working on your own machine, a local Jupyter installation works too. Instructions for both are in the dropdowns below.

  1. Make sure you are signed in to a Google account.
  2. Click one of the notebook links on the lesson page (for example the Beginner notebook). It opens directly in Colab from GitHub.
  3. Colab opens the notebook in read-only mode. To run and edit it, save your own copy first: File > Save a copy in Drive. Your copy lives in your Google Drive and keeps any changes you make.
  4. Run cells one at a time with Shift + Enter, or run everything with Runtime > Run all.
  5. The first time you run a notebook, Colab may show a warning that the notebook was not authored by Google. Click Run anyway.
  6. All required Python libraries (pandas, geopandas, matplotlib) come pre-installed on Colab. If a notebook ever needs an extra package, the install command is included in the notebook itself.
  7. Colab disconnects idle sessions after a while. If that happens, reconnect and rerun the cells from the top. Files created during a session (like saved GeoPackages) disappear when the session ends, so download anything you want to keep via the file browser in the left sidebar.

If you would rather run the notebooks on your own computer:

  1. Install Python 3.10 or newer, ideally through Miniconda or Anaconda.
  2. Install the required libraries:

BASH

pip install jupyterlab pandas geopandas matplotlib openpyxl scipy requests
  1. Download the two notebooks from the notebooks folder of this lesson’s repository.
  2. Start JupyterLab with jupyter lab, open a notebook, and run cells with Shift + Enter.

Grocery access case study: QGIS


Install QGIS (the free Long Term Release) by following the central Setup page of the Foundations module. If you are new to QGIS, its Getting Started with QGIS episode introduces the interface.

Loading the lesson data in QGIS

Part 2 reads its three data files straight from this lesson’s repository, so there is nothing to download:

  1. Layer > Add Layer > Add Vector Layer
  2. Source Type: Protocol: HTTP(S), cloud, etc.
  3. Paste the address given in the episode into URI, then click Add

QField (optional)

Part 1 is a demonstration, so QField is not required. To try field data collection yourself:

  1. Install QField from https://qfield.org/ (Android and iOS app stores, or Windows, macOS and Linux).
  2. In QGIS, install the QFieldSync plugin: Plugins > Manage and Install Plugins, search for QFieldSync, and click Install Plugin.

Troubleshooting

Problem Fix
QGIS will not open on macOS Right-click the app, choose Open, then confirm
A layer loaded from a web address shows nothing Right-click the layer and choose Zoom to Layer; check that the address was pasted completely
Network analysis costs look tiny (such as 0.04) Set the project coordinate system to EPSG:26916 (bottom-right corner of the QGIS window)