SlideShare une entreprise Scribd logo
1  sur  18
Climate data in R with the raster package Jacob van Etten
Packages There are many packages specifically created for R that allow you to do specialized tasks. One of these packages is raster, created by Robert Hijmans and Jacob van Etten (mainly the former, though). The raster package allows you to work with geographical grid (raster) data.
Get raster in RStudio Click on the “Packages” tab in the lower right corner. Click “Install Packages”. Type “raster” and click on “Install”. Leave “Install dependencies” checked. This will also get some other essential packages.
Load the package With the following command, we load the package into R. Make sure you put this in the first line of your new script. library(raster) help(package="raster") Thesecondfunctiongivesyouanoverview of thefunctions in thepackage.
The raster() function The main function to read raster data into R is called (very conveniently) raster. ?raster Let’s make a raster! r1 <- raster() r1 As you can see, there are no values in the raster. Next thing to solve.
Adding values How many values do we need to fill the raster? The function ncell() will tell us. n <- ncell(r1) Let’s make a vector with n random values between 0 and 1 with the function runif(). vals<- runif(n) And we add the values to the raster. values(r1) <- vals
Raster graphics We 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 options that plot() gives. ?plot Click “Plot a Raster* object”. Also, take a look at the examples and try some if you want.
Real data Let’s get some real data to play with. http://goo.gl/4488T This 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 directory in R. setwd(“D:/yourfolder”)
Getting raster data into R Reading 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 interest The function extents requires a vector of 4 values: {xmin, xmax, ymin, ymax}. For instance: newExtent <- extent(c(60, 100, 0, 40)) Orchooseyourownarea of interest, forinstanceusing Google Earth. Then cut the new extent out of r2 and visualize. r3 <- crop(r2, newExtent) plot(r3)
Raster algebra It is very convenient to calculate with rasters. Try this and visualize the result. r4 <- r3 + sqrt(r3) What happens when you do the following and why? r5 <- r2 + r3
Some operations Aggregating cells means the grid becomes coarser. By default the function aggregate() will take the mean of the cells it will aggregate. r6 <- aggregate(r2, fact=2) Now take a look at the examples under ?aggregate and try to understand what happens.
Interpolation See if you can work this out for yourself. Take a look at the first example of  ?interpolate
Sources of data For an overview of a lot of relevant climate and weather data, visit this website: http://iridl.ldeo.columbia.edu/
Moreover... Worldclim data are global climate data (get it using the raster package, getData function) NCDC-NOAA – Global Summary of Day, weather data from thousands of stations (weatherData package) CCAFS data
Worldclim Precipitation at 10 minute resolution wc <- getData(“worldclim”, var=“prec”, res=10) plot(wc)
Global Summary of Day Available from: ftp://ftp.ncdc.noaa.gov/pub/data/gsod/ These data are massive. Use the weatherData package to download these data.
Climate data in R with the raster package

Contenu connexe

Tendances

Terminology and Basic Questions About GIS
Terminology and Basic Questions About GISTerminology and Basic Questions About GIS
Terminology and Basic Questions About GIS
Mrinmoy Majumder
 
Using GIS Technology to Improve Emergency Management
Using GIS Technology to Improve Emergency ManagementUsing GIS Technology to Improve Emergency Management
Using GIS Technology to Improve Emergency Management
AmberStacy
 
Change detection techniques
Change detection techniquesChange detection techniques
Change detection techniques
Femi Opaleye
 

Tendances (20)

Terminology and Basic Questions About GIS
Terminology and Basic Questions About GISTerminology and Basic Questions About GIS
Terminology and Basic Questions About GIS
 
Application of GIS in Mine Contamination and Associated Environmental Impacts
Application of GIS in Mine Contamination and Associated Environmental ImpactsApplication of GIS in Mine Contamination and Associated Environmental Impacts
Application of GIS in Mine Contamination and Associated Environmental Impacts
 
Intro to GIS and Remote Sensing
Intro to GIS and Remote SensingIntro to GIS and Remote Sensing
Intro to GIS and Remote Sensing
 
Using GIS Technology to Improve Emergency Management
Using GIS Technology to Improve Emergency ManagementUsing GIS Technology to Improve Emergency Management
Using GIS Technology to Improve Emergency Management
 
Iirs lecure notes for Remote sensing –An Overview of Decision Maker
Iirs lecure notes for Remote sensing –An Overview of Decision MakerIirs lecure notes for Remote sensing –An Overview of Decision Maker
Iirs lecure notes for Remote sensing –An Overview of Decision Maker
 
