rdapy
Redistricting Analytics in Python
This repository (rdapy) re-implements the main analytics used in Dave's Redistricting (DRA). Unlike the analytics used in the app (dra-analytics) which are implememented in TypeScript, these are implemented as a Python package to make them easier to use outside of DRA. There is also a command-line interface for high-volume scoring.
These are described in detail at the website for this repository.
To use it in your Python, install the package. To use the high-volume scoring scripts, set up the command-line interface.
Installing the Package
To install the package:
pip install rdapy
The latest version of the package is 3.2.0.
Then in your code, either import rdapy or from rdapy import ....
Installing Command-Line Interface
Before installing the command-line interface (CLI), make sure you have the prerequisites installed.
Install Prequisites
The high-volume scoring scripts require Python 3.12 or later.
If that is not the default on your computer,
you can use pyenv to manage multiple Python versions.
These instructions assume you're using pyenv.
Install pyenv from Homebrew:
brew install pyenv
Completing that setup will involve adding a few lines to your shell profile file (like .bash_profile).
You can install Python 3.12 from Homebrew:
brew install python@3.12
Setting Up Your Environment
With the prequisites installed, clone the GitHub repository:
git clone https://github.com/dra2020/rdapy
cd rdapy
Then create a virtual environment that uses Python 3.12, and then reset Python outside the virtual environment to the normal setting:
pyenv shell 3.12
python3 -m venv /path/to/venvs/rdapy
source /path/to/venvs/rdapy/bin/activate
deactivate
pyenv shell --unset
Then activate the virtual environment again, and install the required dependencies:
source /path/to/venvs/rdapy/bin/activate
pip install -r requirements.txt
pip install --upgrade pip
export PYTHONPATH="${PYTHONPATH}:$(pwd)"
Finally, test that the automated tests run:
pytest
Then score some sample plans. On a Mac or Linux, use this bash script:
scripts/score/SCORE.sh \
--state NC \
--plan-type congress \
--geojson /dir/for/unzipped/files/NC_2020_VD_tabblock.vtd.datasets.geojson \
--graph /dir/for/unzipped/files/NC_2020_graph.json \
--precomputed testdata/examples/NC_congress_precomputed.json \
--plans testdata/plans/NC_congress_plans.tagged.jsonl \
--scores /path/to/TEST_scores.csv \
--by-district /path/to/TEST_by-district.jsonl
The --scores and by-district paths are where you want the scores CSV and
by-district JSONL aggregates files to be saved, respectively.
Alternatively or on Windows, use this Python version of the script:
scripts/score/SCORE-PYTHON.py \
--state NC \
--plan-type congress \
--geojson /dir/for/unzipped/files/NC_2020_VD_tabblock.vtd.datasets.geojson \
--graph /dir/for/unzipped/files/NC_2020_graph.json \
--precomputed testdata/examples/NC_congress_precomputed.json \
--plans testdata/plans/NC_congress_plans.tagged.jsonl \
--scores /path/to/TEST_scores.csv \
--by-district /path/to/TEST_by-district.jsonl
It has the same arguments as the bash script, and will produce the same output files, but it is implemented in Python and can be run on Windows.
Development
There is a sample launch.json for VS Code debugging in the docs directory.
Testing
Run automated tests with:
pytest
Questions
Email questions to feedback.
Metadata
Release files for rdapy 3.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rdapy-3.2.0.tar.gz | 82.4 kB | Without provenance | Details for rdapy-3.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rdapy-3.2.0-py3-none-any.whl | Python 3 | none | any | Details for rdapy-3.2.0-py3-none-any.whl |
Total release size: 156.2 kB
Release files / rdapy-3.2.0.tar.gz
| Download URL | rdapy-3.2.0.tar.gz |
|---|---|
| Size | 82.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
471dc77f927e5c7cfa3030ddcbe90c19fa829517ef5f95df80cff1113768d1d2
|
|
BLAKE2b-256 checksum How to use checksums |
6e07b955aac87e6e0a9cfd2713232364a207ad3eeef5c97cd323adec7a4470e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|
Release files / rdapy-3.2.0-py3-none-any.whl
| Download URL | rdapy-3.2.0-py3-none-any.whl |
|---|---|
| Size | 73.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
09e2abb1e3108b1dd490f4cbed972a7d33bd5aab21cb00a449d97d0944f6d8a8
|
|
BLAKE2b-256 checksum How to use checksums |
7525375bed216e554260c4c03ba46c900b15eda3775517cd433dd68bc2fdb073
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|
Security for rdapy 3.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.