Compute() error target_dims = NULL
Hi @aho ,
I am trying to run my a script through Compute(), but I am stumbling on an issue. When on compute I give the target_dims
of lat = NULL
the script stops and the following error appears:
Error in FUN(X[[i]], ...) :
Parameter 'target_dims' must be one or a list of vectors of target dimension names for each data array input in the function 'fun'.
This doesn't appear if I use MultiApply(). I have also tried getting the lat directly in the function through the attr()
command, but apparently (I don't know why) when I launch the function all the attributes are deleted.
Here is an copy of the script I am trying to run (the source
files I use can be found here:
https://earth.bsc.es/gitlab/aaranyos/personal_scripts/-/blob/main/startR_calls_monthly.R
https://earth.bsc.es/gitlab/aaranyos/personal_scripts/-/blob/main/P_PET_Accum.R ).
library(startR)
library(multiApply)
library(s2dv)
library(CSTools)
library(ClimProjDiags)
library(easyVerification)
library(zoo)
library(SPEI)
library(TLMoments)
library(lmom)
library(lmomco)
source("~/Documents/SPEI_scripts/Scripts_Carlos/startR_calls_monthly.R")
source("~/Documents/SPEI_scripts/Scripts_Carlos/P_PET_Accum.R")
config <- list(
# Paths
output_path = '/esarchive/scratch/aaranyos/dcppA-hindcast/R_outputs/',
# Ensemble members
members = paste0('r',9:10,'i2p1f1'),
# Time periods
sdates = 1960,
# Regions
regions = list(lon_min = 50, lon_max = 60, lat_min = 50, lat_max = 60),
# SPEI Accumulation periods
spei_indices_months = list('3' = c(1,2,3,4,5,6,7,8,9,10,11,12)),
#Slurm specifics
ncores = 1, max_jobs=64, job_wallclock ='06:00:00')
retrieve = FALSE
##############################################
###########----- Load the data-----###########
##############################################
tmax <- startR_calls_monthly(variable = 'tasmax',
dataset = 'EC-Earth3',
lon_min = config$regions$lon_min, lon_max = config$regions$lon_max,
lat_min = config$regions$lat_min, lat_max = config$regions$lat_max,
fyears = 1,
members = config$members,
vers = '20200730',
config = config,
retrieve = retrieve)
tmin <- startR_calls_monthly(variable = 'tasmin',
dataset = 'EC-Earth3',
lon_min = config$regions$lon_min, lon_max = config$regions$lon_max,
lat_min = config$regions$lat_min, lat_max = config$regions$lat_max,
fyears = 1,
members = config$members,
vers = '20200730',
config = config,
retrieve = retrieve)
pr <- startR_calls_monthly(variable = 'pr',
dataset = 'EC-Earth3',
lon_min = config$regions$lon_min, lon_max = config$regions$lon_max,
lat_min = config$regions$lat_min, lat_max = config$regions$lat_max,
fyears = 1,
members = config$members,
vers = '20210309',
config = config,
retrieve = retrieve)
warnings()
if (identical(as.numeric(tmin$lat),as.numeric(tmax$lat)) & identical(as.numeric(tmin$lat),as.numeric(pr$lat)) &
identical(as.numeric(tmin$lon),as.numeric(tmax$lon)) & identical(as.numeric(tmin$lon),as.numeric(pr$lon))) {
lat <- tmax$lat
lon <- tmax$lon
} else {stop('Different lons or lats for the variables')}
year_dim <- 'sdate'
month_dim <- 'fmonth'
target_dims <- c(month_dim,year_dim)
output_dims <- list()
for (index in names(config$spei_indices_months)){
output_dims[[paste0('accum',index)]] <- c('fmonth','sdate')
}
###############################################
########----- PET and Accumulation-----########
###############################################
if (isTRUE(retrieve)){
accum <- multiApply::Apply(data = list(tasmin = tmin$data,
tasmax = tmax$data,
pr = pr$data,
lat = lat),
target_dims = list(tasmin = target_dims,
tasmax = target_dims,
pr = target_dims,
lat = NULL),
output_dims = output_dims,
fun = P_PET_Accum,
pet_method = 'hargreaves',
accum_scales = as.numeric(names(config$spei_indices_months)),
units_tas = tmin$units_tas,
units_pr = pr$units_pr,
year_dim = year_dim,
month_dim = month_dim,
ncores = config$ncores)
} else if (isFALSE(retrieve)){
step <- startR::Step(fun = P_PET_Accum,
target_dims = list(tasmin = target_dims,
tasmax = target_dims,
pr = target_dims,
lat = NULL), ##################### ISSUE ########################
output_dims = output_dims)
wf <- startR::AddStep(inputs = list(tasmin = tmin$data,
tasmax = tmax$data,
pr = pr$data,
lat = lat),
pet_method = 'hargreaves',
accum_scales = as.numeric(names(config$spei_indices_months)),
units_tas = tmin$units_tas,
units_pr = pr$units_pr,
year_dim = year_dim,
month_dim = month_dim,
step_fun = step)
accum <- startR::Compute(workflow = wf,
chunks = list(lon=1),
threads_load = config$ncores,
threads_compute = config$ncores,
cluster = list(queue_host = 'nord4',
queue_type = 'slurm',
temp_dir = '/gpfs/scratch/bsc32/bsc32480/startR_hpc/',
r_module = 'R/4.1.2-foss-2019b',
cores_per_job = config$ncores,
job_wallclock = config$job_wallclock,
max_jobs = config$max_jobs,
# extra_queue_params = list("#SBATCH --constraint='medmem'"),
bidirectional = FALSE,
polling_period = 10),
ecflow_suite_dir = '/home/Earth/aaranyos/Desktop/startR_local/',
wait = TRUE)
} else {stop('retrieve must be TRUE or FALSE')}
Thanks for your help.
Best,
Alvise