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

Potential bug when aggregate daily data during DJF #14

Closed matteodefelice closed 8 years ago

matteodefelice commented 8 years ago

I have a SYS4 forecast of temperature for Winter DJF (subsetted for years):

> str(fcst)
List of 6
 $ Variable           :List of 2
  ..$ varName: chr "tas"
  ..$ level  : NULL
  ..- attr(*, "use_dictionary")= logi TRUE
  ..- attr(*, "description")= chr "2 metre temperature @ Ground or water surface"
  ..- attr(*, "units")= chr "degrees Celsius"
  ..- attr(*, "longname")= chr "2-meter air temperature"
  ..- attr(*, "daily_agg_cellfun")= chr "none"
  ..- attr(*, "monthly_agg_cellfun")= chr "none"
  ..- attr(*, "verification_time")= chr "none"
 $ Data               : num [1:15, 1:9388, 1:35, 1:50] 18.7 17.1 18.4 19.6 19.1 ...
  ..- attr(*, "dimensions")= chr [1:4] "member" "time" "lat" "lon"
 $ xyCoords           :List of 2
  ..$ x: num [1:50] -12 -11.25 -10.5 -9.75 -9 ...
  ..$ y: num [1:35] 32.2 33 33.7 34.5 35.2 ...
  ..- attr(*, "projection")= chr "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"
 $ Dates              :List of 2
  ..$ start: chr [1:9388] "1983-12-01 00:00:00 GMT" "1983-12-01 06:00:00 GMT" "1983-12-01 12:00:00 GMT" "1983-12-01 18:00:00 GMT" ...
  ..$ end  : chr [1:9388] "1983-12-01 00:00:00 GMT" "1983-12-01 06:00:00 GMT" "1983-12-01 12:00:00 GMT" "1983-12-01 18:00:00 GMT" ...
  ..- attr(*, "subset")= chr "subsetYears"
  ..- attr(*, "season")= num [1:3] 12 1 2
 $ InitializationDates: chr [1:26] "1983-11-01 00:00:00 GMT" "1984-11-01 00:00:00 GMT" "1985-11-01 00:00:00 GMT" "1986-11-01 00:00:00 GMT" ...
 $ Members            : chr [1:15] "Member_1" "Member_2" "Member_3" "Member_4" ...
 - attr(*, "dataset")= chr "System4_seasonal_15"
 - attr(*, "source")= chr "ECOMS User Data Gateway"
 - attr(*, "URL")= chr "<http://meteo.unican.es/trac/wiki/udg/ecoms>"

When I perform the following operation:

  fcst_tas = aggregateGrid(fcst, aggr.d = list(FUN = mean))

the order of the time vector is broken:

