Skip to content

Add hhs geo level aggregation for NSSP #2036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions _delphi_utils_python/delphi_utils/geomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def add_population_column(
---------
data: pd.DataFrame
The dataframe with a FIPS code column.
geocode_type: {"fips", "zip"}
geocode_type:
The type of the geocode contained in geocode_col.
geocode_col: str, default None
The name of the column containing the geocodes. If None, uses the geocode_type
Expand Down Expand Up @@ -671,8 +671,10 @@ def aggregate_by_weighted_sum(
to a from_geo, e.g. "wastewater collection site").
to_geo: str
The column name of the geocode to aggregate to.
sensor: str
sensor_col: str
The column name of the sensor to aggregate.
time_col: str
The column name of the timestamp to aggregate over.
population_column: str
The column name of the population to weight the sensor by.

Expand Down
1 change: 1 addition & 0 deletions nssp/delphi_nssp/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"nation",
"state",
"county",
"hhs",
]

SIGNALS_MAP = {
Expand Down
8 changes: 8 additions & 0 deletions nssp/delphi_nssp/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ def run_module(params):
df = geo_mapper.add_geocode(df, "fips", "msa", from_col="fips", new_col="geo_id")
df = geo_mapper.aggregate_by_weighted_sum(df, "geo_id", "val", "timestamp", "population")
df = df.rename(columns={"weighted_val": "val"})
elif geo == "hhs":
df = df[(df["county"] == "All") & (df["geography"] != "United States")]
df = df[["geography", "val", "timestamp"]]
df = geo_mapper.add_population_column(df, geocode_type="state_name", geocode_col="geography")
df = geo_mapper.add_geocode(df, "state_name", "state_code", from_col="state_name")
df = geo_mapper.add_geocode(df, "state_code", "hhs", from_col="state_code", new_col="geo_id")
df = geo_mapper.aggregate_by_weighted_sum(df, "geo_id", "val", "timestamp", "population")
df = df.rename(columns={"weighted_val": "val"})
else:
df = df[df["county"] != "All"]
df["geo_id"] = df["fips"]
Expand Down
Loading