From 9cf840f7563a47187a2b3700927216ea6152a0ca Mon Sep 17 00:00:00 2001 From: jamesxgamesyt Date: Mon, 27 Feb 2023 21:21:11 -0500 Subject: [PATCH] minor fixes --- .gitignore | 3 +++ rba/__main__.py | 1 + rba/district_quantification.py | 4 +++- rba/ensemble.py | 4 ++-- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 5363b81..05bb62a 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ examples/*out NC_ensemble_10000 debug.py + +maryland +new_hampshire diff --git a/rba/__main__.py b/rba/__main__.py index 058d00a..ed726e7 100644 --- a/rba/__main__.py +++ b/rba/__main__.py @@ -90,6 +90,7 @@ arguments["graph_file"] = os.path.join(package_dir, f"data/2010/{state}_geodata_merged.json") arguments["difference_file"] = os.path.join(package_dir, f"data/2010/{state}_communities.json") arguments["district_file"] = os.path.join(package_dir, f"data/2010/{state}_districts.json") + # arguments["district_file"] = os.path.join(package_dir, f"../{state}_optimize_10000/Plan_1.json") elif args.func.__name__ == "visualize": arguments["graph_file"] = os.path.join(package_dir, f"data/2010/{state}_geodata_merged.json") arguments["difference_file"] = os.path.join(package_dir, f"data/2010/{state}_communities.json") diff --git a/rba/district_quantification.py b/rba/district_quantification.py index 353f3c1..f6b7716 100644 --- a/rba/district_quantification.py +++ b/rba/district_quantification.py @@ -77,7 +77,9 @@ def quantify_districts(graph_file, district_file, difference_file, verbose=False with open(graph_file, "r") as f: graph_json = json.load(f) graph = nx.readwrite.json_graph.adjacency_graph(graph_json) - districts = load_districts(graph, district_file) + # districts = load_districts(graph, district_file) + with open(district_file, "r") as f: + districts = json.load(f) with open(difference_file, "r") as f: supercommunity_output = json.load(f) # Contains strings as keys. diff --git a/rba/ensemble.py b/rba/ensemble.py index c7e2420..bb1d361 100644 --- a/rba/ensemble.py +++ b/rba/ensemble.py @@ -441,6 +441,8 @@ def ensemble_analysis(graph_file, difference_file, vra_config_file, num_steps, n for precinct in precincts: districts_precinct_df.loc[precinct] = [district_scores[district], homogeneity] + if optimize_vis: + output_dir = vis_dir # Save a histogram of statewide scores. plt.hist(scores_df["state_gerry_score"], bins=30) plt.axvline(scores_df["state_gerry_score"].mean(), color='k', linestyle='dashed', linewidth=1) @@ -463,8 +465,6 @@ def get_z_score(precinct, metric): districts_partition = Partition(graph, assignment=districts_assignment) # TODO: this doesn't work with Maryland for some reason - if optimize_vis: - output_dir = vis_dir _, ax = plt.subplots(figsize=(12.8, 9.6)) visualize_gradient_geopandas( sorted_node_names,