Interpolation 2013
Interpolation 2013Interpolation 2013
Interpolation 2013
 
Landsat seminar
Landsat seminarLandsat seminar
Landsat seminar
 
Sentinel 2
Sentinel 2Sentinel 2
Sentinel 2
 
Change detection techniques
Change detection techniquesChange detection techniques
Change detection techniques
 
Basic of gis concept and theories
Basic of gis concept and theoriesBasic of gis concept and theories
Basic of gis concept and theories
 
Spatial analysis & interpolation in ARC GIS
Spatial analysis & interpolation in ARC GISSpatial analysis & interpolation in ARC GIS
Spatial analysis & interpolation in ARC GIS
 
Forest fire management using gis
Forest fire management using gisForest fire management using gis
Forest fire management using gis
 
Lecture 7: Participatory GIS for Disaster Management
Lecture 7: Participatory GIS for Disaster ManagementLecture 7: Participatory GIS for Disaster Management
Lecture 7: Participatory GIS for Disaster Management
 
5. Introduction to Digital Soil Mapping
5. Introduction to Digital Soil Mapping5. Introduction to Digital Soil Mapping
5. Introduction to Digital Soil Mapping
 
Geodesy, Map Projections - Introduction
Geodesy, Map Projections - IntroductionGeodesy, Map Projections - Introduction
Geodesy, Map Projections - Introduction
 
Spot satellite
Spot satelliteSpot satellite
Spot satellite
 
soil erosion modelling by RUSLE
soil erosion modelling by RUSLEsoil erosion modelling by RUSLE
soil erosion modelling by RUSLE
 
How to download Sentinel 2 satellite data
How to download Sentinel 2 satellite dataHow to download Sentinel 2 satellite data
How to download Sentinel 2 satellite data
 
Soil Loss_GeoDev.pdf
Soil Loss_GeoDev.pdfSoil Loss_GeoDev.pdf
Soil Loss_GeoDev.pdf
 
Data input and transformation
Data input and transformationData input and transformation
Data input and transformation
 

En vedette

Climate Data Sharing for Urban Resilience - OGC Testbed 11
Climate Data Sharing for Urban Resilience - OGC Testbed 11Climate Data Sharing for Urban Resilience - OGC Testbed 11
Climate Data Sharing for Urban Resilience - OGC Testbed 11
George Percivall
 
Document IT Communicate IT Succeed
Document IT Communicate IT SucceedDocument IT Communicate IT Succeed
Document IT Communicate IT Succeed
Deborah Gleason
 
Data recovery saudi arabia
Data recovery saudi arabiaData recovery saudi arabia
Data recovery saudi arabia
Dolphin Data Lab
 
ICLR Friday Forum: Climate data in Ontario (November 13, 2015)
ICLR Friday Forum: Climate data in Ontario (November 13, 2015)ICLR Friday Forum: Climate data in Ontario (November 13, 2015)
ICLR Friday Forum: Climate data in Ontario (November 13, 2015)
glennmcgillivray
 
Saudi arabia presentation
Saudi arabia presentationSaudi arabia presentation
Saudi arabia presentation
bpdow12
 
Saudi Aramco Carbon Management - May 2013
Saudi Aramco Carbon Management - May 2013Saudi Aramco Carbon Management - May 2013
Saudi Aramco Carbon Management - May 2013
Global CCS Institute
 

En vedette (20)

Edwards climate data detectives - yale 2-2015
Edwards   climate data detectives - yale 2-2015Edwards   climate data detectives - yale 2-2015
Edwards climate data detectives - yale 2-2015
 
Andreas Hense: Climate data for our future – acquired, analysed, archived
Andreas Hense: Climate data for our future – acquired, analysed, archivedAndreas Hense: Climate data for our future – acquired, analysed, archived
Andreas Hense: Climate data for our future – acquired, analysed, archived
 
Interpreting Climate Data - Analysing climate vulnerability- online training ...
Interpreting Climate Data - Analysing climate vulnerability- online training ...Interpreting Climate Data - Analysing climate vulnerability- online training ...
Interpreting Climate Data - Analysing climate vulnerability- online training ...
 
Climate Data Sharing for Urban Resilience - OGC Testbed 11
Climate Data Sharing for Urban Resilience - OGC Testbed 11Climate Data Sharing for Urban Resilience - OGC Testbed 11
Climate Data Sharing for Urban Resilience - OGC Testbed 11
 
