Redistricting Analytics in Python
This repository (rdapy) re-implements the main analytics used in Dave’s Redistricting (DRA), ignoring a few DRA-specific aspects (in particular, the five [0-100] ratings). Unlike the analytics used in the app (dra-analytics) which are implememented in TypeScript, these are implemented in Python to make them easier to use outside of DRA.
There are both a PyPi package and a command-line interface.
Package
The analytics in the PyPi package are organized by area (in alphabetical order):
- Compactness: Various measures of compactness
- Equal: Population deviation
- Graph: Checks for contiguity & embeddedness
- Minority: Minority opportunity metrics
- Partisan: Various measures of partisan bias & responsiveness, as well as support for rank-vote graphs and seats-votes curves
- Splitting: County- & district-splitting and COI splitting
The samples
directory contains some simple examples of how to exercies these functions
and how to preprocess raw block-level data into the formats required by the analytics.
Command-Line Interface
The command-line interface uses the package and enables high-volume offline scoring. This toolchain uses DRA GeoJSON and graph files in the dra2020/vtd_data GitHub repository. as input data and scores each plan in an ensemble or collection on several dozen metrics described in Scores (Metrics) generating a CSV file with one row of scores per plan.
There are some housekeeping scripts to support this scoring:
- Extracting Contiguity Graphs: Extracts fully connected adjacency graphs from DRA GeoJSON files.
- Extracting Data: Extracts precinct data from DRA GeoJSON files for scoring.
- One-time Preprocessing: Pre-computes geographic baselines for the geographic advantage metric.
Installation
For installation instructions, see the README.
Questions
Email questions to feedback.