From a20160338462b39333c92135cf53ba28b7373cc9 Mon Sep 17 00:00:00 2001 From: minhkhul Date: Mon, 26 Aug 2024 18:40:44 -0400 Subject: [PATCH] add hhs geo level --- _delphi_utils_python/delphi_utils/geomap.py | 6 ++++-- nssp/delphi_nssp/constants.py | 1 + nssp/delphi_nssp/run.py | 8 ++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/_delphi_utils_python/delphi_utils/geomap.py b/_delphi_utils_python/delphi_utils/geomap.py index be6df2d24..f6df4a919 100644 --- a/_delphi_utils_python/delphi_utils/geomap.py +++ b/_delphi_utils_python/delphi_utils/geomap.py @@ -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 @@ -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. diff --git a/nssp/delphi_nssp/constants.py b/nssp/delphi_nssp/constants.py index ddd2e74b8..9b98d2012 100644 --- a/nssp/delphi_nssp/constants.py +++ b/nssp/delphi_nssp/constants.py @@ -6,6 +6,7 @@ "nation", "state", "county", + "hhs", ] SIGNALS_MAP = { diff --git a/nssp/delphi_nssp/run.py b/nssp/delphi_nssp/run.py index 7c5a3ffac..931cd7c71 100644 --- a/nssp/delphi_nssp/run.py +++ b/nssp/delphi_nssp/run.py @@ -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"]