Package: rdaensemble
rdaensembleRedistricting ensemblesMethodsThe code in this repository supports several methods for generating ensembles of redistricting plans (maps):Random maps from random spanning trees (RMfRST)Random maps from random starting points (RMfRSP)Ensemble of maps using MCMC/ReCom (ReCom)Ensemble of maps using Sequential Monte Carlo (SMC) <<< TODOInput FilesThe inputs for generating & scoring ensembles are:fromrdascoreimportload_data,load_shapes,load_graph,load_metadatadata: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 repositoryrdatools/rdabasein thedatadirectory by state.
They are namedNC_2020_data.csv,NC_2020_shapes_simplified.json, andNC_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 inrdabase.Output FilesEnsembles are saved as JSON files.
A file contains metadata about the ensemble, including the method used to generate it,
and then aplanskey with a list of plans:plans:List[Dict[str,str|float|Dict[str,int|str]]]Each plan item has aname(str), an optionalweight(float), and aplan(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 byrdatools/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.Naming ConventionsYou can name ensemble and score files anything you want.
To facilitate understanding the contents of these files without having to open them,
we recommend the following the convention:Ensemble example:NC20C_RMfRST_1000_plans.jsonScores example:NC20C_RMfRST_1000_scores.csvwhere "NC" is the state code, "20" stands for the 2020 census cycle,
"C" abbreviates "Congress" (as opposed to state upper or lower house),
"RMfRST" is the method, 1000 is the number of plans in the ensemble, and
"plans" and "scores" distinguish between the two types of files.Note: The scores metadata file will be named the same as the scores file,
except it will end_metadata.jsoninstead of.csv,
for example,NC20C_RMfRST_1000_scores_metadata.json.UsageTo generate an ensemble of 1,000 plans using the random maps from random spanning trees method (RMfRST), run:scripts/rmfrst_ensemble.py\--stateNC\--data../rdabase/data/NC/NC_2020_data.csv\--shapes../rdabase/data/NC/NC_2020_shapes_simplified.json\--graph../rdabase/data/NC/NC_2020_graph.json\--size1000\--plans~/iCloud/fileout/ensembles/NC20C_RMfRST_1000_plans.json\--log~/iCloud/fileout/ensembles/NC20C_RMfRST_1000_log.txt\--no-debugTo score the resulting ensemble, run:scripts/score_ensemble.py\--stateNC\--plans~/iCloud/fileout/ensembles/NC20C_RMfRST_1000_plans.json\--data../rdabase/data/NC/NC_2020_data.csv\--shapes../rdabase/data/NC/NC_2020_shapes_simplified.json\--graph../rdabase/data/NC/NC_2020_graph.json\--scores~/iCloud/fileout/ensembles/NC20C_RMfRST_1000_scores.csv\--no-debugTo generate random maps from random starting points (RMfRSP) instead, use thermfrst_ensemble.pyscript.
For ReCom, use therecom_ensemble.pyscript.Note: Ensemble JSON files can be quite large, bigger than GitHub's 100 MB file size limit,
so we recommend that you write them to theensemblesdirectory, which is ignored by Git.