metno / esd

An R-package designed for climate and weather data analysis, empirical-statistical downscaling, and visualisation.
88 stars 30 forks source link

Getting error when setting biascorrect=TRUE #206

Closed javakh closed 7 years ago

javakh commented 7 years ago

Hii, Getting the following error:

ds=DS(y1,EOF(combine(x1,z1)),biascorrect=T) Error in apply(coredata(X), 2, mean, na.rm = TRUE) : dim(X) must have a positive length However ds=DS.comb(y1,EOF(combine(x1,z1))) does not giving such error.

[Here y1: observed data; x1: reanalysis,z1: GCM data]

str(y1) ‘zoo’ series from 1951 to 2005 Data: atomic [1:55] 215 261 305 228 287 ...

  • attr(*, "unit")= chr "mm"
  • attr(*, "variable")= chr "pr"
  • attr(*, "history")=List of 3 ..$ call :List of 1 .. ..$ : language station.subset(x, it = it, is = 1, verbose = verbose) ..$ timestamp: chr "Mon Dec 19 19:10:02 2016" ..$ session :List of 3 .. ..$ R.version : chr "R version 3.2.3 (2015-12-10)" .. ..$ esd.version: chr "esd_1.5" .. ..$ platform : chr "x86_64-w64-mingw32/x64 (64-bit)"
  • attr(*, "standard.error")=‘zoo’ series from 1951 to 2005 Data: num [1:55] 205 199 238 295 190 ... Index: num [1:55] 1951 1952 1953 1954 1955 ... Index: num [1:55] 1951 1952 1953 1954 1955 ... str(x1) ‘zoo’ series from 1951 to 2005 Data: num [1:55, 1:12] 69.7 74.1 76.5 78.9 72.1 ...
  • attr(*, "variable")= chr "rhum"
  • attr(*, "longname")= chr "Monthly Mean of Relative Humidity"
  • attr(*, "units")= chr "%"
  • attr(*, "longitude")= num [1:4(1d)] 80 82.5 85 87.5
  • attr(*, "greenwich")= logi FALSE
  • attr(*, "latitude")= num [1:3(1d)] 22.5 25 27.5
  • attr(*, "level")= num 850
  • attr(*, "levelUnit")= chr "millibar"
  • attr(*, "file")= chr "rhum.mon.mean.nc"
  • attr(*, "title")= chr "monthly mean rhum from the NCEP Reanalysis"
  • attr(*, "source")= chr "monthly"
  • attr(*, "experiment_id")= chr "rhum"
  • attr(*, "timeunit")= chr "month"
  • attr(*, "type")= chr "mean"
  • attr(*, "URL")= chr "http://climexp.knmi.nl/"
  • attr(*, "call")= language retrieve.ncdf4(ncfile = "rhum.mon.mean.nc", lev = 850)
  • attr(*, "institution")= logi NA
  • attr(*, "reference")= logi NA
  • attr(*, "history")=List of 3 ..$ call :List of 1 .. ..$ : language subset.field(ncep_jjas, it = 1951:2005) ..$ timestamp: chr "Mon Dec 19 19:11:02 2016" ..$ session :List of 3 .. ..$ R.version : chr "R version 3.2.3 (2015-12-10)" .. ..$ esd.version: chr "esd_1.5" .. ..$ platform : chr "x86_64-w64-mingw32/x64 (64-bit)"
  • attr(*, "dimensions")= int [1:3] 4 3 55 Index: num [1:55] 1951 1952 1953 1954 1955 ... str(z1) ‘zoo’ series from 1951 to 2005 Data: num [1:55, 1:12] 63.4 72.9 78 71.8 74.4 ...
  • attr(*, "variable")= chr "hur"
  • attr(*, "longname")= chr "Relative Humidity"
  • attr(*, "units")= chr "%"
  • attr(*, "longitude")= num [1:4] 80 82.5 85 87.5
  • attr(*, "greenwich")= logi FALSE
  • attr(*, "latitude")= num [1:3] 22.5 25 27.5
  • attr(*, "level")= num 85000
  • attr(*, "levelUnit")= chr "Pa"
  • attr(*, "calendar")= chr "noleap"
  • attr(*, "file")= chr "E:/NorESM/hur_Amon_NorESM1-M_historical_r1i1p1_195001-200512.nc"
  • attr(*, "title")= chr "NorESM1-M model output prepared for CMIP5 historical"
  • attr(*, "source")= chr "CMIP5"
  • attr(*, "model_id")= chr "NorESM1-M"
  • attr(*, "experiment_id")= chr "historical"
  • attr(*, "realization")= int 1
  • attr(*, "timeunit")= chr "month"
  • attr(*, "type")= chr "model"
  • attr(*, "URL")= chr "http://climexp.knmi.nl/"
  • attr(*, "call")= language retrieve.ncdf4(ncfile = ncfile, path = path, param = param, lon = ..1, lat = ..2, lev = 85000, verbose = verbose)
  • attr(*, "institution")= logi NA
  • attr(*, "reference")= logi NA
  • attr(*, "history")=List of 3 ..$ call :List of 1 .. ..$ : language subset.field(gcm_jjas, it = 1951:2005) ..$ timestamp: chr "Mon Dec 19 19:14:33 2016" ..$ session :List of 3 .. ..$ R.version : chr "R version 3.2.3 (2015-12-10)" .. ..$ esd.version: chr "esd_1.5" .. ..$ platform : chr "x86_64-w64-mingw32/x64 (64-bit)"
  • attr(*, "dimensions")= int [1:3] 4 3 55 Index: num [1:55] 1951 1952 1953 1954 1955 ...

