38 | | > # The library sp needs to be installed to do this example: |
39 | | > require(sp) |
40 | | Loading required package: sp |
41 | | > # Matrix of anomalies between lead month and reference |
42 | | > aux.mat <- matrix(ncol = length(cfs.list), nrow = length(ref$xyCoords$x)*length(ref$xyCoords$y)) |
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) |
45 | | + aux.mat[ ,i] <- mm.field - ref.field |
46 | | + } |
47 | | > # 2D coordinates |
48 | | > xy <- expand.grid(ref$xyCoords$x, ref$xyCoords$y) |
49 | | > # This step ensures regularity of the CFS grid, which is not perfectly regular: |
50 | | > 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: |
52 | | > df <- cbind.data.frame(xy.coords, aux.mat) |
53 | | > names(df) <- c("x","y",paste("LeadMonth_",1:6, sep = "")) |
54 | | > str(df) |
| 38 | # The library sp needs to be installed to do this example: |
| 39 | require(sp) |
| 40 | # Matrix of anomalies between lead month and reference |
| 41 | aux.mat <- sapply(1:length(cfs.list), function(i) {apply(cfs.list[[i]]$Data, MARGIN = c(3,2), FUN = mean, na.rm = TRUE) - ref.field}) |
| 42 | # 2D coordinates |
| 43 | xy <- expand.grid(ref$xyCoords$x, ref$xyCoords$y) |
| 44 | # This step ensures regularity of the CFS grid, which is not perfectly regular: |
| 45 | xy.coords <- coordinates(points2grid(points = SpatialPoints(xy), tolerance = .003)) |
| 46 | # 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: |
| 47 | df <- cbind.data.frame(xy.coords, aux.mat) |
| 48 | names(df) <- c("x","y",paste("LeadMonth_",1:6, sep = "")) |
| 49 | str(df) |
75 | | > load(url("http://meteo.unican.es/work/downscaler/aux/wlines.rda"), verbose = TRUE) |
76 | | Loading objects: |
77 | | wlines |
78 | | > l1 <- list("sp.lines", wlines) |
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)) |
| 75 | load(url("http://meteo.unican.es/work/downscaler/aux/wlines.rda"), verbose = TRUE) |
| 76 | l1 <- list("sp.lines", wlines) |
| 77 | 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)) |