• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Climate data in r with the raster package
 

Climate data in r with the raster package

on

  • 3,146 views

 

Statistics

Views

Total Views
3,146
Views on SlideShare
3,126
Embed Views
20

Actions

Likes
2
Downloads
23
Comments
0

1 Embed 20

http://www.scientifik.info 20

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Climate data in r with the raster package Climate data in r with the raster package Presentation Transcript

    • Climate data in Rwith the raster package Jacob van Etten Alberto Labarga
    • PackagesThere are many packages specifically createdfor R that allow you to do specialized tasks.One of these packages is raster, created byRobert Hijmans and Jacob van Etten (mainlythe former, though).The raster package allows you to work withgeographical grid (raster) data.
    • Get raster in RStudioClick on the “Packages” tab in the lower rightcorner.Click “Install Packages”.Type “raster” and click on “Install”.Leave “Install dependencies” checked. This willalso get some other essential packages.
    • Load the packageWith the following command, we load thepackage into R. Make sure you put this in the firstline of your new script.library(raster)help(package="raster")The second function gives you an overview of thefunctions in the package.
    • The raster() functionThe main function to read raster data into R iscalled (very conveniently) raster.?rasterLet’s make a raster!r1 <- raster()r1As you can see, there are no values in theraster. Next thing to solve.
    • Adding valuesHow many values do we need to fill theraster? The function ncell() will tell us.n <- ncell(r1)Let’s make a vector with n random valuesbetween 0 and 1 with the function runif().vals<- runif(n)And we add the values to the raster.values(r1) <- vals
    • Raster graphicsWe make a picture of the raster we just made.plot(r1, main=“My first raster map in R”)Now let’s take a look at the different optionsthat plot() gives.?plotClick “Plot a Raster* object”.Also, take a look at the examples and try someif you want.
    • Real dataLet’s get some real data to play with.http://goo.gl/4488TThis is a raster representing current conditions(a bit over 1 MB).Unzip the file, and put it in a (new) folder.Now make this folder your working directoryin R.setwd(“D:/yourfolder”)
    • Getting raster data into RReading this data into R is really easy now.r2 <- raster(“current_bio_1_1.asc”)What class is this raster?class(r2)Plot this raster.
    • Cutting an area of interestThe function extents requires a vector of 4 values:{xmin, xmax, ymin, ymax}. For instance:newExtent <- extent(c(60, 100, 0, 40))Or choose your own area of interest, for instanceusing Google Earth.Then cut the new extent out of r2 and visualize.r3 <- crop(r2, newExtent)plot(r3)
    • Raster algebraIt is very convenient to calculate with rasters.Try this and visualize the result.r4 <- r3 + sqrt(r3)What happens when you do the following andwhy?r5 <- r2 + r3
    • Some operationsAggregating cells means the grid becomescoarser. By default the function aggregate()will take the mean of the cells it willaggregate.r6 <- aggregate(r2, fact=2)Now take a look at the examples under?aggregate and try to understand whathappens.
    • InterpolationSee if you can work this out for yourself.Take a look at the first example of?interpolate
    • Sources of dataFor an overview of a lot of relevant climateand weather data, visit this website:http://iridl.ldeo.columbia.edu/
    • Moreover...Worldclim data are global climate data (get itusing the raster package, getData function)NCDC-NOAA – Global Summary of Day,weather data from thousands of stations(weatherData package)CCAFS data
    • WorldclimPrecipitation at 10 minute resolutionwc <- getData(“worldclim”, var=“prec”, res=10)plot(wc)
    • Global Summary of DayAvailable from:ftp://ftp.ncdc.noaa.gov/pub/data/gsod/These data are massive.Use the weatherData package to downloadthese data.