Skip to content

Commit

Permalink
Make BPT shapes valid; bypass 403 error reading laus codes
Browse files Browse the repository at this point in the history
  • Loading branch information
camille-s committed Jan 9, 2024
1 parent ac92752 commit 20fb68f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions data-raw/make_geo_sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ stamford_sf <- sf::st_read("https://gist.github.com/camille-s/7002148f77b0020f78

bridgeport_sf <- sf::st_read("https://gist.github.com/camille-s/c5e4f0178cfbf288af454016018f5173/raw/43faa412db577c4f770d861ab913116ccdb3d445/bpt_tract_neighborhoods.geojson") |>
dplyr::select(name = Name, geometry) |>
sf::st_transform(sf::st_crs(tract_sf)) |>
sf::st_simplify(dTolerance = 1e-6)
sf::st_make_valid() |>
sf::st_transform(sf::st_crs(tract_sf))


hartford_sf <- sf::st_read("https://gist.github.com/camille-s/9e9761b69a7c86bf6d7163cb73636f26/raw/3858f538d955c022b43e168e4c7cec316c2e437f/hfd_shape.json") |>
Expand Down
17 changes: 15 additions & 2 deletions data-raw/make_laus_codes.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,26 @@
# dplyr::select(type = area_type_code, area, code = area_code)

# bls updated the measures listed--for now, filter to the original 4
laus_measures <- readr::read_tsv("https://download.bls.gov/pub/time.series/la/la.measure") |>

# no longer allows direct download--403 error
# got these headers from firefox devtools
headers <- list("User-Agent" = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0",
"Accept" = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
"Accept-Language" = "en-US,en;q=0.5",
"Accept-Encoding" = "gzip, deflate, br")
h1 <- curl::new_handle(); h2 <- curl::new_handle()
curl::handle_setheaders(h1, .list = headers)
curl::handle_setheaders(h2, .list = headers)

laus_measures <- curl::curl("https://download.bls.gov/pub/time.series/la/la.measure", open = "rb", handle = h1) |>
readr::read_tsv() |>
dplyr::filter(measure_code %in% c("03", "04", "05", "06"))

# make this internal
# usethis::use_data(laus_measures, overwrite = TRUE)

laus_codes <- readr::read_tsv("https://download.bls.gov/pub/time.series/la/la.area") |>
laus_codes <- curl::curl("https://download.bls.gov/pub/time.series/la/la.area", open = "rb", handle = h2) |>
readr::read_tsv() |>
dplyr::mutate(state_code = substr(area_code, 3, 4)) |>
dplyr::left_join(dplyr::distinct(tidycensus::fips_codes, state_code, state), by = "state_code") |>
dplyr::filter(area_type_code %in% c("A", "F", "G", "H")) |>
Expand Down
4 changes: 2 additions & 2 deletions data-raw/make_neighborhood_weights.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ tract2nhood <- block2nhood |>
dplyr::mutate(weight = round(hh / sum(hh), 3)) |>
dplyr::ungroup() |>
dplyr::select(-hh) |>
dplyr::left_join(dplyr::distinct(cwi::xwalk, tract, tract_cog_fips), by = "tract") |>
dplyr::left_join(dplyr::distinct(cwi::xwalk, tract, tract_cog), by = "tract") |>
split(~city) |>
purrr::map(dplyr::select, town, name, geoid = tract, geoid_cog = tract_cog_fips, weight) |>
purrr::map(dplyr::select, town, name, geoid = tract, geoid_cog = tract_cog, weight) |>
purrr::map(janitor::remove_empty, "cols") |>
rlang::set_names(~paste(., "tracts", sep = "_"))

Expand Down
Binary file modified data/bridgeport_sf.rda
Binary file not shown.

0 comments on commit 20fb68f

Please sign in to comment.