Document IT Communicate IT Succeed
Document IT Communicate IT SucceedDocument IT Communicate IT Succeed
Document IT Communicate IT Succeed
 
Contextualizing the Visualization of Climate Data
Contextualizing the Visualization of Climate DataContextualizing the Visualization of Climate Data
Contextualizing the Visualization of Climate Data
 
ESRI User Conference 2014 - A Location Aware Mobile Tool for Direct and Indir...
ESRI User Conference 2014 - A Location Aware Mobile Tool for Direct and Indir...ESRI User Conference 2014 - A Location Aware Mobile Tool for Direct and Indir...
ESRI User Conference 2014 - A Location Aware Mobile Tool for Direct and Indir...
 
Data recovery saudi arabia
Data recovery saudi arabiaData recovery saudi arabia
Data recovery saudi arabia
 
ICLR Friday Forum: Climate data in Ontario (November 13, 2015)
ICLR Friday Forum: Climate data in Ontario (November 13, 2015)ICLR Friday Forum: Climate data in Ontario (November 13, 2015)
ICLR Friday Forum: Climate data in Ontario (November 13, 2015)
 
20090701 Climate Data Staging
20090701 Climate Data Staging20090701 Climate Data Staging
20090701 Climate Data Staging
 
Saudi arabia climate policy report
Saudi arabia climate policy reportSaudi arabia climate policy report
Saudi arabia climate policy report
 
Geography Water
Geography WaterGeography Water
Geography Water
 
Collaborate 2012: Environmental Accounting and Reporting
Collaborate 2012: Environmental Accounting and ReportingCollaborate 2012: Environmental Accounting and Reporting
Collaborate 2012: Environmental Accounting and Reporting
 
Saudi arabia presentation
Saudi arabia presentationSaudi arabia presentation
Saudi arabia presentation
 
Making Climate Data Sing
Making Climate Data SingMaking Climate Data Sing
Making Climate Data Sing
 
BigDataEurope - Big Data & Climate Change
BigDataEurope - Big Data & Climate ChangeBigDataEurope - Big Data & Climate Change
BigDataEurope - Big Data & Climate Change
 
Saudi Aramco Carbon Management - May 2013
Saudi Aramco Carbon Management - May 2013Saudi Aramco Carbon Management - May 2013
Saudi Aramco Carbon Management - May 2013
 
The Role of DAta for Climate Monitoring and Prediction
The Role of DAta for Climate Monitoring and PredictionThe Role of DAta for Climate Monitoring and Prediction
The Role of DAta for Climate Monitoring and Prediction
 
Non-renewable groundwater management in Saudi Arabia
Non-renewable groundwater management in Saudi ArabiaNon-renewable groundwater management in Saudi Arabia
Non-renewable groundwater management in Saudi Arabia
 
Gulf Region
Gulf RegionGulf Region
Gulf Region
 

Similaire à Climate data in R with the raster package

Climate data in r with the raster package
Climate data in r with the raster packageClimate data in r with the raster package
Climate data in r with the raster package
Alberto Labarga
 
ComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical SciencesComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical Sciences
alexstorer
 
20130215 Reading data into R
20130215 Reading data into R20130215 Reading data into R
20130215 Reading data into R
Kazuki Yoshida
 

Similaire à Climate data in R with the raster package (20)

Climate data in r with the raster package
Climate data in r with the raster packageClimate data in r with the raster package
Climate data in r with the raster package
 
ComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical SciencesComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical Sciences
 
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي   R program د.هديل القفيديمحاضرة برنامج التحليل الكمي   R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
 
Unit 3
Unit 3Unit 3
Unit 3
 
Lecture_R.ppt
Lecture_R.pptLecture_R.ppt
Lecture_R.ppt
 
Best corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbaiBest corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbai
 
Aggregate.pptx
Aggregate.pptxAggregate.pptx
Aggregate.pptx
 
R programming slides
R  programming slidesR  programming slides
R programming slides
 
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي   R program د.هديل القفيديمحاضرة برنامج التحليل الكمي   R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
 
20130215 Reading data into R
20130215 Reading data into R20130215 Reading data into R
20130215 Reading data into R
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
 
R Introduction
R IntroductionR Introduction
R Introduction
 
Get started with R lang
Get started with R langGet started with R lang
Get started with R lang
 
Hands on data science with r.pptx
Hands  on data science with r.pptxHands  on data science with r.pptx
Hands on data science with r.pptx
 
Transformations and actions a visual guide training
Transformations and actions a visual guide trainingTransformations and actions a visual guide training
Transformations and actions a visual guide training
 
