Skip to content

Commit 6c1086b

Browse files
committed
create Rsmall
1 parent f09d62f commit 6c1086b

4 files changed

+88
-1
lines changed

00_setup_and_funs.R

+16
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ path_temp_unzip <- "../pct-inputs/02_intermediate/x_temporary_files/unzip"
5151
path_outputs_national <- "../pct-outputs-national"
5252
path_outputs_regional_R <- "../pct-outputs-regional-R"
5353
path_outputs_regional_notR <- "../pct-outputs-regional-notR"
54+
path_outputs_regional_Rsmall <- "../pct-outputs-regional-Rsmall"
5455
path_scripts <- "../pct-scripts"
5556
path_shiny <- "../pct-shiny"
5657
path_codebooks <- "../pct-shiny/regions_www/www/static/02_codebooks"
@@ -144,3 +145,18 @@ init_outputs_national <- function(purpose, geography){
144145
assign("rnet_all_attributes", read_csv(file.path(path_temp_scenario, purpose, geography, "rnet_all_attributes.csv")), envir = .GlobalEnv)
145146
}
146147
}
148+
149+
150+
# Initiate R small dataset
151+
init_Rsmall <- function(purpose){
152+
if(purpose == "commute") {
153+
assign("c_codebook_small", read_csv(file.path(path_codebooks, purpose, "c_codebook_small.csv")), envir = .GlobalEnv)
154+
assign("od_l_rf_codebook_small", read_csv(file.path(path_codebooks, purpose, "od_l_rf_codebook_small.csv")), envir = .GlobalEnv)
155+
assign("rq_codebook_small", read_csv(file.path(path_codebooks, purpose, "rq_codebook_small.csv")), envir = .GlobalEnv)
156+
assign("z_codebook_small", read_csv(file.path(path_codebooks, purpose, "z_codebook_small.csv")), envir = .GlobalEnv)
157+
}
158+
if(purpose == "school") {
159+
assign("d_codebook_small", read_csv(file.path(path_codebooks, purpose, "d_codebook_small.csv")), envir = .GlobalEnv)
160+
assign("z_codebook_small", read_csv(file.path(path_codebooks, purpose, "z_codebook_small.csv")), envir = .GlobalEnv)
161+
}
162+
}

07a_build_master.R

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ purpose_private <- paste0(purpose, "_private")
99
geography <- "lsoa"
1010
init_region("pct_regions", geography, purpose) # Define region type and projection, import local authorities
1111
init_outputs_national(purpose, geography) # Load national data
12+
init_Rsmall(purpose) # Load R small codebooks
1213

1314

