-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrscript_combine_df_whc.R
55 lines (42 loc) · 1.59 KB
/
rscript_combine_df_whc.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env Rscript
library(dplyr)
library(tidyr)
library(purrr)
library(magrittr)
library(multidplyr)
library(rlang)
source("R/extract_whc_byfil.R")
dir <- "data/df_whc_hires_chunks/"
filelist <- paste0(dir, list.files(dir, pattern = "df_whc_hires_chunk_.*.RData"))
## get all available cores
ncores <- parallel::detectCores()
if (ncores > 1){
cl <- multidplyr::new_cluster(ncores) %>%
multidplyr::cluster_library(c("dplyr", "tidyr", "magrittr")) %>%
multidplyr::cluster_assign(extract_whc_byfil = extract_whc_byfil)
## distribute to cores, making sure all data from a specific site is sent to the same core
df_whc <- tibble(ifil = filelist) %>%
multidplyr::partition(cl) %>%
dplyr::mutate(out = purrr::map( ifil,
~extract_whc_byfil(.))) %>%
collect() %>%
bind_rows()
} else {
## testing
df_whc <- purrr::map(as.list(filelist),
~extract_whc_byfil(.)) %>%
bind_rows()
}
save(df_whc, file = "~/data/mct_data/df_whc_hires_lasthope.RData")
## test plot
gg <- df_whc %>%
mutate(lon = round(lon, digits = 3), lat = round(lat, digits = 3)) %>%
plot_map3(varnam = "whc_top", lonmin = -80, lonmax = -60, latmin = -60, latmax = -35,
breaks = c(seq(0, 0.4, by = 0.05), 0.8, Inf),
spacing = "constant",
combine = FALSE,
colorscale = viridis::magma
)
gg$ggmap <- gg$ggmap + labs(title = "WHC", subtitle = "Topsoil, fraction")
cowplot::plot_grid(gg$ggmap, gg$gglegend, ncol = 2, rel_widths = c(1, 0.2))
>>>>>>> 0d8a9841fb687049b6d1577f3ab623f8c715f51c