Changes between Version 8 and Version 9 of udg/ecoms/RPackage/examples/pointSelection


Ignore:
Timestamp:
Sep 2, 2014 3:53:27 PM (7 years ago)
Author:
juaco
Comment:

--

Legend:

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

    v8 v9  
    1 = Single point selection
     1= Single point selections
    22
    3 The following call to `loadECOMS` will load a time series of surface (2m) daily mean temperature (`var = "tas"`, as defined in the [http://meteo.unican.es/ecoms-udg/RPackage/Homogeneization vocabulary]) for the coordinate -3.7E 40.4N, (`lonLim = -3.7`, `latLim = 40.4`) corresponding to the city of Madrid (Spain), corresponding to the summer (JJA, `season = 6:8`) of 2001 (`years = 2001`) as forecasted the previous March (`leadMonth = 2`) by the CFSv2 hindcast (`dataset = "CFSv2_seasonal_16"`). We will select the first 10 members (`members = 1:10`). Note that the original variable is stored in the CFSv2 database as 6-hourly. Hence, we indicate to the funciton to compute the daily mean from the 6-hourly data using the argument `time = "DD".`
     3The following call to `loadECOMS` will load a time series of summer 2001 (JJA, `season = 6:8`, `years = 2001`) surface (2m) daily mean temperature (`var = "tas"`, as defined in the [http://meteo.unican.es/ecoms-udg/RPackage/Homogeneization vocabulary]) for the coordinate -3.7E 40.4N, (`lonLim = -3.7`, `latLim = 40.4`) corresponding to the city of Madrid (Spain), as forecasted the previous March (`leadMonth = 2`) by the CFSv2 hindcast (`dataset = "CFSv2_seasonal_16"`). We will select the first 10 members (`members = 1:10`). Note that the original variable is stored in the CFSv2 database as 6-hourly. Hence, we indicate to the function to compute the daily mean from the 6-hourly data using the argument `time = "DD".`
     4
     5
     6First of all, the library is called and we log-in into the ECOMS-UDG:
     7
     8{{{
     9#!text/R
     10> library(ecomsUDG.Raccess)
     11> loginECOMS_UDG("user","password")
     12}}}
     13
     14Now we are ready for accessing the ECOMS-UDG:
    415
    516{{{
    617#!text/R
    718> point.cfs <- loadECOMS(dataset = "CFSv2_seasonal_16", var = "tas", members = 1:10, lonLim = -3.7, latLim = 40.4, season = 6:8, years = 2001, leadMonth = 2, time = "DD")
    8 [2014-06-17 15:51:15] Defining homogeneization parameters for variable "tas"
    9 NOTE: daily mean will be calculated from the 6-h instantaneous model output
    10 [2014-06-17 15:51:15] Defining geo-location parameters
    11 [2014-06-17 15:51:16] Defining initialization time parameters
    12 [2014-06-17 15:51:20] Retrieving data subset ...
    13 [2014-06-17 15:54:16] Done
     19[2014-09-02 15:28:42] Defining homogeneization parameters for variable "tas"
     20NOTE: daily mean will be calculated from the 6-h model output
     21[2014-09-02 15:28:42] Defining geo-location parameters
     22[2014-09-02 15:28:42] Defining initialization time parameters
     23[2014-09-02 15:28:46] Retrieving data subset ...
     24[2014-09-02 15:31:25] Done
    1425> print(object.size(point.cfs))
    15 32088 bytes
     2622456 bytes
    1627}}}
    1728
    18 The returned object contains all the necessary information for data representation (geo-location, time ...). In the next lines we plot the loaded time series for each member. The element `Data` contains the data itself. In this case, it is a 2D array with the dimensions `time` (92 days for June, July and August) and `member` (10 members selected), as indicated by the `dimensions` attribute:
     29The returned object contains all the necessary information for data representation (geo-location, time ...). In the next lines we plot the loaded time series for each member. The element `Data` contains the data itself. In this case, it is a 2D array with the dimensions `member` (10 members selected) and `time` (92 days for June, July and August), as indicated by the `dimensions` attribute.
     30
    1931
    2032{{{
    2133#!text/R
    2234> str(point.cfs$Data)
    23  num [1:92, 1:10] 16.3 17.7 18.6 19.7 20.2 ...
    24  - attr(*, "dimensions")= chr [1:2] "time" "member"
     35 num [1:10, 1:92] 16.3 17.1 12.9 10.4 15.3 ...
     36 - attr(*, "dimensions")= chr [1:2] "member" "time"
    2537}}}
     38
     39
     40Note that, by convention, the dimensions of the Data array will be always ordered in the canonical form ''member > time > lat > lon''. Several vertical levels are never loaded at the same time, so the dimension ''level'' will never appear. This will be indicated in the Variables element of the returned output if existing. In this case it is NULL, because the variable loaded is a surface variable:
     41
     42{{{
     43#!text/R
     44> str(point.cfs$Variable)
     45List of 3
     46 $ varName   : chr "tas"
     47 $ isStandard: logi TRUE
     48 $ level     : NULL
     49}}}
     50
    2651
    2752In the following example we plot the time series with the multi-member mean and its dispersion (interquartilic range 25-75):
     
    2954{{{
    3055#!text/R
    31 > quartiles <- apply(point.cfs$Data, MARGIN = 1, FUN = quantile, probs = c(.25,.75))
    32 > ens.mean <- rowMeans(point.cfs$Data)
    33 > dates <- as.POSIXlt(point.cfs$Dates$start, tz="GMT")
    34 > plot(dates, ens.mean, ylim = range(point.cfs$Data), ty = 'n', ylab = "tas - Daily Mean", xlab = "time")
    35 > polygon(x = c(dates, rev(dates)), y = c(quartiles[1, ], rev(quartiles[2, ])), border = "transparent", col = rgb(0,0,1,.4))
    36 > lines(dates, ens.mean)
     56quartiles <- apply(point.cfs$Data, MARGIN = 2, FUN = quantile, probs = c(.25,.75))
     57ens.mean <- colMeans(point.cfs$Data)
     58dates <- as.POSIXlt(point.cfs$Dates$start, tz="GMT")
     59plot(dates, ens.mean, ylim = range(point.cfs$Data), ty = 'n', ylab = "tas - Daily Mean", xlab = "time")
     60polygon(x = c(dates, rev(dates)), y = c(quartiles[1, ], rev(quartiles[2, ])), border = "transparent", col = rgb(0,0,1,.4))
     61lines(dates, ens.mean)
    3762}}}
    3863
     
    4570#!text/R
    4671> point.wfdei <- loadECOMS(dataset = "WFDEI", var = "tas", lonLim = -3.7, latLim = 40.4, season = 6:8, years = 2001, time = "DD")
    47 [2014-06-17 16:05:55] Defining homogeneization parameters for variable "tas"
    48 [2014-06-17 16:06:55] Defining geo-location parameters
    49 [2014-06-17 16:06:55] Defining time selection parameters
    50 [2014-06-17 16:06:55] Done
     72[2014-09-02 15:49:44] Defining homogeneization parameters for variable "tas"
     73[2014-09-02 15:49:44] Defining geo-location parameters
     74[2014-09-02 15:49:44] Defining time selection parameters
     75[2014-09-02 15:49:45] Retrieving data subset ...
     76[2014-09-02 15:49:45] Done
    5177> print(object.size(point.wfdei))
    52 13360 bytes
     7813704 bytes
    5379}}}
     80
     81The WFDEI point loaded is unidimensional, corresponding to a time series of a single point location. It lacks the "member" dimension because it is an observational dataset:
     82
     83{{{
     84#!text/R
     85> str(point.wfdei$Data)
     86 num [1:92(1d)] 26.6 25.7 25.6 24.3 23.3 ...
     87 - attr(*, "dimensions")= chr "time"
     88> point.wfdei$xyCoords
     89$x
     90[1] -3.75
     91
     92$y
     93[1] 40.25
     94
     95attr(,"projection")
     96[1] "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"
     97}}}
     98
    5499
    55100It is now possible to overlay the observed temperature series with the 2-month ahead prediction of CFS for that particular grid cell (the result is not very impressive, though):
     
    59104> lines(dates, point.wfdei$Data, col = "red", lwd = 1.5)
    60105}}}
     106
    61107[[Image(image-20140617-161214.png)]]
     108