1415
#########################
@@ -30,8 +31,11 @@ for(k in 1:length(regions_tobuild)){
3031
#region_build_param$to_rebuild_rnet <- 0 # uncomment to forcibly skip rnet
3132
if (purpose=="commute") {
3233
source("07b.1_commute_build_region.R") # comment out to skip build entirely
34+
rsmall_maxdist <- 10
35+
source("07b.2_commute_Rsmall.R")
3336
} else if (purpose=="school") {
34-
source("07b.2_school_build_region.R") # comment out to skip build entirely
37+
source("07c.1_school_build_region.R") # comment out to skip build entirely
38+
source("07c.2_school_Rsmall.R")
3539
}
3640

3741
# WRITE REGION STATS FILE

07b.2_commute_Rsmall.R

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Create data directory if not there & start time
2+
if(!dir.exists(file.path(path_outputs_regional_Rsmall, purpose))) { dir.create(file.path(path_outputs_regional_Rsmall, purpose)) }
3+
if(!dir.exists(file.path(path_outputs_regional_Rsmall, purpose, geography))) { dir.create(file.path(path_outputs_regional_Rsmall, purpose, geography)) }
4+
if(!dir.exists(file.path(path_outputs_regional_Rsmall, purpose, geography, region))) { dir.create(file.path(path_outputs_regional_Rsmall, purpose, geography, region)) }
5+
6+
###########################
7+
### MAKE R SMALL OBJECTS
8+
###########################
9+
10+
c <- readRDS(file.path(path_outputs_regional_R, purpose, geography, region, "c.Rds"))
11+
c <- c[c_codebook_small$`Variable name`]
12+
saveRDS(c, (file.path(path_outputs_regional_Rsmall, purpose, geography, region, "c.Rds")) , version = 2)
13+
14+
l <- readRDS(file.path(path_outputs_regional_R, purpose, geography, region, "l.Rds"))
15+
l <- l[l@data$rf_dist_km<=rsmall_maxdist,]
16+
l <- l[od_l_rf_codebook_small$`Variable name`]
17+
saveRDS(l, (file.path(path_outputs_regional_Rsmall, purpose, geography, region, "l.Rds")) , version = 2)
18+
19+
rf <- readRDS(file.path(path_outputs_regional_R, purpose, geography, region, "rf.Rds"))
20+
rf <- rf[rf@data$rf_dist_km<=rsmall_maxdist,]
21+
rf <- rf[od_l_rf_codebook_small$`Variable name`]
22+
saveRDS(rf, (file.path(path_outputs_regional_Rsmall, purpose, geography, region, "rf.Rds")) , version = 2)
23+
24+
rq <- readRDS(file.path(path_outputs_regional_R, purpose, geography, region, "rq.Rds"))
25+
rq <- rq[rq@data$rf_dist_km<=rsmall_maxdist,]
26+
rq <- rq[rq_codebook_small$`Variable name`]
27+
saveRDS(rq, (file.path(path_outputs_regional_Rsmall, purpose, geography, region, "rq.Rds")) , version = 2)
28+
29+
z <- readRDS(file.path(path_outputs_regional_R, purpose, geography, region, "z.Rds"))
30+
z <- z[z_codebook_small$`Variable name`]
31+
saveRDS(z, (file.path(path_outputs_regional_Rsmall, purpose, geography, region, "z.Rds")) , version = 2)
32+
33+
## Can remove this code...could also delete those files locally
34+
if(file.exists(file.path(path_outputs_regional_R, purpose, geography, region, "rnet.Rds"))) {
35+
rnet <- readRDS(file.path(path_outputs_regional_R, purpose, geography, region, "rnet.Rds"))
36+
saveRDS(rnet, (file.path(path_outputs_regional_Rsmall, purpose, geography, region, "rnet.Rds")) , version = 2)
37+
# file.remove(file.path(path_outputs_regional_R, purpose, geography, region, "rnet.Rds"))
38+
}
39+
40+
41+

07c.2_school_Rsmall.R

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Create data directory if not there & start time
2+
if(!dir.exists(file.path(path_outputs_regional_Rsmall, purpose))) { dir.create(file.path(path_outputs_regional_Rsmall, purpose)) }
3+
if(!dir.exists(file.path(path_outputs_regional_Rsmall, purpose, geography))) { dir.create(file.path(path_outputs_regional_Rsmall, purpose, geography)) }
4+
if(!dir.exists(file.path(path_outputs_regional_Rsmall, purpose, geography, region))) { dir.create(file.path(path_outputs_regional_Rsmall, purpose, geography, region)) }
5+
6+
###########################
7+
### MAKE R SMALL OBJECTS
8+
###########################
9+
10+
d <- readRDS(file.path(path_outputs_regional_R, purpose, geography, region, "d.Rds"))
11+
d <- d[d_codebook_small$`Variable name`]
12+
saveRDS(d, (file.path(path_outputs_regional_Rsmall, purpose, geography, region, "d.Rds")) , version = 2)
13+
14+
z <- readRDS(file.path(path_outputs_regional_R, purpose, geography, region, "z.Rds"))
15+
z <- z[z_codebook_small$`Variable name`]
16+
saveRDS(z, (file.path(path_outputs_regional_Rsmall, purpose, geography, region, "z.Rds")) , version = 2)
17+
18+
## Can remove this code...could also delete those files locally
19+
if(file.exists(file.path(path_outputs_regional_R, purpose, geography, region, "rnet.Rds"))) {
20+
rnet <- readRDS(file.path(path_outputs_regional_R, purpose, geography, region, "rnet.Rds"))
21+
saveRDS(rnet, (file.path(path_outputs_regional_Rsmall, purpose, geography, region, "rnet.Rds")) , version = 2)
22+
# file.remove(file.path(path_outputs_regional_R, purpose, geography, region, "rnet.Rds"))
23+
}
24+
25+
26+

0 commit comments

Comments
 (0)