expL <- rnorm(1:200)
dim(expL) <- c(member=10,lat = 4, lon = 5)
obsL <- c(rnorm(1:180),expL[1,,]*1.2)
dim(obsL) <- c(time = 10,lat = 4, lon = 5)
time_obsL <- paste(rep("01", 10), rep("01", 10), 1994 : 2003, sep = "-")
time_expL <- time_obsL[1]
lon <- seq(-1, 5, 1.5)
lat <- seq(30, 35, 1.5)
expLL <- CSTools::s2dv_cube(data = expL, lat = lat, lon = lon, 
                  Dates = list(start = time_expL, end = time_expL))
obsLL <- CSTools::s2dv_cube(data = obsL, lat = lat, lon = lon,
                  Dates = list(start = time_obsL, end = time_obsL))
region <- c(2, 3.5, 31.5, 33.5)
downscaled_field <- CSTools::CST_Analogs(expL = expLL, obsL = obsLL, 
                        region = region,
                         criteria = 'Local_dist')
downscaled_field <- CSTools::CST_Analogs(expL = expLL, obsL = obsLL, 
                        region = region,
                         lonVar = lon, latVar = lat,
                         criteria = 'Local_dist')
downscaled_field <- CSTools::Analogs(expL = expL, obsL = obsL,
                        region = region, time_obsL = time_obsL,
                        time_expL = time_expL,
                         lonVar = lon, latVar = lat,
                         criteria = 'Local_dist')
library(ClimProjDiags); library(multiApply); library(abind)
source("/esarchive/scratch/nperez/git/cstools/R/CST_Analogs.R")
downscaled_field <- CST_Analogs(expL = expLL, obsL = obsLL,
                        region = region,
                         criteria = 'Local_dist')

expVar <- rnorm(1:40)

dim(expVar) <- c(member = 10, lat = 2, lon = 2)
obsVar <- rnorm(1:40)
dim(obsVar) <- c(time = 10, lat = 2, lon = 2)
lonVar <- c(2.0, 3.5)
latVar <- c(31.5, 33.0)
expVar <- CSTools::s2dv_cube(data = expVar, lat = latVar, lon = lonVar,
                  Dates = list(start = time_expL, end = time_expL))
obsVar <- CSTools::s2dv_cube(data = obsVar, lat = latVar, lon = lonVar,
                  Dates = list(start = time_obsL, end = time_obsL))

region <- c(min(lonVar), max(lonVar), min(latVar), max(latVar))
downscaled_field <- CSTools::CST_Analogs(expL = expLL, obsL = obsLL, region = region,
      expVar = expVar, obsVar = obsVar, criteria = 'Local_dist')

downscaled_field <- CST_Analogs(expL = expLL, obsL = obsLL, region = region,
      expVar = expVar, obsVar = obsVar, criteria = 'Local_dist')
source("/esarchive/scratch/nperez/cstools/R/CST_Analogs.R")
library(ClimProjDiags)
library(multiApply)
res <- CST_Analogs(expL = expL, obsL = obsL, region = region,
      expVar = expVar, obsVar = obsVar, criteria = 'Local_dist') 

