Skip to content

Commit

Permalink
add 2020 cartographic tracts
Browse files Browse the repository at this point in the history
  • Loading branch information
knaaptime committed Oct 2, 2023
1 parent 8d3412a commit c38d87f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
44 changes: 37 additions & 7 deletions geosnap/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,28 @@ def __delitem__(self, key):
class DataStore:
"""Storage for geosnap data. Currently supports data from several U.S. federal agencies and national research centers."""

def __init__(self, data_dir="auto"):
self
def __init__(self, data_dir="auto", disclaimer=False):
appname = "geosnap"
appauthor = "geosnap"

if data_dir == "auto":
self.data_dir = user_data_dir(appname, appauthor)
else:
self.data_dir = data_dir
warn(
"The geosnap data storage class is provided for convenience only. The geosnap developers make no promises "
"regarding data quality, consistency, or availability, nor are they responsible for any use/misuse of the data. "
"The end-user is responsible for any and all analyses or applications created with the package."
)
if disclaimer:
warn(
"The geosnap data storage class is provided for convenience only. The geosnap developers make no promises "
"regarding data quality, consistency, or availability, nor are they responsible for any use/misuse of the data. "
"The end-user is responsible for any and all analyses or applications created with the package."
)

def __dir__(self):

atts = [
"acs",
"blocks_2000",
"blocks_2010",
"blocks_2020",
"codebook",
"counties",
"ejscreen",
Expand All @@ -89,6 +90,7 @@ def __dir__(self):
"tracts_1990",
"tracts_2000",
"tracts_2010",
"tracts_2020"
]

return atts
Expand Down Expand Up @@ -474,6 +476,34 @@ def tracts_2010(
t["year"] = 2010
return t

def tracts_2020(
self,
states=None,
):
"""Nationwide Census Tracts as drawn in 2010 (cartographic 500k).
Parameters
----------
states : list-like
list of state fips to subset the national dataframe
Returns
-------
pandas.DataFrame or geopandas.GeoDataFrame
2010 tracts as a geodataframe or as a dataframe with geometry
stored as well-known binary on the 'wkb' column.
"""
msg = "Streaming data from S3. Use `geosnap.io.store_census() to store the data locally for better performance"
local = pathlib.Path(self.data_dir, "tracts_2020_500k.parquet")
remote = "s3://spatial-ucr/census/tracts_cartographic/tracts_2020_500k.parquet"
t = _fetcher(local, remote, msg)

if states:
t = t[t.geoid.str[:2].isin(states)]
t["year"] = 2020
return t

def msas(self):
"""Metropolitan Statistical Areas as drawn in 2020.
Expand Down
4 changes: 4 additions & 0 deletions geosnap/tests/test_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def test_tracts10():
df = datasets.tracts_2010(states=["11"])
assert df.shape == (179, 194)

def test_tracts20():
df = datasets.tracts_2020(states=["11"])
assert df.shape == (206, 15)


def test_counties():
assert datasets.counties().shape == (3233, 2)
Expand Down

0 comments on commit c38d87f

Please sign in to comment.