> fcst_tas$Dates$start[1:100]
  [1] "1984-01-01 00:00:00 GMT" "1984-01-02 00:00:00 GMT" "1984-01-03 00:00:00 GMT"
  [4] "1984-01-04 00:00:00 GMT" "1984-01-05 00:00:00 GMT" "1984-01-06 00:00:00 GMT"
  [7] "1984-01-07 00:00:00 GMT" "1984-01-08 00:00:00 GMT" "1984-01-09 00:00:00 GMT"
 [10] "1984-01-10 00:00:00 GMT" "1984-01-11 00:00:00 GMT" "1984-01-12 00:00:00 GMT"
 [13] "1984-01-13 00:00:00 GMT" "1984-01-14 00:00:00 GMT" "1984-01-15 00:00:00 GMT"
 [16] "1984-01-16 00:00:00 GMT" "1984-01-17 00:00:00 GMT" "1984-01-18 00:00:00 GMT"
 [19] "1984-01-19 00:00:00 GMT" "1984-01-20 00:00:00 GMT" "1984-01-21 00:00:00 GMT"
 [22] "1984-01-22 00:00:00 GMT" "1984-01-23 00:00:00 GMT" "1984-01-24 00:00:00 GMT"
 [25] "1984-01-25 00:00:00 GMT" "1984-01-26 00:00:00 GMT" "1984-01-27 00:00:00 GMT"
 [28] "1984-01-28 00:00:00 GMT" "1984-01-29 00:00:00 GMT" "1984-01-30 00:00:00 GMT"
 [31] "1984-01-31 00:00:00 GMT" "1984-02-01 00:00:00 GMT" "1984-02-02 00:00:00 GMT"
 [34] "1984-02-03 00:00:00 GMT" "1984-02-04 00:00:00 GMT" "1984-02-05 00:00:00 GMT"
 [37] "1984-02-06 00:00:00 GMT" "1984-02-07 00:00:00 GMT" "1984-02-08 00:00:00 GMT"
 [40] "1984-02-09 00:00:00 GMT" "1984-02-10 00:00:00 GMT" "1984-02-11 00:00:00 GMT"
 [43] "1984-02-12 00:00:00 GMT" "1984-02-13 00:00:00 GMT" "1984-02-14 00:00:00 GMT"
 [46] "1984-02-15 00:00:00 GMT" "1984-02-16 00:00:00 GMT" "1984-02-17 00:00:00 GMT"
 [49] "1984-02-18 00:00:00 GMT" "1984-02-19 00:00:00 GMT" "1984-02-20 00:00:00 GMT"
 [52] "1984-02-21 00:00:00 GMT" "1984-02-22 00:00:00 GMT" "1984-02-23 00:00:00 GMT"
 [55] "1984-02-24 00:00:00 GMT" "1984-02-25 00:00:00 GMT" "1984-02-26 00:00:00 GMT"
 [58] "1984-02-27 00:00:00 GMT" "1984-02-28 00:00:00 GMT" "1984-02-29 00:00:00 GMT"
 [61] "1983-12-01 00:00:00 GMT" "1983-12-02 00:00:00 GMT" "1983-12-03 00:00:00 GMT"
 [64] "1983-12-04 00:00:00 GMT" "1983-12-05 00:00:00 GMT" "1983-12-06 00:00:00 GMT"
 [67] "1983-12-07 00:00:00 GMT" "1983-12-08 00:00:00 GMT" "1983-12-09 00:00:00 GMT"
 [70] "1983-12-10 00:00:00 GMT" "1983-12-11 00:00:00 GMT" "1983-12-12 00:00:00 GMT"
 [73] "1983-12-13 00:00:00 GMT" "1983-12-14 00:00:00 GMT" "1983-12-15 00:00:00 GMT"
 [76] "1983-12-16 00:00:00 GMT" "1983-12-17 00:00:00 GMT" "1983-12-18 00:00:00 GMT"
 [79] "1983-12-19 00:00:00 GMT" "1983-12-20 00:00:00 GMT" "1983-12-21 00:00:00 GMT"
 [82] "1983-12-22 00:00:00 GMT" "1983-12-23 00:00:00 GMT" "1983-12-24 00:00:00 GMT"
 [85] "1983-12-25 00:00:00 GMT" "1983-12-26 00:00:00 GMT" "1983-12-27 00:00:00 GMT"
 [88] "1983-12-28 00:00:00 GMT" "1983-12-29 00:00:00 GMT" "1983-12-30 00:00:00 GMT"
 [91] "1983-12-31 00:00:00 GMT" "1985-01-01 00:00:00 GMT" "1985-01-02 00:00:00 GMT"
 [94] "1985-01-03 00:00:00 GMT" "1985-01-04 00:00:00 GMT" "1985-01-05 00:00:00 GMT"
 [97] "1985-01-06 00:00:00 GMT" "1985-01-07 00:00:00 GMT" "1985-01-08 00:00:00 GMT"
[100] "1985-01-09 00:00:00 GMT"
jbedia commented 8 years ago

Hi Matteo. Thanks for reporting. Can you send me the fcst object to try to reproduce the problem?

matteodefelice commented 8 years ago

You can download a subsetted version here: https://www.dropbox.com/s/5r09kn44suoh59v/fcst-test-01.Rdata?dl=0

matteodefelice commented 8 years ago

Any news on this? I am just asking because I should work on a workaround to compute the DJF! (Sorry to push you)

jbedia commented 8 years ago

Hi Matteo, sorry for my slow reaction with this issue. It is now fixed. Note the addition of line 199, of critical importance when using tapply with time factors as INDEX! Just let me know if it is working properly by closing the issue. Thanks for reporting!

matteodefelice commented 8 years ago

Now it seems working correctly.