-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrscript_return_level_nsif.R
58 lines (46 loc) · 1.55 KB
/
rscript_return_level_nsif.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
56
57
58
#!/usr/bin/env Rscript
args = commandArgs(trailingOnly=TRUE)
# args <- c(5, 30)
overwrite <- TRUE
library(tidyverse)
library(extRemes)
source("R/calc_return_level.R")
load("data/df_corr.RData")
df_corr <- df_corr %>%
dplyr::select(lon, lat, s0 = cwd_lue0_nSIF) %>% ## select which one to consider here!
arrange(lon) %>%
mutate(idx = 1:n()) %>%
mutate(chunk = rep(1:as.integer(args[2]), each = (nrow(.)/as.integer(args[2])), len = nrow(.)))
## split sites data frame into (almost) equal chunks
list_df_split <- df_corr_tmp %>%
group_by(chunk) %>%
group_split()
## retain only the one required for this chunk
df_corr_sub <- list_df_split[[as.integer(args[1])]]
##------------------------------------------------------------------------
## asdf
##------------------------------------------------------------------------
filn <- paste0("data/df_rl/df_rl_nSIF_ichunk_", args[1], "_", args[2], ".RData")
df_rl_diag <- df_corr_sub %>%
drop_na() %>%
group_by(lon) %>%
nest() %>%
mutate(ilon = as.integer((lon + 179.975)/0.05 + 1)) %>%
ungroup()
# ## xxx debug
# filn <- paste0("data/df_rl/df_rl_fet_ichunk_TEST.RData")
# df_rl_diag <- df_rl_diag %>%
# dplyr::filter(lon > 120 & lon < 121)
if (nrow(df_rl_diag)>0){
if (!file.exists(filn) || overwrite){
df <- df_rl_diag %>%
mutate(data = purrr::map2(ilon, data, ~calc_return_level(.x, .y))) %>%
unnest(data) %>%
dplyr::select(-ilon)
save(df, file = filn)
} else {
print(paste("File exists already: ", filn))
}
} else {
print("No data available for this chunk.")
}