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

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

--

### Legend:

Unmodified
 v25 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. The following expression lists all the R functions available, read them and loads them into the R working session: {{{ > rfuncs <- list.files(pattern = "\\.R$") > print(rfuncs) [1] "dataInventory.R" "loadData.R" "loadObservations.R" "loadSystem4.R" "makeNcmlDataset.R" > for (i in 1:length(rfuncs)) { + source(rfuncs[i]) + } }}} = loadSystem4 = 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: {{{ > openDAP.query <- loadSystem4(dataset = "http://www.meteo.unican.es/tds5/dodsC/system4/System4_Seasonal_15Members.ncml", + var = "tas", members = 1, + lonLim = c(-10,5), latLim = c(35,45), + season = 1, years = 1990:1999, leadMonth = 1) }}} Data are now ready for analysis into our R session: The 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]. = loadSeasonalForecast In 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: {{{ > openDAP.query <- loadSeasonalForecast(dataset = "http://www.meteo.unican.es/tds5/dodsC/system4/System4_Seasonal_15Members.ncml", + standard.vars = TRUE, dictionary = "System4_Seasonal_15Members.dic", + var = "tas", members = 1, + lonLim = c(-10,5), latLim = c(35,45), + season = 1, years = 1990:1999, leadMonth = 1) > }}} Data 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]. {{{ > str(openDAP.query) List of 7$ VarName      : chr "Mean_temperature_at_2_metres" $VarUnits : chr "degC"$ TimeStep     :Class 'difftime'  atomic [1:1] 1 .. ..- attr(*, "tzone")= chr "" .. ..- attr(*, "units")= chr "days" List of 5 $VarName : chr "Mean_temperature_at_2_metres_since_last_24_hours_surface"$ MemberData   :List of 1 ..$: num [1:310, 1:280] 13.3 13.9 12.5 13 13 ... .. ..$ : NULL .. ..$: chr [1:2] "lat" "lon"$ RunDates     : POSIXlt[1:310], format: "1989-12-01" "1989-12-01" "1989-12-01" ... $RunDates : chr [1:310] "1989-12-01" "1989-12-01" "1989-12-01" "1989-12-01" ...$ ForecastDates:List of 2 ..$Start: POSIXlt[1:310], format: "1990-01-01" "1990-01-02" "1990-01-03" ... ..$ End  : POSIXct[1:310], format: "1990-01-02" "1990-01-03" "1990-01-04" ... }}} 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. ..$Start: POSIXlt[1:310], format: "1990-01-01" "1990-01-02" "1990-01-03" "1990-01-04" ... ..$ End  : POSIXlt[1:310], format: "1990-01-02" "1990-01-03" "1990-01-04" "1990-01-05" ... }}} 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 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. {{{ > mean.field <- colMeans(openDAP.query\$MemberData[[1]]) > # Creation of a matrix with selected point locations: > city.names <- c("Sevilla", "Madrid", "Santander", "Zaragoza") > locations <- matrix(c(-5.9, 37.4167, -3.68, 40.4, -3.817, 43.43, -0.8167, 41.667), ncol=2, byrow = TRUE) > city.names <- c("Madrid", "Santander") > locations <- matrix(c(-3.68, 40.4, -3.817, 43.43), ncol=2, byrow = TRUE) > dimnames(locations) <- list(city.names, c("lon","lat")) > print(locations) lon     lat Sevilla   -5.9000 37.4167 Madrid    -3.6800 40.4000 Santander -3.8170 43.4300 Zaragoza  -0.8167 41.6670 lon   lat Madrid    -3.680 40.40 Santander -3.817 43.43 }}}