Changes between Version 25 and Version 26 of udg/ecoms/RPackage/examples


Ignore:
Timestamp:
May 24, 2013 2:10:10 PM (8 years ago)
Author:
juaco
Comment:

--

Legend:

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

    v25 v26  
    11
    2 The following examples are partly based on locally stored data. Only the `loadSystem4` function does not require locally stored datasets because it works by remotely accessing the System4 databases stored in the SPECS-EUPORIAS Data Server. Therefore, it is recommended that the '''meteoR.zip''' file is downloaded and unzipped in a convenient directory. Once the zip file has been downloaded and unzipped, we will define the 'r' folder as the working directory. Therefore, in the following examples all the path names given will be relative to the 'r' directory.
    3 
    4 The following expression lists all the R functions available, read them and loads them into the R working session:
    5 
    6 {{{
    7 > rfuncs <- list.files(pattern = "\\.R$")
    8 > print(rfuncs)
    9 [1] "dataInventory.R"    "loadData.R"         "loadObservations.R" "loadSystem4.R"      "makeNcmlDataset.R"
    10 > for (i in 1:length(rfuncs)) {
    11 +      source(rfuncs[i])
    12 + }
    13 
    14 }}}
    15 
    16 
    17 = loadSystem4 =
    18 
    19 In the next lines we describe an illustrative example of the `loadSystem4` function. We will retrieve System4 simulation data for the Iberian Peninsula, considering mean surface temperature for January and the first simulation member, for the 10-year period 1990-1999. This simple example has been chosen because of the fast data access (note that this also depends on the connection speed). Using a standard broadband connection, loading the following dataset took approximately 19 seconds:
    20 
    21 {{{
    22 > openDAP.query <- loadSystem4(dataset = "http://www.meteo.unican.es/tds5/dodsC/system4/System4_Seasonal_15Members.ncml",
    23 +                             var = "tas", members = 1,
    24 +                             lonLim = c(-10,5), latLim = c(35,45),
    25 +                             season = 1, years = 1990:1999, leadMonth = 1)
    26 
    27 }}}
    28 
    29 Data are now ready for analysis into our R session:
     2The following examples are partly based on locally stored data. Only the `loadSeasonalForecast` function does not require locally stored datasets because it works by remotely accessing the System4 databases stored in the SPECS-EUPORIAS Data Server (in this case a valid username and password are required though, as detailed [https://www.meteo.unican.es/trac/meteo/wiki/SpecsEuporias/RPackage/Authentication here]). Therefore, it is recommended that the '''meteoR_v0.1.0.zip''' file is downloaded and unzipped in a convenient directory. Before starting, please follow the [https://www.meteo.unican.es/trac/meteo/wiki/SpecsEuporias/RPackage/Requirements instructions].
     3
     4
     5= loadSeasonalForecast
     6
     7In the next lines we describe an illustrative example of the `loadSeasonalForecast` function. '''Note that to make this example a valid username and password are required''' in order to access the SPECS-EUPORIAS Data Server, as detailed [https://www.meteo.unican.es/trac/meteo/wiki/SpecsEuporias/RPackage/Authentication here]. We will retrieve System4 simulation data for the Iberian Peninsula, considering mean surface temperature for January and the first simulation member, for the 10-year period 1990-1999. This simple example has been chosen because of the fast data access (note that this also depends on the connection speed). Using a standard broadband connection, loading the following dataset took approximately 19 seconds:
     8
     9{{{
     10> openDAP.query <- loadSeasonalForecast(dataset = "http://www.meteo.unican.es/tds5/dodsC/system4/System4_Seasonal_15Members.ncml",
     11+                                         standard.vars = TRUE, dictionary = "System4_Seasonal_15Members.dic",
     12+                                         var = "tas", members = 1,
     13+                                         lonLim = c(-10,5), latLim = c(35,45),
     14+                                         season = 1, years = 1990:1999, leadMonth = 1)
     15>
     16
     17}}}
     18
     19
     20Data are now ready for analysis into our R session. Note that we have set the `standard.vars` argument to `TRUE`, and we have specified a path to the dictionary, a file with extension ''.dic'', whose aim is to translate the original variable stored in the dataset (in this case in Kelvin instead of Celsius). More details on the use of the dictionary are provided [https://www.meteo.unican.es/trac/meteo/wiki/SpecsEuporias/RPackage here].
    3021
    3122{{{
    3223> str(openDAP.query)
    33 List of 7
    34  $ VarName      : chr "Mean_temperature_at_2_metres"
    35  $ VarUnits     : chr "degC"
    36  $ TimeStep     :Class 'difftime'  atomic [1:1] 1
    37   .. ..- attr(*, "tzone")= chr ""
    38   .. ..- attr(*, "units")= chr "days"
     24List of 5
     25 $ VarName      : chr "Mean_temperature_at_2_metres_since_last_24_hours_surface"
    3926 $ MemberData   :List of 1
    4027  ..$ : num [1:310, 1:280] 13.3 13.9 12.5 13 13 ...
     
    4330  .. ..$ : NULL
    4431  .. ..$ : chr [1:2] "lat" "lon"
    45  $ RunDates     : POSIXlt[1:310], format: "1989-12-01" "1989-12-01" "1989-12-01" ...
     32 $ RunDates     : chr [1:310] "1989-12-01" "1989-12-01" "1989-12-01" "1989-12-01" ...
    4633 $ ForecastDates:List of 2
    47   ..$ Start: POSIXlt[1:310], format: "1990-01-01" "1990-01-02" "1990-01-03" ...
    48   ..$ End  : POSIXct[1:310], format: "1990-01-02" "1990-01-03" "1990-01-04" ...
    49 
    50 }}}
    51 
    52 A common task consists of the representation of data, e.g. by mapping the spatial mean for the period considered. Another common task is the representation of time series for selected point locations/grid cells. In this example, we will map the mean temperature field for the period selected (1990-99) preserving the original spatial resolution of the model. Furthermore, we will display time series of the requested dataset at four grid points coincident with the locations of four Spanish cities. To this aim, we will make use of some `base` R functions and also from some contributed packages that can be very useful for climate data handling and representation.
     34  ..$ Start: POSIXlt[1:310], format: "1990-01-01" "1990-01-02" "1990-01-03" "1990-01-04" ...
     35  ..$ End  : POSIXlt[1:310], format: "1990-01-02" "1990-01-03" "1990-01-04" "1990-01-05" ...
     36
     37}}}
     38
     39A common task consists of the representation of data, e.g. by mapping the spatial mean for the period considered. Another common task is the representation of time series for selected point locations/grid cells. In this example, we will map the mean temperature field for the period selected (1990-99) preserving the original spatial resolution of the model. Furthermore, we will display time series at two grid points coincident with the locations of two Spanish cities. To this aim, we will make use of some `base` R functions and also from some contributed packages that can be very useful for climate data handling and representation.
    5340
    5441{{{
     
    5643> mean.field <- colMeans(openDAP.query$MemberData[[1]])
    5744> # Creation of a matrix with selected point locations:
    58 > city.names <- c("Sevilla", "Madrid", "Santander", "Zaragoza")
    59 > locations <- matrix(c(-5.9, 37.4167, -3.68, 40.4, -3.817, 43.43, -0.8167, 41.667), ncol=2, byrow = TRUE)
     45> city.names <- c("Madrid", "Santander")
     46> locations <- matrix(c(-3.68, 40.4, -3.817, 43.43), ncol=2, byrow = TRUE)
    6047> dimnames(locations) <- list(city.names, c("lon","lat"))
    6148> print(locations)
    62              lon     lat
    63 Sevilla   -5.9000 37.4167
    64 Madrid    -3.6800 40.4000
    65 Santander -3.8170 43.4300
    66 Zaragoza  -0.8167 41.6670
     49             lon   lat
     50Madrid    -3.680 40.40
     51Santander -3.817 43.43
    6752
    6853}}}