SantanderMetGroup / downscaleR

An R package for climate data bias correction and downscaling (part of the climate4R bundle)
https://github.com/SantanderMetGroup/climate4R
GNU General Public License v3.0
103 stars 59 forks source link

Error in grid$Data[i, , ind.NN.y[k, l], ind.NN.x[k, l]] : incorrect number of dimensions #89

Open catorpar opened 2 years ago

catorpar commented 2 years ago

Hello,

I'm trying to conduct a bias correction but I'm getting the following error:

Error in grid$Data[i, , ind.NN.y[k, l], ind.NN.x[k, l]] : incorrect number of dimensions

I used loadeR to upload the observed and GCM datasets, then defined the x, y and newdata variables and run the biasCorrection function as indicated by example, and that's when the error occurs.

`obsdata <- "~/Future Climate Analysis/Observed" Obs <- loadStationData(dataset = obsdata, var="precip", stationID = NULL) gcmdata <- "~Future Climate Analysis/GCM" GCM <- loadStationData(dataset = gcmdata, var="precip", stationID = NULL) ObsTrain <- subsetGrid(Obs,years = 2006:2010, station.id = "26130570") GCMTrain <- subsetGrid(GCM,years = 2006:2010, station.id = "cam_44") GCMTest <- subsetGrid(GCM,years= 2011:2015, station.id = "cam_44") x <- ObsTrain y <- GCMTrain newdata <- GCMTest

biasCorrection(x, y, newdata = newdata, precipitation = TRUE, method = "eqm", window=NULL, wet.threshold = 0.1, join.members = TRUE) ` Attached you can find the files I'm using to complete the bias correction.

GCM.zip Observed.zip

Any help will be greatly appreciate it.

Camilo

dsys2003 commented 2 years ago

If you want to use biasCorrection, you must use aggr.d or aggr.m, this is a bug.

durutti commented 2 years ago

For me, the version that doesn't give the error when using locations is downscaleR-3.3.2. So you can install it locally until the bug is fixed

miturbide commented 2 years ago

We have included a step in biasCorrection to ensure the correspondence of dates between observed and simulated data in the training period. However, this new implementation (in the transformeR package) was not adapted to single station data in its first version... it is now, in the development version of transformeR.

You can install this version as follows:

library(devtools) install_github("SantanderMetGroup/transformeR@devel")

durutti commented 2 years ago

Yes it works now !!! I think a minor change is needed in line 8 in setGridDates.asPOSIXlt if (length(strsplit(ref, "-")[[1]]) == 3) chnage to if (length(strsplit(as.character(ref), "-")[[1]]) == 3)

example

d<-as.POSIXlt(as.Date('2000-1-1')) s<-strsplit(d, "-") Error in strsplit(d, "-") : non-character argument

s<-strsplit(as.character(d), "-")

length(s[[1]])==3 [1] TRUE

Thank you very much for your efforts

miturbide commented 2 years ago

Thanks durutti, good point. Line 8 has been updated in the devel branch following your suggestion. Now the function works with date class objects too.