Skip to content

Commit

Permalink
change main args, fix county data lines, add new test states, add ens…
Browse files Browse the repository at this point in the history
…emble score distribution lines
  • Loading branch information
pbnjam-es committed Feb 26, 2023
1 parent fca4938 commit 4d6e8c0
Show file tree
Hide file tree
Showing 21 changed files with 159 additions and 29 deletions.
11 changes: 8 additions & 3 deletions rba/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import argparse
import os
import json

import rba

Expand Down Expand Up @@ -50,7 +51,7 @@
draw_parser.add_argument("--state", type=str, default="new_hampshire")
draw_parser.add_argument("--output_file", type=str)
# draw_parser.add_argument("--graph_file", type=str, default=os.path.join(package_dir, "data/2010/new_hampshire_geodata_merged.json"))
draw_parser.add_argument("--edge_lifetime_file", type=str, default=None)
# draw_parser.add_argument("--edge_lifetime_file", type=str, default=None)
draw_parser.add_argument("--num_frames", type=int, default=50)
draw_parser.add_argument("--partition_file", type=str, default=None)
draw_parser.set_defaults(func=rba.visualization.visualize)
Expand Down Expand Up @@ -84,20 +85,24 @@
if args.func.__name__ == "create_communities":
arguments["graph_file"] = os.path.join(package_dir, f"data/2010/{state}_geodata_merged.json")
arguments["output_file"] = os.path.join(package_dir, f"data/2010/{state}_communities.json")
elif args.func.__name__ == "quantify_districtss":
elif args.func.__name__ == "quantify_districts":
arguments["graph_file"] = os.path.join(package_dir, f"data/2010/{state}_geodata_merged.json")
arguments["community_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")
elif args.func.__name__ == "visualize":
arguments["graph_file"] = os.path.join(package_dir, f"data/2010/{state}_geodata_merged.json")
arguments["edge_lifetime_file"] = os.path.join(package_dir, f"data/2010/{state}_communities.json")
elif args.func.__name__ == "ensemble_analysis":
arguments["graph_file"] = os.path.join(package_dir, f"data/2010/{state}_geodata_merged.json")
arguments["community_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["vra_config_file"] = os.path.join(package_dir, f"data/2010/vra_{state}.json")
elif args.func.__name__ == "optimize":
arguments["graph_file"] = os.path.join(package_dir, f"data/2010/{state}_geodata_merged.json")
arguments["community_file"] = os.path.join(package_dir, f"data/2010/{state}_communities.json")
# with open(os.path.join(package_dir, f"data/2010/{state}_communities.json"), "r") as f:
# community_data = json.load(f)
arguments["communitygen_out_file"] = os.path.join(package_dir, f"data/2010/{state}_communities.json")
# arguments["communitygen_out_file"] = community_data
arguments["vra_config_file"] = os.path.join(package_dir, f"data/2010/vra_{state}.json")
# if arguments["func"]
# args.func(**{key: val for key, val in vars(args).items() if key != "func"})
Expand Down
11 changes: 10 additions & 1 deletion rba/community_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import networkx as nx
import numpy as np
import shapely
from gerrychain import Graph
from scipy.spatial import distance
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -36,7 +37,15 @@ def compute_precinct_similarities(graph, verbose=False):
if data["total_pop"] == 0:
population_density = 0
else:
population_density = math.log(data["total_pop"]/data["ALAND10"])
# population_density = math.log(data["total_pop"]/data["ALAND10"])
# print(data["geometry"]["coordinates"])
if isinstance(data["geometry"]["coordinates"][0][0][0], float):
geometry = shapely.geometry.Polygon(data["geometry"]["coordinates"][0])
else:
geomlist = [shapely.geometry.Polygon(data["geometry"]["coordinates"][i][0]) for i in range(len(data["geometry"]["coordinates"]))]
geometry = shapely.ops.unary_union(geomlist)
# print(geometry.type)
population_density = math.log(data["total_pop"]/geometry.area)
min_pop_density = min(min_pop_density, population_density)
max_pop_density = max(max_pop_density, population_density)
population_densities[node] = population_density
Expand Down
2 changes: 1 addition & 1 deletion rba/data/2010/maryland_communities.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rba/data/2010/maryland_geodata_merged.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rba/data/2010/new_hampshire_communities.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rba/data/2010/new_hampshire_geodata_merged.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions rba/data/2010/new_york_communities.json

Large diffs are not rendered by default.

Loading

0 comments on commit 4d6e8c0

Please sign in to comment.