Changes between Version 1 and Version 2 of udg/ecoms/RPackage/examples/drift


Ignore:
Timestamp:
Sep 2, 2014 8:33:40 PM (7 years ago)
Author:
juaco
Comment:

--

Legend:

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

    v1 v2  
    1 First, we load the forecast of the target variable recursively for lead month values from 1 to 6 (i.e., the initializations from January to June)
     1= Analysing model drift in South-western Iberia
     2
     3We will take as reference for measuring the drift the lead-month 0 forecast (i.e. the July initializations)
     4
     5{{{#!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)
     7> plotMeanField(ref)
     8> ref.field <- apply(ref$Data, MARGIN = c(4,3), FUN = mean, na.rm = TRUE)
     9}}}
     10
     11
     12[[Image(image-20140902-201518.png)]]
     13
     14
     15Next, we will load the forecast of the target variable recursively for lead month values from 1 to 6 (i.e., the initializations from January to June). The different objects are arranged in a list:
     16
    217
    318{{{#!text/R
     
    722}}}
    823
    9 We will take as reference for measuring the drift the lead-month 0 forecast (i.e. the July initializations)
     24In 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:
    1025
    1126{{{#!text/R
    12 > ref <- loadECOMS(dataset = "CFSv2_seasonal_16", var = "tas", lonLim = c(-10,-1), latLim = c(36,40), season = 7, years = 2006, leadMonth = 0)
    13 > plotMeanField(ref)
     27> require(sp)
     28> # Matrix of anomalies between lead month and reference
     29> 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)
     32+       aux.mat[ ,i] <- mm.field - ref.field
     33+ }
     34> # 2D coordinates
     35> xy <- expand.grid(ref$xyCoords$x, ref$xyCoords$y)
     36> xy.coords <- coordinates(points2grid(points = SpatialPoints(xy), tolerance = .003))
     37> df <- cbind.data.frame(xy.coords, aux.mat)
     38> names(df) <- c("x","y",paste("LeadMonth_",1:6, sep = ""))
     39> str(df)
     40'data.frame':   55 obs. of  8 variables:
     41 $ x          : num  -10.31 -9.38 -8.44 -7.5 -6.56 ...
     42 $ 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:
     50> coordinates(df) <- c(1,2)
     51> class(df)
     52[1] "SpatialPixelsDataFrame"
     53attr(,"package")
     54[1] "sp"
     55> # Application of the 'spplot' method, generating a lattice-type map:
     56> spplot(df, as.table = TRUE, col.regions = colorRampPalette(c("blue","white","red")), at = seq(-2.5,2.5,.25))
    1457}}}
    1558
    1659
     60[[Image(image-20140902-203119.png)]]
     61
     62The 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.