# 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)
Comment:

--

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

 v1 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) = Analysing model drift in South-western Iberia We will take as reference for measuring the drift the lead-month 0 forecast (i.e. the July initializations) {{{#!text/R > ref <- loadECOMS(dataset = "CFSv2_seasonal_16", var = "tas", lonLim = c(-10,-1), latLim = c(36,40), season = 7, years = 2006, leadMonth = 0) > plotMeanField(ref) > ref.field <- apply(ref$Data, MARGIN = c(4,3), FUN = mean, na.rm = TRUE) }}} [[Image(image-20140902-201518.png)]] Next, 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: {{{#!text/R }}} We will take as reference for measuring the drift the lead-month 0 forecast (i.e. the July initializations) 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: {{{#!text/R > ref <- loadECOMS(dataset = "CFSv2_seasonal_16", var = "tas", lonLim = c(-10,-1), latLim = c(36,40), season = 7, years = 2006, leadMonth = 0) > plotMeanField(ref) > require(sp) > # Matrix of anomalies between lead month and reference > aux.mat <- matrix(ncol = length(cfs.list), nrow = length(ref$xyCoords$x)*length(ref$xyCoords$y)) + for (i in 1:length(cfs.list)) { + mm.field <- apply(cfs.list[[i]]$Data, MARGIN = c(4,3), FUN = mean, na.rm = TRUE) +       aux.mat[ ,i] <- mm.field - ref.field + } > # 2D coordinates > xy <- expand.grid(ref$xyCoords$x, ref$xyCoords$y) > xy.coords <- coordinates(points2grid(points = SpatialPoints(xy), tolerance = .003)) > df <- cbind.data.frame(xy.coords, aux.mat) > names(df) <- c("x","y",paste("LeadMonth_",1:6, sep = "")) > str(df) 'data.frame':   55 obs. of  8 variables: $x : num -10.31 -9.38 -8.44 -7.5 -6.56 ...$ y          : num  40.2 40.2 40.2 40.2 40.2 ... $LeadMonth_1: num 0.0398 0.0691 0.1427 0.116 0.1935 ...$ LeadMonth_2: num  0.386 0.451 0.472 0.311 0.161 ... $LeadMonth_3: num 0.0428 0.0787 0.0707 -0.125 -0.2751 ...$ LeadMonth_4: num  0.261 0.258 0.131 -0.177 -0.464 ... $LeadMonth_5: num 0.0576 0.154 0.1327 -0.1282 -0.3963 ...$ LeadMonth_6: num  0.0789 0.192 0.0989 -0.2667 -0.6457 ... > Conversion of the data.frame to a Spatial gridded object: > coordinates(df) <- c(1,2) > class(df) [1] "SpatialPixelsDataFrame" attr(,"package") [1] "sp" > # Application of the 'spplot' method, generating a lattice-type map: > spplot(df, as.table = TRUE, col.regions = colorRampPalette(c("blue","white","red")), at = seq(-2.5,2.5,.25)) }}} [[Image(image-20140902-203119.png)]] 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.