gerrytools 1.2.0__tar.gz → 1.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gerrytools-1.2.1/PKG-INFO +181 -0
- gerrytools-1.2.1/README.md +147 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/ben/binary_ensemble.py +2 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/ben/parse.py +2 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/ben/reben.py +4 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/mgrp/run_container.py +1 -0
- gerrytools-1.2.1/gerrytools.egg-info/PKG-INFO +181 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools.egg-info/SOURCES.txt +6 -2
- gerrytools-1.2.1/gerrytools.egg-info/requires.txt +24 -0
- gerrytools-1.2.1/pyproject.toml +68 -0
- gerrytools-1.2.1/tests/test_data.py +611 -0
- gerrytools-1.2.1/tests/test_geometry.py +168 -0
- gerrytools-1.2.1/tests/test_plotting.py +67 -0
- gerrytools-1.2.1/tests/test_scoring.py +319 -0
- gerrytools-1.2.0/PKG-INFO +0 -165
- gerrytools-1.2.0/README.md +0 -153
- gerrytools-1.2.0/gerrytools.egg-info/PKG-INFO +0 -165
- gerrytools-1.2.0/gerrytools.egg-info/requires.txt +0 -28
- gerrytools-1.2.0/setup.py +0 -55
- {gerrytools-1.2.0 → gerrytools-1.2.1}/LICENSE +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/MANIFEST.in +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/__init__.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/ben/__init__.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/ben/docker_manager.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/data/AssignmentCompressor.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/data/URLs.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/data/__init__.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/data/acs.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/data/census.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/data/estimatecvap.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/data/fetch.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/data/geometries.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/data/remap.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/geometry/__init__.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/geometry/compactness.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/geometry/dataframe.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/geometry/dissolve.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/geometry/dualgraph.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/geometry/optimize.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/geometry/unitmap.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/geometry/updater.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/mgrp/__init__.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/mgrp/runners/__init__.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/mgrp/runners/forest.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/mgrp/runners/recom.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/mgrp/runners/smc.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/plotting/__init__.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/plotting/annotation.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/plotting/bins.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/plotting/boxplot.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/plotting/choropleth.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/plotting/colors.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/plotting/districtnumbers.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/plotting/drawgraph.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/plotting/drawplan.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/plotting/gifs.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/plotting/histogram.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/plotting/latexcolors.json +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/plotting/multidimensional.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/plotting/scatterplot.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/plotting/sealevel.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/plotting/utils.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/plotting/violin.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/scoring/__init__.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/scoring/contiguity.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/scoring/demographics.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/scoring/partisan.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/scoring/population.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/scoring/scores.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/scoring/splits.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/scoring/types.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/utilities/JSON.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/utilities/__init__.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools/utilities/rename.py +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools.egg-info/dependency_links.txt +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/gerrytools.egg-info/top_level.txt +0 -0
- {gerrytools-1.2.0 → gerrytools-1.2.1}/setup.cfg +0 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gerrytools
|
|
3
|
+
Version: 1.2.1
|
|
4
|
+
Summary: Tools for processing and visualizing districting plans.
|
|
5
|
+
Author-email: MGGG Redistricting Lab <engineering@mggg.org>
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: pandas>=2.3.2
|
|
11
|
+
Requires-Dist: scipy>=1.16.1
|
|
12
|
+
Requires-Dist: networkx>=3.5.0
|
|
13
|
+
Requires-Dist: geopandas>=1.1.1
|
|
14
|
+
Requires-Dist: Shapely>=2.0.0
|
|
15
|
+
Requires-Dist: matplotlib>=3.10.6
|
|
16
|
+
Requires-Dist: gerrychain>=0.3.2
|
|
17
|
+
Requires-Dist: sortedcontainers
|
|
18
|
+
Requires-Dist: jsonlines>=4.0.0
|
|
19
|
+
Requires-Dist: imageio>=2.37.0
|
|
20
|
+
Requires-Dist: us>=3.2.0
|
|
21
|
+
Requires-Dist: pydantic>=2.11.7
|
|
22
|
+
Requires-Dist: censusdata>=1.15.post1
|
|
23
|
+
Requires-Dist: seaborn>=0.13.2
|
|
24
|
+
Requires-Dist: numpy>=2.3.2
|
|
25
|
+
Requires-Dist: maup>=2.0.3
|
|
26
|
+
Requires-Dist: gurobipy>=12.0.3
|
|
27
|
+
Requires-Dist: opencv-python-headless>=4.11.0.86
|
|
28
|
+
Provides-Extra: docs
|
|
29
|
+
Requires-Dist: myst-parser>=4.0.1; extra == "docs"
|
|
30
|
+
Requires-Dist: sphinx>=8.2.3; extra == "docs"
|
|
31
|
+
Requires-Dist: sphinx-copybutton>=0.5.2; extra == "docs"
|
|
32
|
+
Requires-Dist: sphinx-rtd-theme>=3.0.2; extra == "docs"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# gerrytools
|
|
36
|
+
|
|
37
|
+
[](https://dl.circleci.com/status-badge/redirect/gh/mggg/gerrytools/tree/main)
|
|
38
|
+
[](https://codecov.io/gh/mggg/gerrytools)
|
|
39
|
+
[](https://badge.fury.io/py/gerrytools)
|
|
40
|
+
[](https://mggg.github.io/gerrytools/)
|
|
41
|
+
[](https://mggg.org)
|
|
42
|
+
[](https://github.com/psf/black)
|
|
43
|
+
[](https://pycqa.github.io/isort/)
|
|
44
|
+
|
|
45
|
+
A companion to [GerryChain](https://github.com/mggg/GerryChain), GerryTools is a robust suite of
|
|
46
|
+
geometric and algorithmic tools to analyze districting plans and related data. GerryTools is
|
|
47
|
+
actively developed and used by the [MGGG Redistricting Lab](https://mggg.org) and our collaborators
|
|
48
|
+
to prepare accurate, precise, and clean information for our projects. It is distributed under a
|
|
49
|
+
[3-Clause BSD License](https://opensource.org/licenses/BSD-3-Clause).
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
### Using `pip` (recommended)
|
|
54
|
+
|
|
55
|
+
To install GerryTools from [PyPi](https://pypi.org/project/gerrytools/), run
|
|
56
|
+
|
|
57
|
+
```console
|
|
58
|
+
pip install gerrytools
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
from the command line. if you would like to use the `mgrp` and `ben` modules as well, you can invoke
|
|
62
|
+
|
|
63
|
+
```console
|
|
64
|
+
pip install "gerrytools[mgrp]"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
you will need to make sure that [Docker Desktop](https://www.docker.com/get-started/) is installed
|
|
68
|
+
on your machine an updated to version >= 4.28.0. For more information on getting this set up, please
|
|
69
|
+
see [our documentation page](https://gerrytools.readthedocs.io/en/latest/topics/docker/)
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
GerryTools is split up into multiple sub-packages, each designed to simplify and standardize
|
|
74
|
+
redistricting workflows.
|
|
75
|
+
|
|
76
|
+
- **`gerrytools.ben`** BEN (binary-ensemble) is our general purpose compression algorithm for
|
|
77
|
+
working with ensembles of plans. In general, the ben algorithm can improve the storage of an
|
|
78
|
+
ensemble of plans by an order of magnitude. When combined with the special XBEN (eXtreme BEN)
|
|
79
|
+
portion of the algorithm, many ensembles of plans can be compressed small enough to fit into an
|
|
80
|
+
email (~25Mb).
|
|
81
|
+
|
|
82
|
+
- **`gerrytools.data`** deals with the retrieval and processing of data. Here, you can find tools
|
|
83
|
+
for grabbing decennial Census ('10 and '20), ACS 5-year ('12-'20), ACS CVAP Special Tab ('12-'20),
|
|
84
|
+
districtr portal, and 2020 decennial Census geometric data. You can also find tools for moving
|
|
85
|
+
CVAP data to other levels of geometry (e.g. prorating 2019 CVAP on 2019 Census tracts to 2020
|
|
86
|
+
blocks).
|
|
87
|
+
|
|
88
|
+
- **`gerrytools.geometry`** provides facilities for dealing with geometric and related data. There
|
|
89
|
+
are tools for translating and evaluating GerryChain
|
|
90
|
+
[`Partition`](https://mggg.github.io/GerryChain/api.html#module-gerrychain.partition)s, performing
|
|
91
|
+
fast geometric dissolutions, creating unit maps (e.g. 2020 blocks to 2020 VTDs), creating
|
|
92
|
+
[dual graphs for GerryChain](https://mggg.github.io/GerryChain/api.html#adjacency-graphs), and
|
|
93
|
+
optimization algorithms for renaming districts.
|
|
94
|
+
|
|
95
|
+
- **`gerrytools.mgrp`** this module uses a Docker container to allow users to access several
|
|
96
|
+
ensemble methods for generating districting plans on a state. In particular our Rust
|
|
97
|
+
implementation of our `gerrychain` library, `frcw`, the Julia implementation of
|
|
98
|
+
[Forest Recom](https://arxiv.org/pdf/2008.08054.pdf), and the R/C++ implementation of
|
|
99
|
+
[Sequential Monte Carlo (SMC)](https://github.com/alarm-redist/redist) are available through this
|
|
100
|
+
module.
|
|
101
|
+
|
|
102
|
+
- **`gerrytools.plotting`** contains methods for generating extremely high-quality Lab-standard data
|
|
103
|
+
visualizations.
|
|
104
|
+
|
|
105
|
+
- **`gerrytools.scoring`** provides a vast array of redistricting plan scores. These can be used
|
|
106
|
+
standalone _or_ as GerryChain
|
|
107
|
+
[updaters](https://mggg.github.io/GerryChain/api.html#module-gerrychain.updaters).
|
|
108
|
+
|
|
109
|
+
- **`gerrychain.utilities`** has ease-of-use methods for renaming directories containing shapefiles
|
|
110
|
+
(which comes in handy more often than you'd think) and making JSON objects out of Python objects
|
|
111
|
+
(useful when trying to organize information for many districting plans in a standard format).
|
|
112
|
+
|
|
113
|
+
<!-- ### Example
|
|
114
|
+
|
|
115
|
+
GerryTools is easy to use and is designed to simplify data- and redistricting-related
|
|
116
|
+
workflows. For example, let's say we want to analyze Alabama's citizen voting-age
|
|
117
|
+
population data on 2020 Census tracts. First, we can download the geometric data
|
|
118
|
+
for the state using `gerrytools.data.geometry20()`:
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from gerrytools.data import geometry20
|
|
122
|
+
from us import states
|
|
123
|
+
|
|
124
|
+
# Retrieves Lab-processed and -cleaned geometry data, and writes it to file.
|
|
125
|
+
geometry20(states.AL, "~/project/AL-tracts.zip", geometry="tract")
|
|
126
|
+
```
|
|
127
|
+
Next, we can download cleaned citizen voting-age population (CVAP) data from the 2020 ACS special tabulation release:
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from gerrytools.data import cvap
|
|
131
|
+
from us import states
|
|
132
|
+
|
|
133
|
+
# A pandas DataFrame of 2020 CVAP data for the state of Alabama at the 2020 Census
|
|
134
|
+
# tract level.
|
|
135
|
+
data = cvap(states.AL, geometry="tract", year=2020)
|
|
136
|
+
data.to_csv("~/project/AL-cvap.csv")
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Finally, we can merge the two datasets, attaching the CVAP demographic data to
|
|
140
|
+
the geometric data:
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
import geopandas as gpd
|
|
144
|
+
import pandas as pd
|
|
145
|
+
|
|
146
|
+
# Import geometric and demographic data.
|
|
147
|
+
geometric = gpd.read_file("~/project/AL-tracts.zip")
|
|
148
|
+
demographic = pd.read_csv("~/project/AL-cvap.csv")
|
|
149
|
+
|
|
150
|
+
# Merge. Note that the DataFrames have different unique identifier columns --- this
|
|
151
|
+
# is intentional, and serves to differentiate datasets of varying geometric levels.
|
|
152
|
+
merged = geometric.merge(demographic, left_on="GEOID20", right_on="TRACT20")
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
And there we are — what once took hours of setup and parsing now takes less than a
|
|
156
|
+
minute. -->
|
|
157
|
+
|
|
158
|
+
## Contributing
|
|
159
|
+
|
|
160
|
+
GerryTools is an active project, and has multiple contributors. If you'd like to contribute, here
|
|
161
|
+
are a few house rules:
|
|
162
|
+
|
|
163
|
+
1. After cloning this repository, run `sh setup.sh` to download and install necessary git hooks and
|
|
164
|
+
linting configurations.
|
|
165
|
+
|
|
166
|
+
1. **Follow the [PEP8 style guide](https://peps.python.org/pep-0008/)**. After installing the above
|
|
167
|
+
git hooks, linting is performed before every push. PEP8 errors can be automatically corrected by
|
|
168
|
+
running `autopep8 --in-place --aggressive -r gerrytools` on the command line from the root
|
|
169
|
+
directory.
|
|
170
|
+
|
|
171
|
+
1. **Write tests.** All changes, major or minor, **must** be accompanied by testing code. Code and
|
|
172
|
+
tests will be immediately reviewed by Lab maintainers.
|
|
173
|
+
|
|
174
|
+
1. Test coverage must stay **at least** the same; this can be checked by running
|
|
175
|
+
`pytest --cov=evaltools` after the tests are added to `tests/`.
|
|
176
|
+
|
|
177
|
+
1. **Write documentation.** All changes should be documented via docstrings, and code should be
|
|
178
|
+
repletely commented. It's much easier to decipher commented code! Docstring documentation is
|
|
179
|
+
compiled on every commit via git hooks.
|
|
180
|
+
|
|
181
|
+
We look forward to your contributions!
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# gerrytools
|
|
2
|
+
|
|
3
|
+
[](https://dl.circleci.com/status-badge/redirect/gh/mggg/gerrytools/tree/main)
|
|
4
|
+
[](https://codecov.io/gh/mggg/gerrytools)
|
|
5
|
+
[](https://badge.fury.io/py/gerrytools)
|
|
6
|
+
[](https://mggg.github.io/gerrytools/)
|
|
7
|
+
[](https://mggg.org)
|
|
8
|
+
[](https://github.com/psf/black)
|
|
9
|
+
[](https://pycqa.github.io/isort/)
|
|
10
|
+
|
|
11
|
+
A companion to [GerryChain](https://github.com/mggg/GerryChain), GerryTools is a robust suite of
|
|
12
|
+
geometric and algorithmic tools to analyze districting plans and related data. GerryTools is
|
|
13
|
+
actively developed and used by the [MGGG Redistricting Lab](https://mggg.org) and our collaborators
|
|
14
|
+
to prepare accurate, precise, and clean information for our projects. It is distributed under a
|
|
15
|
+
[3-Clause BSD License](https://opensource.org/licenses/BSD-3-Clause).
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
### Using `pip` (recommended)
|
|
20
|
+
|
|
21
|
+
To install GerryTools from [PyPi](https://pypi.org/project/gerrytools/), run
|
|
22
|
+
|
|
23
|
+
```console
|
|
24
|
+
pip install gerrytools
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
from the command line. if you would like to use the `mgrp` and `ben` modules as well, you can invoke
|
|
28
|
+
|
|
29
|
+
```console
|
|
30
|
+
pip install "gerrytools[mgrp]"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
you will need to make sure that [Docker Desktop](https://www.docker.com/get-started/) is installed
|
|
34
|
+
on your machine an updated to version >= 4.28.0. For more information on getting this set up, please
|
|
35
|
+
see [our documentation page](https://gerrytools.readthedocs.io/en/latest/topics/docker/)
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
GerryTools is split up into multiple sub-packages, each designed to simplify and standardize
|
|
40
|
+
redistricting workflows.
|
|
41
|
+
|
|
42
|
+
- **`gerrytools.ben`** BEN (binary-ensemble) is our general purpose compression algorithm for
|
|
43
|
+
working with ensembles of plans. In general, the ben algorithm can improve the storage of an
|
|
44
|
+
ensemble of plans by an order of magnitude. When combined with the special XBEN (eXtreme BEN)
|
|
45
|
+
portion of the algorithm, many ensembles of plans can be compressed small enough to fit into an
|
|
46
|
+
email (~25Mb).
|
|
47
|
+
|
|
48
|
+
- **`gerrytools.data`** deals with the retrieval and processing of data. Here, you can find tools
|
|
49
|
+
for grabbing decennial Census ('10 and '20), ACS 5-year ('12-'20), ACS CVAP Special Tab ('12-'20),
|
|
50
|
+
districtr portal, and 2020 decennial Census geometric data. You can also find tools for moving
|
|
51
|
+
CVAP data to other levels of geometry (e.g. prorating 2019 CVAP on 2019 Census tracts to 2020
|
|
52
|
+
blocks).
|
|
53
|
+
|
|
54
|
+
- **`gerrytools.geometry`** provides facilities for dealing with geometric and related data. There
|
|
55
|
+
are tools for translating and evaluating GerryChain
|
|
56
|
+
[`Partition`](https://mggg.github.io/GerryChain/api.html#module-gerrychain.partition)s, performing
|
|
57
|
+
fast geometric dissolutions, creating unit maps (e.g. 2020 blocks to 2020 VTDs), creating
|
|
58
|
+
[dual graphs for GerryChain](https://mggg.github.io/GerryChain/api.html#adjacency-graphs), and
|
|
59
|
+
optimization algorithms for renaming districts.
|
|
60
|
+
|
|
61
|
+
- **`gerrytools.mgrp`** this module uses a Docker container to allow users to access several
|
|
62
|
+
ensemble methods for generating districting plans on a state. In particular our Rust
|
|
63
|
+
implementation of our `gerrychain` library, `frcw`, the Julia implementation of
|
|
64
|
+
[Forest Recom](https://arxiv.org/pdf/2008.08054.pdf), and the R/C++ implementation of
|
|
65
|
+
[Sequential Monte Carlo (SMC)](https://github.com/alarm-redist/redist) are available through this
|
|
66
|
+
module.
|
|
67
|
+
|
|
68
|
+
- **`gerrytools.plotting`** contains methods for generating extremely high-quality Lab-standard data
|
|
69
|
+
visualizations.
|
|
70
|
+
|
|
71
|
+
- **`gerrytools.scoring`** provides a vast array of redistricting plan scores. These can be used
|
|
72
|
+
standalone _or_ as GerryChain
|
|
73
|
+
[updaters](https://mggg.github.io/GerryChain/api.html#module-gerrychain.updaters).
|
|
74
|
+
|
|
75
|
+
- **`gerrychain.utilities`** has ease-of-use methods for renaming directories containing shapefiles
|
|
76
|
+
(which comes in handy more often than you'd think) and making JSON objects out of Python objects
|
|
77
|
+
(useful when trying to organize information for many districting plans in a standard format).
|
|
78
|
+
|
|
79
|
+
<!-- ### Example
|
|
80
|
+
|
|
81
|
+
GerryTools is easy to use and is designed to simplify data- and redistricting-related
|
|
82
|
+
workflows. For example, let's say we want to analyze Alabama's citizen voting-age
|
|
83
|
+
population data on 2020 Census tracts. First, we can download the geometric data
|
|
84
|
+
for the state using `gerrytools.data.geometry20()`:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from gerrytools.data import geometry20
|
|
88
|
+
from us import states
|
|
89
|
+
|
|
90
|
+
# Retrieves Lab-processed and -cleaned geometry data, and writes it to file.
|
|
91
|
+
geometry20(states.AL, "~/project/AL-tracts.zip", geometry="tract")
|
|
92
|
+
```
|
|
93
|
+
Next, we can download cleaned citizen voting-age population (CVAP) data from the 2020 ACS special tabulation release:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from gerrytools.data import cvap
|
|
97
|
+
from us import states
|
|
98
|
+
|
|
99
|
+
# A pandas DataFrame of 2020 CVAP data for the state of Alabama at the 2020 Census
|
|
100
|
+
# tract level.
|
|
101
|
+
data = cvap(states.AL, geometry="tract", year=2020)
|
|
102
|
+
data.to_csv("~/project/AL-cvap.csv")
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Finally, we can merge the two datasets, attaching the CVAP demographic data to
|
|
106
|
+
the geometric data:
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
import geopandas as gpd
|
|
110
|
+
import pandas as pd
|
|
111
|
+
|
|
112
|
+
# Import geometric and demographic data.
|
|
113
|
+
geometric = gpd.read_file("~/project/AL-tracts.zip")
|
|
114
|
+
demographic = pd.read_csv("~/project/AL-cvap.csv")
|
|
115
|
+
|
|
116
|
+
# Merge. Note that the DataFrames have different unique identifier columns --- this
|
|
117
|
+
# is intentional, and serves to differentiate datasets of varying geometric levels.
|
|
118
|
+
merged = geometric.merge(demographic, left_on="GEOID20", right_on="TRACT20")
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
And there we are — what once took hours of setup and parsing now takes less than a
|
|
122
|
+
minute. -->
|
|
123
|
+
|
|
124
|
+
## Contributing
|
|
125
|
+
|
|
126
|
+
GerryTools is an active project, and has multiple contributors. If you'd like to contribute, here
|
|
127
|
+
are a few house rules:
|
|
128
|
+
|
|
129
|
+
1. After cloning this repository, run `sh setup.sh` to download and install necessary git hooks and
|
|
130
|
+
linting configurations.
|
|
131
|
+
|
|
132
|
+
1. **Follow the [PEP8 style guide](https://peps.python.org/pep-0008/)**. After installing the above
|
|
133
|
+
git hooks, linting is performed before every push. PEP8 errors can be automatically corrected by
|
|
134
|
+
running `autopep8 --in-place --aggressive -r gerrytools` on the command line from the root
|
|
135
|
+
directory.
|
|
136
|
+
|
|
137
|
+
1. **Write tests.** All changes, major or minor, **must** be accompanied by testing code. Code and
|
|
138
|
+
tests will be immediately reviewed by Lab maintainers.
|
|
139
|
+
|
|
140
|
+
1. Test coverage must stay **at least** the same; this can be checked by running
|
|
141
|
+
`pytest --cov=evaltools` after the tests are added to `tests/`.
|
|
142
|
+
|
|
143
|
+
1. **Write documentation.** All changes should be documented via docstrings, and code should be
|
|
144
|
+
repletely commented. It's much easier to decipher commented code! Docstring documentation is
|
|
145
|
+
compiled on every commit via git hooks.
|
|
146
|
+
|
|
147
|
+
We look forward to your contributions!
|
|
@@ -62,6 +62,7 @@ def ben(
|
|
|
62
62
|
"auto_remove": True,
|
|
63
63
|
"tty": True,
|
|
64
64
|
"stdin_open": True,
|
|
65
|
+
"network_mode": "none",
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
if input_parent_path == output_parent_path:
|
|
@@ -180,6 +181,7 @@ def ben_replay(
|
|
|
180
181
|
"auto_remove": True,
|
|
181
182
|
"tty": True,
|
|
182
183
|
"stdin_open": True,
|
|
184
|
+
"network_mode": "none",
|
|
183
185
|
}
|
|
184
186
|
|
|
185
187
|
config_args["volumes"] = {
|
|
@@ -85,6 +85,7 @@ def msms_parse(
|
|
|
85
85
|
"auto_remove": True,
|
|
86
86
|
"tty": True,
|
|
87
87
|
"stdin_open": True,
|
|
88
|
+
"network_mode": "none",
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
if (
|
|
@@ -278,6 +279,7 @@ def smc_parse(
|
|
|
278
279
|
"auto_remove": True,
|
|
279
280
|
"tty": True,
|
|
280
281
|
"stdin_open": True,
|
|
282
|
+
"network_mode": "none",
|
|
281
283
|
}
|
|
282
284
|
|
|
283
285
|
if input_parent_path == output_parent_path:
|
|
@@ -80,6 +80,7 @@ def canonicalize_ben_file(
|
|
|
80
80
|
"auto_remove": True,
|
|
81
81
|
"tty": True,
|
|
82
82
|
"stdin_open": True,
|
|
83
|
+
"network_mode": "none",
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
if input_parent_path == output_parent_path:
|
|
@@ -197,6 +198,7 @@ def relabel_json_file_by_key(
|
|
|
197
198
|
"auto_remove": True,
|
|
198
199
|
"tty": True,
|
|
199
200
|
"stdin_open": True,
|
|
201
|
+
"network_mode": "none",
|
|
200
202
|
}
|
|
201
203
|
|
|
202
204
|
if dual_graph_parent_path == output_parent_path:
|
|
@@ -324,6 +326,7 @@ def relabel_ben_file_by_key(
|
|
|
324
326
|
"auto_remove": True,
|
|
325
327
|
"tty": True,
|
|
326
328
|
"stdin_open": True,
|
|
329
|
+
"network_mode": "none",
|
|
327
330
|
}
|
|
328
331
|
|
|
329
332
|
if (
|
|
@@ -505,6 +508,7 @@ def relabel_ben_file_with_map(
|
|
|
505
508
|
"auto_remove": True,
|
|
506
509
|
"tty": True,
|
|
507
510
|
"stdin_open": True,
|
|
511
|
+
"network_mode": "none",
|
|
508
512
|
}
|
|
509
513
|
|
|
510
514
|
if (
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gerrytools
|
|
3
|
+
Version: 1.2.1
|
|
4
|
+
Summary: Tools for processing and visualizing districting plans.
|
|
5
|
+
Author-email: MGGG Redistricting Lab <engineering@mggg.org>
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: pandas>=2.3.2
|
|
11
|
+
Requires-Dist: scipy>=1.16.1
|
|
12
|
+
Requires-Dist: networkx>=3.5.0
|
|
13
|
+
Requires-Dist: geopandas>=1.1.1
|
|
14
|
+
Requires-Dist: Shapely>=2.0.0
|
|
15
|
+
Requires-Dist: matplotlib>=3.10.6
|
|
16
|
+
Requires-Dist: gerrychain>=0.3.2
|
|
17
|
+
Requires-Dist: sortedcontainers
|
|
18
|
+
Requires-Dist: jsonlines>=4.0.0
|
|
19
|
+
Requires-Dist: imageio>=2.37.0
|
|
20
|
+
Requires-Dist: us>=3.2.0
|
|
21
|
+
Requires-Dist: pydantic>=2.11.7
|
|
22
|
+
Requires-Dist: censusdata>=1.15.post1
|
|
23
|
+
Requires-Dist: seaborn>=0.13.2
|
|
24
|
+
Requires-Dist: numpy>=2.3.2
|
|
25
|
+
Requires-Dist: maup>=2.0.3
|
|
26
|
+
Requires-Dist: gurobipy>=12.0.3
|
|
27
|
+
Requires-Dist: opencv-python-headless>=4.11.0.86
|
|
28
|
+
Provides-Extra: docs
|
|
29
|
+
Requires-Dist: myst-parser>=4.0.1; extra == "docs"
|
|
30
|
+
Requires-Dist: sphinx>=8.2.3; extra == "docs"
|
|
31
|
+
Requires-Dist: sphinx-copybutton>=0.5.2; extra == "docs"
|
|
32
|
+
Requires-Dist: sphinx-rtd-theme>=3.0.2; extra == "docs"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# gerrytools
|
|
36
|
+
|
|
37
|
+
[](https://dl.circleci.com/status-badge/redirect/gh/mggg/gerrytools/tree/main)
|
|
38
|
+
[](https://codecov.io/gh/mggg/gerrytools)
|
|
39
|
+
[](https://badge.fury.io/py/gerrytools)
|
|
40
|
+
[](https://mggg.github.io/gerrytools/)
|
|
41
|
+
[](https://mggg.org)
|
|
42
|
+
[](https://github.com/psf/black)
|
|
43
|
+
[](https://pycqa.github.io/isort/)
|
|
44
|
+
|
|
45
|
+
A companion to [GerryChain](https://github.com/mggg/GerryChain), GerryTools is a robust suite of
|
|
46
|
+
geometric and algorithmic tools to analyze districting plans and related data. GerryTools is
|
|
47
|
+
actively developed and used by the [MGGG Redistricting Lab](https://mggg.org) and our collaborators
|
|
48
|
+
to prepare accurate, precise, and clean information for our projects. It is distributed under a
|
|
49
|
+
[3-Clause BSD License](https://opensource.org/licenses/BSD-3-Clause).
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
### Using `pip` (recommended)
|
|
54
|
+
|
|
55
|
+
To install GerryTools from [PyPi](https://pypi.org/project/gerrytools/), run
|
|
56
|
+
|
|
57
|
+
```console
|
|
58
|
+
pip install gerrytools
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
from the command line. if you would like to use the `mgrp` and `ben` modules as well, you can invoke
|
|
62
|
+
|
|
63
|
+
```console
|
|
64
|
+
pip install "gerrytools[mgrp]"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
you will need to make sure that [Docker Desktop](https://www.docker.com/get-started/) is installed
|
|
68
|
+
on your machine an updated to version >= 4.28.0. For more information on getting this set up, please
|
|
69
|
+
see [our documentation page](https://gerrytools.readthedocs.io/en/latest/topics/docker/)
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
GerryTools is split up into multiple sub-packages, each designed to simplify and standardize
|
|
74
|
+
redistricting workflows.
|
|
75
|
+
|
|
76
|
+
- **`gerrytools.ben`** BEN (binary-ensemble) is our general purpose compression algorithm for
|
|
77
|
+
working with ensembles of plans. In general, the ben algorithm can improve the storage of an
|
|
78
|
+
ensemble of plans by an order of magnitude. When combined with the special XBEN (eXtreme BEN)
|
|
79
|
+
portion of the algorithm, many ensembles of plans can be compressed small enough to fit into an
|
|
80
|
+
email (~25Mb).
|
|
81
|
+
|
|
82
|
+
- **`gerrytools.data`** deals with the retrieval and processing of data. Here, you can find tools
|
|
83
|
+
for grabbing decennial Census ('10 and '20), ACS 5-year ('12-'20), ACS CVAP Special Tab ('12-'20),
|
|
84
|
+
districtr portal, and 2020 decennial Census geometric data. You can also find tools for moving
|
|
85
|
+
CVAP data to other levels of geometry (e.g. prorating 2019 CVAP on 2019 Census tracts to 2020
|
|
86
|
+
blocks).
|
|
87
|
+
|
|
88
|
+
- **`gerrytools.geometry`** provides facilities for dealing with geometric and related data. There
|
|
89
|
+
are tools for translating and evaluating GerryChain
|
|
90
|
+
[`Partition`](https://mggg.github.io/GerryChain/api.html#module-gerrychain.partition)s, performing
|
|
91
|
+
fast geometric dissolutions, creating unit maps (e.g. 2020 blocks to 2020 VTDs), creating
|
|
92
|
+
[dual graphs for GerryChain](https://mggg.github.io/GerryChain/api.html#adjacency-graphs), and
|
|
93
|
+
optimization algorithms for renaming districts.
|
|
94
|
+
|
|
95
|
+
- **`gerrytools.mgrp`** this module uses a Docker container to allow users to access several
|
|
96
|
+
ensemble methods for generating districting plans on a state. In particular our Rust
|
|
97
|
+
implementation of our `gerrychain` library, `frcw`, the Julia implementation of
|
|
98
|
+
[Forest Recom](https://arxiv.org/pdf/2008.08054.pdf), and the R/C++ implementation of
|
|
99
|
+
[Sequential Monte Carlo (SMC)](https://github.com/alarm-redist/redist) are available through this
|
|
100
|
+
module.
|
|
101
|
+
|
|
102
|
+
- **`gerrytools.plotting`** contains methods for generating extremely high-quality Lab-standard data
|
|
103
|
+
visualizations.
|
|
104
|
+
|
|
105
|
+
- **`gerrytools.scoring`** provides a vast array of redistricting plan scores. These can be used
|
|
106
|
+
standalone _or_ as GerryChain
|
|
107
|
+
[updaters](https://mggg.github.io/GerryChain/api.html#module-gerrychain.updaters).
|
|
108
|
+
|
|
109
|
+
- **`gerrychain.utilities`** has ease-of-use methods for renaming directories containing shapefiles
|
|
110
|
+
(which comes in handy more often than you'd think) and making JSON objects out of Python objects
|
|
111
|
+
(useful when trying to organize information for many districting plans in a standard format).
|
|
112
|
+
|
|
113
|
+
<!-- ### Example
|
|
114
|
+
|
|
115
|
+
GerryTools is easy to use and is designed to simplify data- and redistricting-related
|
|
116
|
+
workflows. For example, let's say we want to analyze Alabama's citizen voting-age
|
|
117
|
+
population data on 2020 Census tracts. First, we can download the geometric data
|
|
118
|
+
for the state using `gerrytools.data.geometry20()`:
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from gerrytools.data import geometry20
|
|
122
|
+
from us import states
|
|
123
|
+
|
|
124
|
+
# Retrieves Lab-processed and -cleaned geometry data, and writes it to file.
|
|
125
|
+
geometry20(states.AL, "~/project/AL-tracts.zip", geometry="tract")
|
|
126
|
+
```
|
|
127
|
+
Next, we can download cleaned citizen voting-age population (CVAP) data from the 2020 ACS special tabulation release:
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from gerrytools.data import cvap
|
|
131
|
+
from us import states
|
|
132
|
+
|
|
133
|
+
# A pandas DataFrame of 2020 CVAP data for the state of Alabama at the 2020 Census
|
|
134
|
+
# tract level.
|
|
135
|
+
data = cvap(states.AL, geometry="tract", year=2020)
|
|
136
|
+
data.to_csv("~/project/AL-cvap.csv")
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Finally, we can merge the two datasets, attaching the CVAP demographic data to
|
|
140
|
+
the geometric data:
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
import geopandas as gpd
|
|
144
|
+
import pandas as pd
|
|
145
|
+
|
|
146
|
+
# Import geometric and demographic data.
|
|
147
|
+
geometric = gpd.read_file("~/project/AL-tracts.zip")
|
|
148
|
+
demographic = pd.read_csv("~/project/AL-cvap.csv")
|
|
149
|
+
|
|
150
|
+
# Merge. Note that the DataFrames have different unique identifier columns --- this
|
|
151
|
+
# is intentional, and serves to differentiate datasets of varying geometric levels.
|
|
152
|
+
merged = geometric.merge(demographic, left_on="GEOID20", right_on="TRACT20")
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
And there we are — what once took hours of setup and parsing now takes less than a
|
|
156
|
+
minute. -->
|
|
157
|
+
|
|
158
|
+
## Contributing
|
|
159
|
+
|
|
160
|
+
GerryTools is an active project, and has multiple contributors. If you'd like to contribute, here
|
|
161
|
+
are a few house rules:
|
|
162
|
+
|
|
163
|
+
1. After cloning this repository, run `sh setup.sh` to download and install necessary git hooks and
|
|
164
|
+
linting configurations.
|
|
165
|
+
|
|
166
|
+
1. **Follow the [PEP8 style guide](https://peps.python.org/pep-0008/)**. After installing the above
|
|
167
|
+
git hooks, linting is performed before every push. PEP8 errors can be automatically corrected by
|
|
168
|
+
running `autopep8 --in-place --aggressive -r gerrytools` on the command line from the root
|
|
169
|
+
directory.
|
|
170
|
+
|
|
171
|
+
1. **Write tests.** All changes, major or minor, **must** be accompanied by testing code. Code and
|
|
172
|
+
tests will be immediately reviewed by Lab maintainers.
|
|
173
|
+
|
|
174
|
+
1. Test coverage must stay **at least** the same; this can be checked by running
|
|
175
|
+
`pytest --cov=evaltools` after the tests are added to `tests/`.
|
|
176
|
+
|
|
177
|
+
1. **Write documentation.** All changes should be documented via docstrings, and code should be
|
|
178
|
+
repletely commented. It's much easier to decipher commented code! Docstring documentation is
|
|
179
|
+
compiled on every commit via git hooks.
|
|
180
|
+
|
|
181
|
+
We look forward to your contributions!
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
LICENSE
|
|
2
2
|
MANIFEST.in
|
|
3
3
|
README.md
|
|
4
|
-
|
|
4
|
+
pyproject.toml
|
|
5
5
|
gerrytools/__init__.py
|
|
6
6
|
gerrytools.egg-info/PKG-INFO
|
|
7
7
|
gerrytools.egg-info/SOURCES.txt
|
|
@@ -63,4 +63,8 @@ gerrytools/scoring/splits.py
|
|
|
63
63
|
gerrytools/scoring/types.py
|
|
64
64
|
gerrytools/utilities/JSON.py
|
|
65
65
|
gerrytools/utilities/__init__.py
|
|
66
|
-
gerrytools/utilities/rename.py
|
|
66
|
+
gerrytools/utilities/rename.py
|
|
67
|
+
tests/test_data.py
|
|
68
|
+
tests/test_geometry.py
|
|
69
|
+
tests/test_plotting.py
|
|
70
|
+
tests/test_scoring.py
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
pandas>=2.3.2
|
|
2
|
+
scipy>=1.16.1
|
|
3
|
+
networkx>=3.5.0
|
|
4
|
+
geopandas>=1.1.1
|
|
5
|
+
Shapely>=2.0.0
|
|
6
|
+
matplotlib>=3.10.6
|
|
7
|
+
gerrychain>=0.3.2
|
|
8
|
+
sortedcontainers
|
|
9
|
+
jsonlines>=4.0.0
|
|
10
|
+
imageio>=2.37.0
|
|
11
|
+
us>=3.2.0
|
|
12
|
+
pydantic>=2.11.7
|
|
13
|
+
censusdata>=1.15.post1
|
|
14
|
+
seaborn>=0.13.2
|
|
15
|
+
numpy>=2.3.2
|
|
16
|
+
maup>=2.0.3
|
|
17
|
+
gurobipy>=12.0.3
|
|
18
|
+
opencv-python-headless>=4.11.0.86
|
|
19
|
+
|
|
20
|
+
[docs]
|
|
21
|
+
myst-parser>=4.0.1
|
|
22
|
+
sphinx>=8.2.3
|
|
23
|
+
sphinx-copybutton>=0.5.2
|
|
24
|
+
sphinx-rtd-theme>=3.0.2
|