mirror of
https://github.com/DOI-DO/j40-cejst-2.git
synced 2025-02-24 02:24:20 -08:00
This ended up being a pretty large task. Here's what this PR does: 1. Pulls in Vincent's data from island areas into the score ETL. This is from the 2010 decennial census, the last census of any kind in the island areas. 2. Grabs a few new fields from 2010 island areas decennial census. 3. Calculates area median income for island areas. 4. Stops using EJSCREEN as the source of our high school education data and directly pulls that from census (this was related to this project so I went ahead and fixed it). 5. Grabs a bunch of data from the 2010 ACS in the states/Puerto Rico/DC, so that we can create percentiles comparing apples-to-apples (ish) from 2010 island areas decennial census data to 2010 ACS data. This required creating a new class because all the ACS fields are different between 2010 and 2019, so it wasn't as simple as looping over a year parameter. 6. Creates a combined population field of island areas and mainland so we can use those stats in our comparison tool, and updates the comparison tool accordingly.
88 lines
3.4 KiB
Python
88 lines
3.4 KiB
Python
import pandas as pd
|
|
|
|
from data_pipeline.etl.base import ExtractTransformLoad
|
|
from data_pipeline.score import field_names
|
|
from data_pipeline.utils import get_module_logger
|
|
|
|
logger = get_module_logger(__name__)
|
|
|
|
|
|
class EJSCREENETL(ExtractTransformLoad):
|
|
def __init__(self):
|
|
self.EJSCREEN_FTP_URL = "https://edap-arcgiscloud-data-commons.s3.amazonaws.com/EJSCREEN2020/EJSCREEN_Tract_2020_USPR.csv.zip"
|
|
self.EJSCREEN_CSV = self.TMP_PATH / "EJSCREEN_Tract_2020_USPR.csv"
|
|
self.CSV_PATH = self.DATA_PATH / "dataset" / "ejscreen_2019"
|
|
self.df: pd.DataFrame
|
|
|
|
self.COLUMNS_TO_KEEP = [
|
|
self.GEOID_TRACT_FIELD_NAME,
|
|
field_names.TOTAL_POP_FIELD,
|
|
# pylint: disable=duplicate-code
|
|
field_names.AIR_TOXICS_CANCER_RISK_FIELD,
|
|
field_names.RESPITORY_HAZARD_FIELD,
|
|
field_names.DIESEL_FIELD,
|
|
field_names.PM25_FIELD,
|
|
field_names.OZONE_FIELD,
|
|
field_names.TRAFFIC_FIELD,
|
|
field_names.RMP_FIELD,
|
|
field_names.TSDF_FIELD,
|
|
field_names.NPL_FIELD,
|
|
field_names.WASTEWATER_FIELD,
|
|
field_names.HOUSEHOLDS_LINGUISTIC_ISO_FIELD,
|
|
field_names.POVERTY_FIELD,
|
|
field_names.OVER_64_FIELD,
|
|
field_names.UNDER_5_FIELD,
|
|
field_names.LEAD_PAINT_FIELD,
|
|
]
|
|
|
|
def extract(self) -> None:
|
|
logger.info("Downloading EJScreen Data")
|
|
super().extract(
|
|
self.EJSCREEN_FTP_URL,
|
|
self.TMP_PATH,
|
|
verify=False, # EPA EJScreen end point has certificate issues often
|
|
)
|
|
|
|
def transform(self) -> None:
|
|
logger.info("Transforming EJScreen Data")
|
|
self.df = pd.read_csv(
|
|
self.EJSCREEN_CSV,
|
|
dtype={"ID": "string"},
|
|
# EJSCREEN writes the word "None" for NA data.
|
|
na_values=["None"],
|
|
low_memory=False,
|
|
)
|
|
|
|
# rename ID to Tract ID
|
|
self.df.rename(
|
|
columns={
|
|
"ID": self.GEOID_TRACT_FIELD_NAME,
|
|
# Note: it is currently unorthodox to use `field_names` in an ETL class,
|
|
# but I think that's the direction we'd like to move all ETL classes. - LMB
|
|
"ACSTOTPOP": field_names.TOTAL_POP_FIELD,
|
|
"CANCER": field_names.AIR_TOXICS_CANCER_RISK_FIELD,
|
|
"RESP": field_names.RESPITORY_HAZARD_FIELD,
|
|
"DSLPM": field_names.DIESEL_FIELD,
|
|
"PM25": field_names.PM25_FIELD,
|
|
"OZONE": field_names.OZONE_FIELD,
|
|
"PTRAF": field_names.TRAFFIC_FIELD,
|
|
"PRMP": field_names.RMP_FIELD,
|
|
"PTSDF": field_names.TSDF_FIELD,
|
|
"PNPL": field_names.NPL_FIELD,
|
|
"PWDIS": field_names.WASTEWATER_FIELD,
|
|
"LINGISOPCT": field_names.HOUSEHOLDS_LINGUISTIC_ISO_FIELD,
|
|
"LOWINCPCT": field_names.POVERTY_FIELD,
|
|
"OVER64PCT": field_names.OVER_64_FIELD,
|
|
"UNDER5PCT": field_names.UNDER_5_FIELD,
|
|
"PRE1960PCT": field_names.LEAD_PAINT_FIELD,
|
|
},
|
|
inplace=True,
|
|
)
|
|
|
|
def load(self) -> None:
|
|
logger.info("Saving EJScreen CSV")
|
|
# write nationwide csv
|
|
self.CSV_PATH.mkdir(parents=True, exist_ok=True)
|
|
self.df[self.COLUMNS_TO_KEEP].to_csv(
|
|
self.CSV_PATH / "usa.csv", index=False
|
|
)
|