edited parallel script

This commit is contained in:
Ben Varick 2024-04-03 11:48:00 -05:00
parent f22ee7b45b
commit 1a7a2bf3f8
Signed by: ben
SSH Key Fingerprint: SHA256:jWnpFDAcacYM5aPFpYRqlsamlDyKNpSj3jj+k4ojtUo
2 changed files with 12 additions and 9 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ api_keys/*
basemaps/* basemaps/*
.Rproj.user .Rproj.user
.Rhistory .Rhistory
other/districts_done.csv

View File

@ -119,10 +119,12 @@ county_focus <- str_to_upper(unique(WI_schools %>% pull(CTY_DIST)))
#county_focus <- c("VILAS", "BROWN") #county_focus <- c("VILAS", "BROWN")
#county_focus <- c("BROWN") #county_focus <- c("BROWN")
school_type_focus <- unique(WI_schools %>% filter(CTY_DIST %in% str_to_title(county_focus)) %>% pull(SCHOOLTYPE)) school_type_focus <- unique(WI_schools %>% pull(SCHOOLTYPE))
#school_type_focus <- unique(WI_schools %>% filter(CTY_DIST %in% str_to_title(county_focus)) %>% pull(SCHOOLTYPE))
#school_type_focus <- c("High School") #school_type_focus <- c("High School")
district_focus <- unique(WI_schools %>% filter(CTY_DIST %in% str_to_title(county_focus), SCHOOLTYPE %in% school_type_focus, !is.na(DISTRICT_NAME)) %>% pull(DISTRICT_NAME)) district_focus <- unique(WI_schools %>% pull(DISTRICT_NAME))
#district_focus <- unique(WI_schools %>% filter(CTY_DIST %in% str_to_title(county_focus), SCHOOLTYPE %in% school_type_focus, !is.na(DISTRICT_NAME)) %>% pull(DISTRICT_NAME))
#district_focus <- c("Madison Metropolitan") #district_focus <- c("Madison Metropolitan")
#district_focus <- c("Milwaukee") #district_focus <- c("Milwaukee")
#district_focus <- c("Charter") #district_focus <- c("Charter")
@ -157,10 +159,10 @@ for(county in county_focus) {
labs(title = paste0("Pedestrians/bicyclists under 18 years old hit by cars in ", labs(title = paste0("Pedestrians/bicyclists under 18 years old hit by cars in ",
str_to_title(county), str_to_title(county),
" County"), " County"),
caption = "crash data from UW TOPS lab - retrieved 3/2024 per direction of the WisDOT Bureau of Transportation Safety",
x = "Year", x = "Year",
y = "Number of crashes", y = "Number of crashes")
caption = "data from UW TOPS Laboratory") ggsave(file = paste0("~/temp/figures/crash_maps/Crash Maps/",
ggsave(file = paste0("figures/crash_maps/Crash Maps/",
str_to_title(county), str_to_title(county),
" County/_", " County/_",
str_to_title(county), str_to_title(county),
@ -251,7 +253,7 @@ districts_done <- read_csv(file = "other/districts_done.csv")
district_focus <- district_focus[! district_focus %in% districts_done$district] district_focus <- district_focus[! district_focus %in% districts_done$district]
generate_school_maps <- function(district) { generate_school_maps <- function(district) {
message(paste("***", district, "School District |", match(district, district_focus), "/271")) message(paste("***", district, "School District |", match(district, district_focus), "/", length(district_focus)))
options(ggmap.file_drawer = paste0("basemaps/districts/", district)) options(ggmap.file_drawer = paste0("basemaps/districts/", district))
dir.create(file_drawer(), recursive = TRUE, showWarnings = FALSE) dir.create(file_drawer(), recursive = TRUE, showWarnings = FALSE)
saveRDS(list(), file_drawer("index.rds")) saveRDS(list(), file_drawer("index.rds"))
@ -367,7 +369,7 @@ generate_school_maps <- function(district) {
xmax = bbox['right'] + (bbox['right']-bbox['left']) * 0.20) + xmax = bbox['right'] + (bbox['right']-bbox['left']) * 0.20) +
coord_sf(clip = "off") coord_sf(clip = "off")
ggsave(file = paste0("figures/crash_maps/Crash Maps/", ggsave(file = paste0("~/temp/figures/crash_maps/Crash Maps/",
str_to_title(school_data %>% pull(CTY_DIST)), str_to_title(school_data %>% pull(CTY_DIST)),
" County/", " County/",
school_data %>% pull(DISTRICT_NAME), school_data %>% pull(DISTRICT_NAME),
@ -390,7 +392,7 @@ generate_school_maps <- function(district) {
## generate maps in parallel ---- ## generate maps in parallel ----
mclapply(district_focus, mclapply(district_focus,
generate_school_maps, generate_school_maps,
mc.cores = 8, mc.cores = 12,
mc.cleanup = TRUE, mc.cleanup = TRUE,
mc.preschedule = TRUE, mc.preschedule = TRUE,
mc.silent = FALSE) mc.silent = FALSE)
@ -400,7 +402,7 @@ double_check <- list(NULL)
for(school in WI_schools$district_school) { for(school in WI_schools$district_school) {
school_data <- WI_schools %>% filter(district_school %in% school) school_data <- WI_schools %>% filter(district_school %in% school)
school_check <- data.frame(district_school = c(school), school_check <- data.frame(district_school = c(school),
exists = c(file.exists(paste0("figures/crash_maps/Crash Maps/", exists = c(file.exists(paste0("~/temp/figures/crash_maps/Crash Maps/",
str_to_title(school_data %>% pull(CTY_DIST)), str_to_title(school_data %>% pull(CTY_DIST)),
" County/", " County/",
school_data %>% pull(DISTRICT_NAME), school_data %>% pull(DISTRICT_NAME),