Changes between Version 16 and Version 17 of udg/ecoms/RPackage/examples


Ignore:
Timestamp:
May 20, 2013 9:39:37 AM (8 years ago)
Author:
juaco
Comment:

--

Legend:

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

    v16 v17  
    1111+      source(rfuncs[i])
    1212+ }
     13
    1314}}}
    1415
     
    2324+                             lonLim = c(-10,5), latLim = c(35,45),
    2425+                             season = 1, years = 1990:1999, leadMonth = 1)
     26
    2527}}}
    2628
     
    4547  ..$ Start: POSIXlt[1:310], format: "1990-01-01" "1990-01-02" "1990-01-03" ...
    4648  ..$ End  : POSIXct[1:310], format: "1990-01-02" "1990-01-03" "1990-01-04" ...
     49
    4750}}}
    4851
     
    6265Santander -3.8170 43.4300
    6366Zaragoza  -0.8167 41.6670
     67
    6468}}}
    6569
     
    7276> library(akima)
    7377> grid.075 <- interp(lon, lat, mean.field, xo = seq(min(lon), max(lon), .75), yo = seq(min(lat), max(lat), .75))
     78
    7479}}}
    7580
     
    8287 $ y: num [1:14] 35.2 36 36.7 37.5 38.2 ...
    8388 $ z: num [1:19, 1:14] 15.1 15.1 15 15 14.3 ...
     89
    8490}}}
    8591
     
    96102# Adds the world map to the current plot:
    97103> world(add=TRUE)
     104
    98105}}}
    99106
     
    118125  ..$ : NULL
    119126  ..$ : chr [1:4] "Sevilla" "Madrid" "Santander" "Zaragoza"
     127
    120128}}}
    121129
     
    133141> legend("bottomleft", city.names, lty=1, col=1:4)
    134142> title(main = "Mean surface Temperature January")
     143
    135144}}}
    136145
     
    144153{{{#!comment
    145154setwd("/home/juaco/Desktop/r")
    146 }}}
    147 
    148 # Loading Observations
     155
     156}}}
    149157
    150158The function `loadObservations` is intended to deal with observational datasets from weather stations stored as csv files in a standard format.
     
    154162> list.files("./datasets/observations/Iberia_ECA")
    155163[1] "ecaIberia.nc" "Master.csv"   "pr.csv"       "tas.csv"      "tasmax.csv"   "tasmin.csv"
     164
    156165}}}
    157166
     
    167176$ Altitude : int  151 185 667 7 1894 790 251 44 43 704 ...
    168177$ Metadata : Factor w/ 1 level " Data provided by the ECA&D project. Available at http://www.ecad.eu": 1 1 1 1 1 1 1 1 1 1 ...
     178
    169179}}}
    170180
     
    182192> plot(master[ ,2:3], asp=1, pch=15, col="red")
    183193> world(add=TRUE)
     194
    184195}}}
    185196
     
    191202[1] "000033" "000229" "000230" "000231" "000232" "000233" "000234" "000236" "000309" "000336" "000414" "000416" "000420" "000421"
    192203[15] "000788" "000800" "001392" "001398" "003904" "003905" "003907" "003908" "003922" "003928" "003936" "003947" "003948" "003949"
    193 }}}
     204
     205}}}
     206
     207We place the labels on top of each location. There are ways to avoid the overlapping of labels in order to explore the dataset, for instance in an interactive fashion by means of the `identify` function .
     208
     209{{{
     210> text(master$Longitude + .2, master$Latitude + .2, stationIDs, cex=.7)
     211
     212}}}
     213
     214
     215[[Image(stations.png)]]
     216
     217In this particular example we are interested in the mean surface temperature from the cities of Santander and Madrid. The station codes are
     218''"000230"'' and ''"001392"'' for Madrid and Santander respectively. We will select the period 1990-1999.
     219
     220{{{
     221> stationData <- loadObservations(source.dir="./datasets/observations/Iberia_ECA/", var="tas",
     222+           standard.vars=FALSE, stationID=c("000230","001392"), startDate="1990-01-01", endDate="1999-12-31")
     223> str(stationData)
     224List of 5
     225 $ StationID   : chr [1:2] "000230" "001392"
     226 $ LatLonCoords: num [1:2, 1:2] 40.41 43.46 -3.68 -3.82
     227  ..- attr(*, "dimnames")=List of 2
     228  .. ..$ : NULL
     229  .. ..$ : chr [1:2] "Latitude" "Longitude"
     230 $ Altitude    : int [1:2] 667 64
     231 $ Dates       : POSIXlt[1:3652], format: "1990-01-01" "1990-01-02" "1990-01-03" "1990-01-04" ...
     232 $ Data        : num [1:3652, 1:2] 112 85 90 74 101 109 110 82 86 66 ...
     233  ..- attr(*, "dimnames")=List of 2
     234  .. ..$ : NULL
     235  .. ..$ : chr [1:2] "000230" "001392"
     236> plot(stationData$Dates, stationData$Data[ ,1], col = "red", type = "l")
     237> lines(stationData$Dates, stationData$Data[ ,2], col = "green")
     238> legend("topright", c("Madrid","Santander"), col = c("red","green"), lty=1, bg = "white")
     239
     240}}}   
     241
     242[[Image(timeSeriesObs.png)]]
     243
     244
     245
     246= Creating a dataset =
     247