Changes between Initial Version and Version 1 of udg/ecoms/RPackage/examples/bias


Ignore:
Timestamp:
Sep 2, 2014 6:24:59 PM (8 years ago)
Author:
juaco
Comment:

--

Legend:

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

    v1 v1  
     1= Example 3. Calculating the bias of an ensemble forecast
     2
     3In this example we will calculate the bias of the multimember forecast loaded
     4[http://meteo.unican.es/trac/wiki/EcomsUdg/RPackage/Examples/continentalSelection in the previous example].
     5
     6We first load the reference observations for the spatio-temporal domain previously chosen:
     7
     8{{{
     9#!text/R
     10> ex2.obs <- loadECOMS(dataset = "WFDEI", var = "tasmin", lonLim = c(-15,35), latLim = c(32, 75), season = c(12,1,2), years = 2001:2010)
     11[2014-09-02 17:07:43] Defining homogeneization parameters for variable "tasmin"
     12[2014-09-02 17:07:44] Defining geo-location parameters
     13[2014-09-02 17:07:44] Defining time selection parameters
     14[2014-09-02 17:07:44] Retrieving data subset ...
     15[2014-09-02 17:07:58] Done
     16> print(object.size(ex2.obs), units = "Mb")
     1760.6 Mb
     18}}}
     19
     20This is the map of the observed mean minimum surface temperature observed for DJF 2001-2010:
     21
     22{{{
     23#!text/R
     24> plotMeanField(ex2.obs)
     25}}}
     26
     27[[Image(image-20140902-171138.png)]]
     28
     29Note that WFDEI provides data for land areas only, and its spatial resolution is finer than CFS (1º vs 0.5º). In order to compare both datasets, it is first necessary to put them in the same grid (i.e., to interpolate). We use bilinear interpolation to this aim, using the `downscaleR` function `interpGridData` in combination with the `getGrid` method, useful to recover the parameters defining the grid of a dataset to pass them to the interpolator:
     30
     31{{{
     32#!text/R
     33> obs.regridded <- interpGridData(gridData = ex2.obs, new.grid = getGrid(ex2), method = "bilinear")
     34[2014-09-02 17:22:11] Performing bilinear interpolation... may take a while
     35[2014-09-02 17:22:30] Done
     36Warning messages:
     371: In interpGridData(gridData = ex2.obs, new.grid = getGrid(ex2), method = "bilinear") :
     38  The new longitudes are outside the data extent
     392: In interpGridData(gridData = ex2.obs, new.grid = getGrid(ex2), method = "bilinear") :
     40  The new latitudes are outside the data extent
     41}}}
     42
     43Note the warnings reminding us that the extent of the input grid is wider that that of CFS. However, in this case we can safely ignore this warnings, since all the land areas we are interest in are within the CFS domain.
     44
     45{{{
     46#!text/R
     47> plotMeanField(obs.regridded)
     48}}}
     49
     50
     51[[Image(image-20140902-172529.png)]]
     52
     53
     54Now that both model data and observations are in the same grid, we can compute the bias. First, we calculate the spatial mean of WFDEI, which is the reference against which to compute the biases:
     55
     56{{{
     57#!text/R
     58> ref <- apply(obs.regridded$Data, MARGIN = c(3,2), mean, na.rm = TRUE)
     59}}}
     60
     61The following lines of code compute the bias of each member w.r.t. the reference and plot them:
     62
     63{{{
     64#!text/R
     65# Now we compute the difference agains each of the multimember spatial means:
     66> require(fields)
     67> n.members <- dim(ex2$Data)[1]
     68> par(mfrow = c(1,2))
     69> for (i in 1:n.members) {
     70+       member <- apply(ex2$Data[i, , , ], MARGIN = c(3,2), mean, na.rm = TRUE)
     71+       bias <- member - ref     
     72+       image.plot(ex2$xyCoords$x, ex2$xyCoords$y, bias, xlab = "lon", ylab = "lat", asp = 1)
     73+       title(paste("Bias member", i))
     74+       world(add = TRUE)
     75+ }
     76> par(mfrow = c(1,1)) # To reset the graphical window
     77}}}
     78
     79[[Image(image-20140902-180232.png)]]