-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrscript_get_data_sif_jj.R
59 lines (52 loc) · 1.82 KB
/
rscript_get_data_sif_jj.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
59
#!/usr/bin/env Rscript
args = commandArgs(trailingOnly=TRUE)
# args <- c(1, 30)
library(dplyr)
library(tidyr)
library(purrr)
library(lubridate)
library(magrittr)
library(tidync)
library(rbeni)
##------------------------------------------------------------------------
## Extract point data and construct separate nested time series data frame
## for each longitde slice
##------------------------------------------------------------------------
dir <- "~/data/gome_2_sif_downscaled/data_orig/"
fileprefix <- "GOME_JJ_dcSIF_005deg_8day_"
nclist <- paste0(dir, list.files(dir, pattern = paste0(fileprefix, ".*.nc"), recursive = TRUE))
outdir <- "~/data/gome_2_sif_downscaled/data_tidy/"
varnam <- "SIF"
lonnam <- "lon"
latnam <- "lat"
timenam <- "time"
timedimnam <- "time"
##------------------------------------------------------------------------
## split it up into chunks (total number of chunks provided by argument 2)
##------------------------------------------------------------------------
nchunk <- as.integer(args[2]) # 1000 # make sure this is consistent with the number of parallel jobs (job array!) in the submission script
# ## first round: all longitudes
# nlon <- 7200
# nrows_chunk <- ceiling(nlon/nchunk)
# ilat <- seq(1:nlon)
## second round
ilat <- 3961:4176
nlon <- length(ilat)
nrows_chunk <- ceiling(nlon/nchunk)
irow_chunk <- split(ilat, ceiling(seq_along(ilat)/nrows_chunk))
print("getting data for longitude indices:")
print(irow_chunk[[as.integer(args[1])]])
## create files for each longitude slice, containing full time series wrapped for each gridcell (latitude)
nclist_to_df(
nclist,
outdir = outdir,
fileprefix = fileprefix,
varnam = varnam,
ilon = irow_chunk[[as.integer(args[1])]],
lonnam = lonnam,
latnam = latnam,
timenam = timenam,
timedimnam = timedimnam,
ncores = "all",
single_basedate = TRUE
)