@@ -13,21 +13,25 @@ library(purrr)
1313library(arrow )
1414library(clustermq )
1515
16+ root_dir <- here :: here(" workflows/irrigation-statewide" )
17+ cfg <- config :: get(
18+ file = file.path(root_dir , " config_paths.yml" ),
19+ config = " default"
20+ )
21+
1622n_workers <- as.integer(Sys.getenv(" CLUSTERMQ_N_JOBS" , " 20" ))
1723walltime <- " 02:00:00"
1824
19- cimis_root <- Sys.getenv( " CIMIS_DIR " , " /projectnb/dietzelab/ccmmf/data_raw/cimis/cimis " )
20-
21- outdir <- " _results_v2/ daily-raw"
25+ cimis_root <- cfg [[ " cimis_dir " ]]
26+ preprocess_dir <- cfg [[ " cimis_preprocess_dir " ]]
27+ outdir <- file.path( preprocess_dir , " daily-raw" )
2228dir.create(outdir , recursive = TRUE , showWarnings = FALSE )
2329
24- W <- readRDS(" _results_v2/spatial_weights.rds" )
30+ W <- readRDS(file.path(preprocess_dir , " spatial_weights.rds" ))
31+ weights_alt <- file.path(preprocess_dir , " spatial_weights_alt.rds" )
2532
2633cimis_manifest <- " cimis_files.txt"
27- years <- seq(
28- as.integer(Sys.getenv(" START_YEAR" , " 2015" )),
29- as.integer(Sys.getenv(" END_YEAR" , " 2024" ))
30- )
34+ years <- seq(as.integer(cfg [[" year1" ]]), as.integer(cfg [[" year2" ]]))
3135if (! file.exists(cimis_manifest )) {
3236 get_cimis_files <- function (year ) {
3337 ydir <- file.path(cimis_root , year )
@@ -47,7 +51,7 @@ if (!file.exists(cimis_manifest)) {
4751}
4852
4953# Extract
50- process_file <- function (fname , W , outdir ) {
54+ process_file <- function (fname , W , outdir , weights_alt ) {
5155 day <- basename(dirname(fname ))
5256 month <- basename(dirname(dirname(fname )))
5357 year <- basename(dirname(dirname(dirname(fname ))))
@@ -66,7 +70,7 @@ process_file <- function(fname, W, outdir) {
6670 rsize <- terra :: size(r )
6771 if (rsize == 285600 ) {
6872 # Alternate size files -- use alternate weights
69- W <- readRDS(" _results_v2/spatial_weights_alt.rds " )
73+ W <- readRDS(weights_alt )
7074 } else if (rsize != 276000 ) {
7175 stop(" File " , fname , " has unexpected size " , rsize )
7276 }
@@ -99,8 +103,8 @@ process_file <- function(fname, W, outdir) {
99103cimis_long <- Q(
100104 fun = process_file ,
101105 fname = cimis_files ,
102- const = list (W = W , outdir = outdir ),
103- n_jobs = n_workers , # SGE array size -- persistent worker processes
106+ const = list (W = W , outdir = outdir , weights_alt = weights_alt ),
107+ n_jobs = n_workers , # SGE array size — persistent worker processes
104108 template = list (cores = 1 , walltime = walltime ),
105109 fail_on_error = FALSE
106110)
0 commit comments