How to solve this problem???

Thanks.

brasmus commented 7 years ago

Try setting verbose=TRUE, splitting up the commands and check the individual bits. Eg use diagnose and plot. Check all the bits.

javakh commented 7 years ago

This is the results I have obtained: ceof=EOF(combine(x1,z1))

ds=DS.comb(y1,ceof,biascorrect=T,verbose=T) [1] "DS.comb" [1] "Bias correcion - bias-fix common EOF" Error in apply(coredata(X), 2, mean, na.rm = TRUE) : dim(X) must have a positive length diagnose(ceof) $mean.diff [,1] [,2] [,3] [,4] [,5] CMIP5 4.104444e-17 3.845015e-17 5.260717e-17 1.246739e-16 1.235177e-17 [,6] [,7] [,8] [,9] [,10] CMIP5 6.135433e-17 7.74108e-18 3.892138e-16 2.318954e-16 4.828403e-16 [,11] [,12] CMIP5 8.430611e-17 1.109922e-15

$sd.ratio [,1] [,2] [,3] [,4] [,5] [,6] [,7] CMIP5 0.2877986 0.138918 0.1065822 0.1525996 0.08791121 0.139281 0.1166833 [,8] [,9] [,10] [,11] [,12] CMIP5 0.04182473 0.1882926 0.1322217 0.1959158 0.2983779

$autocorr.ratio [,1] [,2] [,3] [,4] [,5] [,6] [,7] CMIP5 -0.7370777 -0.7925867 0.8598023 0.95957 -0.7795867 -0.9219605 -0.8632522 [,8] [,9] [,10] [,11] [,12] CMIP5 0.9605013 0.9902146 -0.927463 -0.8818522 0.9366334

$common.period [1] "1951-01-01" "2005-01-01"

$sd0 1.y 2.y 3.y 4.y 5.y 6.y 7.y 0.10748277 0.08879543 0.10096439 0.10278856 0.09170408 0.08877393 0.10137559 8.y 9.y 10.y 11.y 12.y x.1 x.2 0.09817552 0.08576234 0.10199616 0.08527407 0.10781237 0.08346241 0.10312076 x.3 x.4 x.5 x.6 x.7 x.8 x.9 0.09123985 0.08917976 0.10054293 0.10313927 0.09078275 0.09423420 0.10565671 x.10 x.11 x.12 0.09008497 0.10605117 0.08303620

$calibrationdata [1] "monthly"

attr(,"variable") [1] "rhum" attr(,"evaluation_period") [1] "1951-01-01-2005-01-01" attr(,"history") attr(,"history")$call attr(,"history")$call[[1]] diagnose.comb.eof(x, ...)

attr(,"history")$timestamp [1] "Tue Dec 20 07:38:23 2016"

attr(,"history")$session attr(,"history")$session$R.version [1] "R version 3.2.3 (2015-12-10)"

attr(,"history")$session$esd.version [1] "esd_1.5"

attr(,"history")$session$platform [1] "x86_64-w64-mingw32/x64 (64-bit)"

attr(,"class") [1] "diagnose" "comb" "eof" "list"

image

javakh commented 7 years ago

I suspect the problem may occur in DS.eof() function which is used inside DS.comb()

