Changes between Version 3 and Version 4 of udg/ecoms/RPackage/examples/drift


Ignore:
Timestamp:
Sep 3, 2014 6:16:16 PM (7 years ago)
Author:
juaco
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • udg/ecoms/RPackage/examples/drift

    v3 v4  
    11= Analysing model drift in South-western Iberia
    22
    3 We will take as reference for measuring the drift the lead-month 0 forecast (i.e. the July initializations)
     3In this practice, we will analyse the model drift by using the forecast of daily mean surface temperature for July 2001 considering 6 different forecast (lead) months, rfom January to June. The lead month 0 (i.e., the initialization of July itself) will be the reference from which we will compute the anomalies. In this example, we will consider the first member of the CFSv2 hindcast.
     4
     5
    46
    57{{{#!text/R
    6 > ref <- loadECOMS(dataset = "CFSv2_seasonal_16", var = "tas", lonLim = c(-10,-1), latLim = c(36,40), season = 7, years = 2006, leadMonth = 0)
     8> # The selection of leadMonth = 0 will give a NOTE on screen:
     9> ref <- loadECOMS(dataset = "CFSv2_seasonal_16", var = "tas", members = 1, lonLim = c(-10,-1), latLim = c(36,40), season = 7, years = 2006, leadMonth = 0, time = "DD")
     10[2014-09-03 17:50:20] Defining homogeneization parameters for variable "tas"
     11NOTE: daily mean will be calculated from the 6-h model output
     12NOTE: 'leadMonth = 0' selected
     13[2014-09-03 17:50:20] Defining geo-location parameters
     14[2014-09-03 17:50:20] Defining initialization time parameters
     15[2014-09-03 17:50:26] Retrieving data subset ...
     16[2014-09-03 17:50:31] Done
    717> plotMeanField(ref)
    8 > ref.field <- apply(ref$Data, MARGIN = c(4,3), FUN = mean, na.rm = TRUE)
     18> title(main = "Lead month 0 forecast of July 2001")
     19> # This is the spatial mean of the reference field
     20> ref.field <- apply(ref$Data, MARGIN = c(3,2), FUN = mean, na.rm = TRUE)
    921}}}
    1022
    11 
    12 [[Image(image-20140902-201518.png)]]
     23[[Image(image-20140903-175339.png)]]
    1324
    1425
     
    1829{{{#!text/R
    1930> cfs.list <- lapply(1:6, function(lead.month) {
    20       loadECOMS(dataset = "CFSv2_seasonal_16", var = "tas", lonLim = c(-10,-1), latLim = c(36,40), season = 7, years = 2006, leadMonth = lead.month)
     31      loadECOMS(dataset = "CFSv2_seasonal_16", var = "tas", members = 1, lonLim = c(-10,-1), latLim = c(36,40), season = 7, years = 2006, leadMonth = lead.month, time = "DD")
    2132})
    2233}}}
    2334
    24 In order to visualize the departures of each lead month from the reference in the same range of values, we will use the `spplot` method for plotting spatial objects of the library `sp`. To this aim, we will first compute the multi-member spatial mean for each lead month forecast, and then we will arrange the data in a matrix of 6 columns (one for each month), and x*y coordinates rows:
     35In order to visualize the departures of each lead month from the reference in the same range of values, we will use the `spplot` method for plotting spatial objects of the library `sp`. To this aim, we will first compute the multi-member spatial mean for each lead month forecast, and then we will arrange the data in a matrix of 6 columns (one for each month), and x * y rows, as follows:
    2536
    2637{{{#!text/R
     38> # The library sp needs to be installed to do this example:
    2739> require(sp)
     40Loading required package: sp
    2841> # Matrix of anomalies between lead month and reference
    2942> aux.mat <- matrix(ncol = length(cfs.list), nrow = length(ref$xyCoords$x)*length(ref$xyCoords$y))
    30 + for (i in 1:length(cfs.list)) {
    31 +       mm.field <- apply(cfs.list[[i]]$Data, MARGIN = c(4,3), FUN = mean, na.rm = TRUE)
     43> for (i in 1:length(cfs.list)) {
     44+       mm.field <- apply(cfs.list[[i]]$Data, MARGIN = c(3,2), FUN = mean, na.rm = TRUE)
    3245+       aux.mat[ ,i] <- mm.field - ref.field
    3346+ }
    3447> # 2D coordinates
    3548> xy <- expand.grid(ref$xyCoords$x, ref$xyCoords$y)
     49> # This step ensures regularity of the CFS grid, which is not perfectly regular:
    3650> xy.coords <- coordinates(points2grid(points = SpatialPoints(xy), tolerance = .003))
     51> # Now we create a data.frame with the coordinates X-Y in the first two columns and the mean anomalies in the next 6 columns:
    3752> df <- cbind.data.frame(xy.coords, aux.mat)
    3853> names(df) <- c("x","y",paste("LeadMonth_",1:6, sep = ""))
     
    4156 $ x          : num  -10.31 -9.38 -8.44 -7.5 -6.56 ...
    4257 $ y          : num  40.2 40.2 40.2 40.2 40.2 ...
    43  $ LeadMonth_1: num  0.0398 0.0691 0.1427 0.116 0.1935 ...
    44  $ LeadMonth_2: num  0.386 0.451 0.472 0.311 0.161 ...
    45  $ LeadMonth_3: num  0.0428 0.0787 0.0707 -0.125 -0.2751 ...
    46  $ LeadMonth_4: num  0.261 0.258 0.131 -0.177 -0.464 ...
    47  $ LeadMonth_5: num  0.0576 0.154 0.1327 -0.1282 -0.3963 ...
    48  $ LeadMonth_6: num  0.0789 0.192 0.0989 -0.2667 -0.6457 ...
    49 > Conversion of the data.frame to a Spatial gridded object:
     58 $ LeadMonth_1: num  0.0596 0.1601 0.5955 0.9068 1.2601 ...
     59 $ LeadMonth_2: num  -0.1215 0.0509 0.3622 0.5444 0.6977 ...
     60 $ LeadMonth_3: num  -0.48 -0.359 -0.402 -0.693 -0.967 ...
     61 $ LeadMonth_4: num  0.22303 0.27295 0.23869 0.04764 -0.00855 ...
     62 $ LeadMonth_5: num  -1.212 -0.986 -0.682 -0.587 -0.584 ...
     63 $ LeadMonth_6: num  -1.314 -0.732 -0.32 -0.5 -0.98 ...
    5064> coordinates(df) <- c(1,2)
     65> gridded(df) <- TRUE
    5166> class(df)
    5267[1] "SpatialPixelsDataFrame"
     
    5570}}}
    5671
    57 In the next lines we use the `spplot` method of package `sp`, generating a lattice-type map. In first place, we will also load a `SpatialLines` dataset remotely stored at Santander Met Group server, in order to represent the grographical lines in the lattice map generated:
     72In the next lines we use apply the `spplot` method of package `sp`, generating a lattice-type map. In first place, we will also load a `SpatialLines` dataset remotely stored at Santander Met Group server, in order to represent the coastline in the lattice map generated as a geographical reference:
    5873
    5974{{{#!text/R
     
    6277  wlines
    6378> l1 <- list("sp.lines", wlines)
    64 > spplot(df, as.table = TRUE, col.regions = colorRampPalette(c("blue","white","red")), at = seq(-2.5,2.5,.25), scales = list(draw = TRUE), sp.layout = list(l1))
     79> spplot(df, as.table = TRUE, col.regions = colorRampPalette(c("blue","white","red")), at = seq(-5.25,5.25,.25), scales = list(draw = TRUE), sp.layout = list(l1))
    6580}}}
    6681
    67 [[Image(image-20140903-171550.png)]]
     82[[Image(image-20140903-180503.png)]]
    6883
    6984
    70 The results show how a increasing lead month leads to a negative bias of the forecast, demonstrating that the mean state of a variable of a forecast is not stationary through time.
     85The results show how a increasing lead month leads to a negative bias of the forecast, demonstrating that the mean state of a variable of a forecast is not stationary along the runtime dimension.
     86
     87Finally, we display the spatial mean of the anomalies w.r.t. the reference for each lead month considered using a barplot:
     88
     89{{{#!text/R
     90> barplot(colMeans(df@data), names.arg = abbreviate(names(df)), xlab = "lead month", ylab = "anomaly (ºC)")
     91> title(main = "Mean forecast bias w.r.t. the lead-month 0 initialization")
     92> mtext("Member 1")
     93}}}
     94
     95[[Image(image-20140903-181520.png)]]
     96