Package: gerrytools
gerrytoolsA companion toGerryChain, GerryTools is
a robust suite of geometric and algorithmic tools to analyze districting plans
and related data. GerryTools is actively developed and used by theMGGG Redistricting Laband our collaborators to prepare
accurate, precise, and clean information for our projects. It is distributed
under a3-Clause BSD License.InstallationUsingpip(recommended)To install GerryTools fromPyPi, run$ pip install gerrytoolsfrom the command line.UsageContentsGerryTools is split up into multiple sub-packages, each designed to simplify and
standardize redistricting workflows.gerrytools.datadeals with the retrieval and processing of data. Here, you
can find tools for grabbing decennial Census ('10 and '20), ACS 5-year ('12-'20),
ACS CVAP Special Tab ('12-'20), districtr portal, and 2020 decennial Census geometric
data. You can also find tools for moving CVAP data to other levels of geometry (e.g. prorating 2019 CVAP on 2019 Census tracts to 2020 blocks).gerrytools.geometryprovides facilities for dealing with geometric and
related data. There are tools for translating and evaluating GerryChainPartitions, performing fast geometric dissolutions, creating unit maps (e.g. 2020 blocks to 2020 VTDs), creatingdual graphs for GerryChain, and optimization algorithms for renaming districts.gerrytools.plottingcontains methods for generating extremely high-quality
Lab-standard data visualizations.gerrytools.scoringprovides a vast array of redistricting plan scores. These
can be used standaloneoras GerryChainupdaters.gerrychain.utilitieshas ease-of-use methods for renaming directories
containing shapefiles (which comes in handy more often than you'd think) and making
JSON objects out of Python objects (useful when trying to organize information
for many districting plans in a standard format).ExampleGerryTools is easy to use and is designed to simplify data- and redistricting-related
workflows. For example, let's say we want to analyze Alabama's citizen voting-age
population data on 2020 Census tracts. First, we can download the geometric data
for the state usinggerrytools.data.geometry20():fromgerrytools.dataimportgeometry20fromusimportstates# Retrieves Lab-processed and -cleaned geometry data, and writes it to file.geometry20(states.AL,"~/project/AL-tracts.zip",geometry="tract")Next, we can download cleaned citizen voting-age population (CVAP) data from the 2020 ACS special tabulation release:fromgerrytools.dataimportcvapfromusimportstates# A pandas DataFrame of 2020 CVAP data for the state of Alabama at the 2020 Census# tract level.data=cvap(states.AL,geometry="tract",year=2020)data.to_csv("~/project/AL-cvap.csv")Finally, we can merge the two datasets, attaching the CVAP demographic data to
the geometric data:importgeopandasasgpdimportpandasaspd# Import geometric and demographic data.geometric=gpd.read_file("~/project/AL-tracts.zip")demographic=pd.read_csv("~/project/AL-cvap.csv")# Merge. Note that the DataFrames have different unique identifier columns --- this# is intentional, and serves to differentiate datasets of varying geometric levels.merged=geometric.merge(demographic,left_on="GEOID20",right_on="TRACT20")And there we are — what once took hours of setup and parsing now takes less than a
minute.ContributingGerryTools is an active project, and has multiple contributors. If you'd like to
contribute, here are a few house rules:After cloning this repository, runsh setup.shto download and install
necessary git hooks and linting configurations.Follow thePEP8 style guide. After
installing the above git hooks, linting is performed before every push. PEP8 errors can be automatically corrected by runningautopep8 --in-place --aggressive -r gerrytoolson the command line from the root directory.Write tests.All changes, major or minor,mustbe accompanied by testing
code. Code and tests will be immediately reviewed by Lab maintainers.Test coverage must stayat leastthe same; this can be checked by runningpytest --cov=evaltoolsafter the tests are added totests/.Write documentation.All changes should be documented via docstrings,
and code should be repletely commented. It's much easier to decipher commented
code! Docstring documentation is compiled on every commit via git hooks.We look forward to your contributions!