Skip to main content

Redistricting ensembles

Project description

rdaensemble

Redistricting ensembles

Installation

To clone the repository:

$ git clone https://github.com/rdatools/rdaensemble
$ cd rdaensemble

To run the scripts, install the dependencies:

pip install -r requirements.txt

To install the package in another project:

$ pip install rdaensemble

Usage

To generate an ensemble of plans, use one of the *_ensemble.py scripts:

  • rmfrst_ensemble.py for Random Maps from Random Spanning Trees (RMfRST)
  • rmfrsp_ensemble.py for Random Maps from Random Starting Points (RMfRSP)
  • recom_ensemble.py for ReCom

There are example calls in each file. Note: The resulting ensemble JSON files can be quite large--bigger than GitHub's 100 MB file size limit-- so we recommend that you write them to a directory which is not under source control.

To score the plans in an ensemble, use the score_ensemble.py script.

The other scripts are specific to our "trade-offs in redistricting" project and are not generally useful.

Notes

The inputs for generating & scoring ensembles are:

from rdascore import load_data, load_shapes, load_graph, load_metadata

data: Dict[str, Dict[str, int | str]] = load_data(data_path)
shapes: Dict[str, Any] = load_shapes(shapes_path)
graph: Dict[str, List[str]] = load_graph(graph_path)
metadata: Dict[str, Any] = load_metadata(state_code, data_path)

The precinct data, shapes, and graphs are all available in the companion repository rdatools/rdabase in the data directory by state. They are named NC_2020_data.csv, NC_2020_shapes_simplified.json, and NC_2020_graph.json, for example.

Theoretically, these inputs can come from any source, but for simplicity, reproducibility, and apples-to-apples comparisons, it's best to use the input files in rdabase.

Ensembles are saved as JSON files. A file contains metadata about the ensemble, including the method used to generate it, and then a plans key with a list of plans:

plans: List[Dict[str, str | float | Dict[str, int | str]]]

Each plan item has a name (str), an optional weight (float), and a plan (Dict[str, int | str]]) which represents the assignments as geoid: district_id key: value pairs.

Scores for the plans in an ensemble are saved as a CSV file, with one row per plan and one column per metric. The metrics are the same as those produced by rdatools/rdascore, except they also include the energy of the plan. The metric names are descriptive.

When a scores CSV file is produced, a companion JSON file with metadata about the scoring is also generated.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rdaensemble-1.9.0.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

rdaensemble-1.9.0-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

Details for the file rdaensemble-1.9.0.tar.gz.

File metadata

  • Download URL: rdaensemble-1.9.0.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for rdaensemble-1.9.0.tar.gz
Algorithm Hash digest
SHA256 0f8ca3251e76d5638174f0ee59dc615e62978fc3a843a4da388b54bd1038b8e1
MD5 722909c58b80c9a1ffdb89e308e88042
BLAKE2b-256 d632230d1fe634eb291d7b93890e416fc9d1a4ee5e816d0a4401493e64e0402d

See more details on using hashes here.

File details

Details for the file rdaensemble-1.9.0-py3-none-any.whl.

File metadata

  • Download URL: rdaensemble-1.9.0-py3-none-any.whl
  • Upload date:
  • Size: 25.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for rdaensemble-1.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb041e2a266962c8cfbc40c6e8cd76194a1afb7d37c926f38a5cce3093b34154
MD5 c0afe19d53a0d4e88e754d71053efa74
BLAKE2b-256 3d11d0b56846bbfcbd9a757b6f9695149f5801add2367ceac86a405b0f01d7a9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page