Devtools cheatsheet
Devtools cheatsheetDevtools cheatsheet
Devtools cheatsheet
 
Devtools cheatsheet
Devtools cheatsheetDevtools cheatsheet
Devtools cheatsheet
 
Lecture1_R.ppt
Lecture1_R.pptLecture1_R.ppt
Lecture1_R.ppt
 
Lecture1_R.ppt
Lecture1_R.pptLecture1_R.ppt
Lecture1_R.ppt
 
Lecture1 r
Lecture1 rLecture1 r
Lecture1 r
 

Plus de CCAFS | CGIAR Research Program on Climate Change, Agriculture and Food Security

Plus de CCAFS | CGIAR Research Program on Climate Change, Agriculture and Food Security (20)

CGIAR-AICCRA Knowledge Management Guide (2021)
CGIAR-AICCRA Knowledge Management Guide (2021)CGIAR-AICCRA Knowledge Management Guide (2021)
CGIAR-AICCRA Knowledge Management Guide (2021)
 
Achieving NDC Ambition in Agriculture: How much does agriculture contribute t...
Achieving NDC Ambition in Agriculture: How much does agriculture contribute t...Achieving NDC Ambition in Agriculture: How much does agriculture contribute t...
Achieving NDC Ambition in Agriculture: How much does agriculture contribute t...
 
Achieving NDC Ambition in Agriculture: Mitigation ambition in new & updated N...
Achieving NDC Ambition in Agriculture: Mitigation ambition in new & updated N...Achieving NDC Ambition in Agriculture: Mitigation ambition in new & updated N...
Achieving NDC Ambition in Agriculture: Mitigation ambition in new & updated N...
 
Achieving NDC Ambition in Agriculture: Overview of NDC ambition in the agricu...
Achieving NDC Ambition in Agriculture: Overview of NDC ambition in the agricu...Achieving NDC Ambition in Agriculture: Overview of NDC ambition in the agricu...
Achieving NDC Ambition in Agriculture: Overview of NDC ambition in the agricu...
 
CCAFS and GRA Resources for CLIFF-GRADS 2021
CCAFS and GRA Resources for CLIFF-GRADS 2021CCAFS and GRA Resources for CLIFF-GRADS 2021
CCAFS and GRA Resources for CLIFF-GRADS 2021
 
CSA Monitoring: Understanding adoption, synergies and tradeoffs at farm and h...
CSA Monitoring: Understanding adoption, synergies and tradeoffs at farm and h...CSA Monitoring: Understanding adoption, synergies and tradeoffs at farm and h...
CSA Monitoring: Understanding adoption, synergies and tradeoffs at farm and h...
 
Livestock and sustainability in changing climate: Impacts and global best pra...
Livestock and sustainability in changing climate: Impacts and global best pra...Livestock and sustainability in changing climate: Impacts and global best pra...
Livestock and sustainability in changing climate: Impacts and global best pra...
 
Plant-based protein market in Asia
Plant-based protein market in AsiaPlant-based protein market in Asia
Plant-based protein market in Asia
 
ADB ESLAP case study outputs and synthesis results: Sustainable livestock gui...
ADB ESLAP case study outputs and synthesis results: Sustainable livestock gui...ADB ESLAP case study outputs and synthesis results: Sustainable livestock gui...
ADB ESLAP case study outputs and synthesis results: Sustainable livestock gui...
 
ADB ESLAP Case Study "Dairy value chain in Indonesia"
ADB ESLAP Case Study "Dairy value chain in Indonesia"ADB ESLAP Case Study "Dairy value chain in Indonesia"
ADB ESLAP Case Study "Dairy value chain in Indonesia"
 
Assessment of the environmental sustainability of plant-based meat and pork: ...
Assessment of the environmental sustainability of plant-based meat and pork: ...Assessment of the environmental sustainability of plant-based meat and pork: ...
Assessment of the environmental sustainability of plant-based meat and pork: ...
 
Case study on dairy value chain in China
Case study on dairy value chain in ChinaCase study on dairy value chain in China
Case study on dairy value chain in China
 
Global sustainable livestock investment overview
Global sustainable livestock investment overviewGlobal sustainable livestock investment overview
Global sustainable livestock investment overview
 
The impact of mechanization in smallholder rice production in Nigeria
The impact of mechanization in smallholder rice production in NigeriaThe impact of mechanization in smallholder rice production in Nigeria
The impact of mechanization in smallholder rice production in Nigeria
 