ds <- DS.eof(ceof,y,verbos=T) [1] "DS.eof" [1] "DS.pca" [1] "zoo" [1] "Predictor is a zoo object" [1] "DS.pca" [1] "eof" "zoo" [1] "Predictor is OK - an EOF object" [1] "Make the Ip lool like PCAs before downscaling" [1] "DS.pca" [1] "eof" "zoo" [1] "Predictor is OK - an EOF object" [1] "matchdate: t = [ 1951 - 2005 ], it= [ 1951 - 2005 ]" [1] "1951-01-01" "1951-01-01" "1975-05-06" [1] "select 55 dates" [1] "1951-01-01" "1952-01-01" "1953-01-01" "1954-01-01" "1955-01-01" [6] "1956-01-01" "1957-01-01" "1958-01-01" "1959-01-01" "1960-01-01" [11] "1961-01-01" "1962-01-01" "1963-01-01" "1964-01-01" "1965-01-01" [16] "1966-01-01" "1967-01-01" "1968-01-01" "1969-01-01" "1970-01-01" [21] "1971-01-01" "1972-01-01" "1973-01-01" "1974-01-01" "1975-01-01" [26] "1976-01-01" "1977-01-01" "1978-01-01" "1979-01-01" "1980-01-01" [31] "1981-01-01" "1982-01-01" "1983-01-01" "1984-01-01" "1985-01-01" [36] "1986-01-01" "1987-01-01" "1988-01-01" "1989-01-01" "1990-01-01" [41] "1991-01-01" "1992-01-01" "1993-01-01" "1994-01-01" "1995-01-01" [46] "1996-01-01" "1997-01-01" "1998-01-01" "1999-01-01" "2000-01-01" [51] "2001-01-01" "2002-01-01" "2003-01-01" "2004-01-01" "2005-01-01" [1] "55 matching dates" [1] "matchdate: index(y)" [1] 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 [16] 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 [31] 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 [46] 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 [1] "matchdate: t = [ 1951 - 2005 ], it= [ 1951 - 2005 ]" [1] "1951-01-01" "1951-01-01" "1975-05-06" [1] "select 55 dates" [1] "1951-01-01" "1952-01-01" "1953-01-01" "1954-01-01" "1955-01-01" [6] "1956-01-01" "1957-01-01" "1958-01-01" "1959-01-01" "1960-01-01" [11] "1961-01-01" "1962-01-01" "1963-01-01" "1964-01-01" "1965-01-01" [16] "1966-01-01" "1967-01-01" "1968-01-01" "1969-01-01" "1970-01-01" [21] "1971-01-01" "1972-01-01" "1973-01-01" "1974-01-01" "1975-01-01" [26] "1976-01-01" "1977-01-01" "1978-01-01" "1979-01-01" "1980-01-01" [31] "1981-01-01" "1982-01-01" "1983-01-01" "1984-01-01" "1985-01-01" [36] "1986-01-01" "1987-01-01" "1988-01-01" "1989-01-01" "1990-01-01" [41] "1991-01-01" "1992-01-01" "1993-01-01" "1994-01-01" "1995-01-01" [46] "1996-01-01" "1997-01-01" "1998-01-01" "1999-01-01" "2000-01-01" [51] "2001-01-01" "2002-01-01" "2003-01-01" "2004-01-01" "2005-01-01" [1] "55 matching dates" [1] "matchdate: index(y)" [1] 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 [16] 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 [31] 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 [46] 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 [1] "match date for error" [1] "lm" [1] "Default" [1] "Prepare output data" [1] "PC 1 PC 2 PC 3 PC 4 PC 5 PC 6 PC 7" [1] "Predictor pattern" num [1:4, 1:3, 1:12] 0.336 0.33 0.293 0.234 0.326 ... d d
4 3 12 [1] 55 12 [1] "station" "field" "annual" "zoo"
[1] "eof" "zoo" [1] "--- DS.station ---" [1] "i= 1" [1] "station" "field" "annual" "zoo"
[1] "index" "class" "location" "variable" "unit"
[6] "longitude" "latitude" "altitude" "country" "longname"
[11] "station_id" "quality" "calendar" "source" "URL"
[16] "type" "aspect" "reference" "info" "method"
[21] "history"
[1] "The predictor is some kind of EOF-object" [1] " EOF " [1] "--- DS.default ---" [1] "index(y)" [1] 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 [16] 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 [31] 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 [46] 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 [1] "station" "field" "annual" "zoo"
[1] "eof" "zoo" Error: is.matrix(X) is not TRUE

However

is.matrix(ceof) [1] TRUE

This is contradictory.,

kajsamp commented 7 years ago

I fixed some bugs in the EOF.comb function that may have caused the problems that you describe. Can you update esd and try again?

Thanks, Kajsa