Hi @jhardenberg and @silvia,
Allowing CST_RFWeights work on s2dv_cube objects, the users will be able to download WorldClim in R and compute the weighs:
library(CSTools); library(raster); library(s2dv)
worldclim <- getData("worldclim", var = "prec", res = 0.5, lon = 5, lat = 45)
wc_month1 <- crop(worldclim[[1]], extent(3.5, 11.5, 41.5, 49.5))
xy <- xyFromCell(wc_month1, 1:length(wc_month1))
lons <- unique(xy[,1])
lats <- unique(xy[,2])
wc_data <- as.array(wc_month1)
dim(wc_data) <- c(lat = length(lats), lon = length(lons))
worldclim <- s2dv_cube(data = wc_data, lon = lons, lat = lats, Datasets = 'WorldClim')
PlotEquiMap(wc_data, lon = lons, lat = lats, filled.continents = FALSE)
source("/esarchive/scratch/nperez/git/cstools/R/CST_RFWeights.R")
weight1 <- CST_RFWeights(worldclim, nf = 4)
In the current fix, I don't understand the difference between 'latin' vs 'lat' and 'lonin' vs 'lon'. This may be very easy to solve by @jhardenberg.
This fix could be also improved by returning the final longitudes and latitudes.
Please, take a look and fix it or let me know if something is wrong.
Cheers,
Núria