Skip to content

Commit 4b9e836

Browse files
committed
Merge branch 'ndefries/geomapper/popsafe-county-level' into ndefries/geomapper/chng-fips-map-generation
2 parents f9ed4d4 + 4fa39b7 commit 4b9e836

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

_delphi_utils_python/data_proc/geomap/geo_data_proc.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
FIPS_PUERTO_RICO_POPULATION_URL = "https://www2.census.gov/geo/docs/maps-data/data/rel/zcta_county_rel_10.txt?"
3434
STATE_HHS_FILE = "hhs.txt"
3535
ZIP_POP_MISSING_FILE = "zip_pop_filling.csv"
36-
LOWPOP_COUNTY_GROUPS_FILE = "lowpop_county_groups.csv"
36+
CHNG_COUNTY_GROUPS_FILE = "chng_county_groups.csv"
3737

3838
# Out files
3939
FIPS_STATE_OUT_FILENAME = "fips_state_table.csv"
@@ -484,7 +484,7 @@ def derive_fips_chngfips_crosswalk():
484484
derive_fips_state_crosswalk()
485485

486486
assign_county_groups()
487-
county_groups = pd.read_csv(LOWPOP_COUNTY_GROUPS_FILE, dtype="string", index_col=False)
487+
county_groups = pd.read_csv(CHNG_COUNTY_GROUPS_FILE, dtype="string", index_col=False)
488488
# Split list of county FIPS codes into separate columns.
489489
county_groups = pd.concat(
490490
[county_groups, county_groups.fips_list.str.split("|", expand=True)],
@@ -503,21 +503,21 @@ def derive_fips_chngfips_crosswalk():
503503
columns="county_num"
504504
).dropna()
505505

506-
county_groups["state_fips"] = county_groups["state_fips"].str.zfill(2).astype("string")
507-
county_groups["group"] = county_groups["group"].str.zfill(2).astype("string")
506+
county_groups["state_fips"] = county_groups["state_fips"].str.zfill(2)
507+
county_groups["group"] = county_groups["group"].str.zfill(2)
508508
county_groups["fips"] = county_groups["fips"].str.zfill(5).astype("string")
509509
# Combine state codes and group ids into a single FIPS code.
510510
county_groups["chng-fips"] = county_groups["state_fips"] + "g" + county_groups["group"]
511511

512512
county_groups = county_groups[["fips", "chng-fips"]]
513513
fips_to_state = pd.read_csv(join(OUTPUT_DIR, FIPS_STATE_OUT_FILENAME), dtype="string", index_col=False)
514514

515-
# Get all the fips that aren't included in the low-population groupings.
515+
# Get all the fips that aren't included in the chng groupings.
516516
extra_fips_list = list(set(fips_to_state.fips) - set(county_groups.fips))
517-
# Normal fips codes and CHNG fips codes are the same for high-population counties.
517+
# Normal fips codes and CHNG fips codes are the same for ungrouped counties.
518518
extra_fips_df = pd.DataFrame({"fips" : extra_fips_list, "chng-fips" : extra_fips_list}, dtype="string")
519519

520-
# Combine high-pop and low-pop counties.
520+
# Combine grouped and ungrouped counties.
521521
pd.concat(
522522
[county_groups, extra_fips_df]
523523
).sort_values(
@@ -581,12 +581,12 @@ def fetch_county_groups_spreadsheet():
581581
def assign_county_groups():
582582
county_groups = fetch_county_groups_spreadsheet()
583583

584-
# If a `lowpop_county_groups.csv` already exists in `data_proc/geomap`, we
584+
# If a county groups mapping file already exists in `data_proc/geomap`, we
585585
# have to be careful to not reassign a group number to a different group.
586586
# Group numbers must remain fixed, even if a given county group is no longer
587587
# being used.
588-
if isfile(LOWPOP_COUNTY_GROUPS_FILE):
589-
old_county_groups = pd.read_csv(LOWPOP_COUNTY_GROUPS_FILE, dtype="string", index_col=False)
588+
if isfile(CHNG_COUNTY_GROUPS_FILE):
589+
old_county_groups = pd.read_csv(CHNG_COUNTY_GROUPS_FILE, dtype="string", index_col=False)
590590
old_county_groups.group = old_county_groups.group.astype(int)
591591
old_county_groups.state_fips = old_county_groups.state_fips.astype(int)
592592

@@ -636,12 +636,13 @@ def assign_county_groups():
636636
# Combine old_county_groups and county_groups
637637
county_groups = pd.concat([old_county_groups, county_groups])
638638
else:
639+
# Group numbers are 1-indexed.
639640
county_groups["group"] = county_groups.groupby("state_fips").cumcount() + 1
640641

641642
county_groups.sort_values(
642643
["state_fips"], kind="stable"
643644
).to_csv(
644-
LOWPOP_COUNTY_GROUPS_FILE, index=False
645+
CHNG_COUNTY_GROUPS_FILE, index=False
645646
)
646647

647648

0 commit comments

Comments
 (0)