Biodiversity in agriculture for people and planet
Biodiversity in agriculture for people and planetBiodiversity in agriculture for people and planet
Biodiversity in agriculture for people and planet
 
Greenhouse gas (GHG) emissions & priority action in climate mitigation in the...
Greenhouse gas (GHG) emissions & priority action in climate mitigation in the...Greenhouse gas (GHG) emissions & priority action in climate mitigation in the...
Greenhouse gas (GHG) emissions & priority action in climate mitigation in the...
 
Evaluation of Rwanda climate services for agriculture through a gender lens
Evaluation of Rwanda climate services for agriculture through a gender lensEvaluation of Rwanda climate services for agriculture through a gender lens
Evaluation of Rwanda climate services for agriculture through a gender lens
 
Introduction to Climate-Smart Agriculture: Busia County, Kenya
Introduction to Climate-Smart Agriculture: Busia County, KenyaIntroduction to Climate-Smart Agriculture: Busia County, Kenya
Introduction to Climate-Smart Agriculture: Busia County, Kenya
 
Delivering information for national low-emission development strategies: acti...
Delivering information for national low-emission development strategies: acti...Delivering information for national low-emission development strategies: acti...
Delivering information for national low-emission development strategies: acti...
 
Delivering information for national low-emission development strategies: acti...
Delivering information for national low-emission development strategies: acti...Delivering information for national low-emission development strategies: acti...
Delivering information for national low-emission development strategies: acti...
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

Climate data in R with the raster package

  • 1. Climate data in R with the raster package Jacob van Etten
  • 2. Packages There are many packages specifically created for R that allow you to do specialized tasks. One of these packages is raster, created by Robert Hijmans and Jacob van Etten (mainly the former, though). The raster package allows you to work with geographical grid (raster) data.
  • 3. Get raster in RStudio Click on the “Packages” tab in the lower right corner. Click “Install Packages”. Type “raster” and click on “Install”. Leave “Install dependencies” checked. This will also get some other essential packages.
  • 4. Load the package With the following command, we load the package into R. Make sure you put this in the first line of your new script. library(raster) help(package="raster") Thesecondfunctiongivesyouanoverview of thefunctions in thepackage.
  • 5. The raster() function The main function to read raster data into R is called (very conveniently) raster. ?raster Let’s make a raster! r1 <- raster() r1 As you can see, there are no values in the raster. Next thing to solve.
  • 6. Adding values How many values do we need to fill the raster? The function ncell() will tell us. n <- ncell(r1) Let’s make a vector with n random values between 0 and 1 with the function runif(). vals<- runif(n) And we add the values to the raster. values(r1) <- vals
  • 7. Raster graphics We 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 options that plot() gives. ?plot Click “Plot a Raster* object”. Also, take a look at the examples and try some if you want.
  • 8. Real data Let’s get some real data to play with. http://goo.gl/4488T This 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 directory in R. setwd(“D:/yourfolder”)
  • 9. Getting raster data into R Reading 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.
  • 10. Cutting an area of interest The function extents requires a vector of 4 values: {xmin, xmax, ymin, ymax}. For instance: newExtent <- extent(c(60, 100, 0, 40)) Orchooseyourownarea of interest, forinstanceusing Google Earth. Then cut the new extent out of r2 and visualize. r3 <- crop(r2, newExtent) plot(r3)
  • 11. Raster algebra It is very convenient to calculate with rasters. Try this and visualize the result. r4 <- r3 + sqrt(r3) What happens when you do the following and why? r5 <- r2 + r3
  • 12. Some operations Aggregating cells means the grid becomes coarser. By default the function aggregate() will take the mean of the cells it will aggregate. r6 <- aggregate(r2, fact=2) Now take a look at the examples under ?aggregate and try to understand what happens.
  • 13. Interpolation See if you can work this out for yourself. Take a look at the first example of ?interpolate
  • 14. Sources of data For an overview of a lot of relevant climate and weather data, visit this website: http://iridl.ldeo.columbia.edu/
  • 15. Moreover... Worldclim data are global climate data (get it using the raster package, getData function) NCDC-NOAA – Global Summary of Day, weather data from thousands of stations (weatherData package) CCAFS data
  • 16. Worldclim Precipitation at 10 minute resolution wc <- getData(“worldclim”, var=“prec”, res=10) plot(wc)
  • 17. Global Summary of Day Available from: ftp://ftp.ncdc.noaa.gov/pub/data/gsod/ These data are massive. Use the weatherData package to download these data.