Print This Post Print This Post

RWikience: introduction tutorial

R Logo

All data in Climate Wikience are directly accessible from R using RWikience package

RWikience package allows to retrieve raster, time series data from Climate Wikience to R and also contains related utility fuctions. Steps to get data into R:

  1. Download and install R from www.r-project.org/
  2. Download and install an IDE like RStudio www.rstudio.com/ide/
  3. Install rJava package (you will need this to run RWikience)
  4. You can install rJava by typing the following code in R console:
    install.packages(“rJava”)
  5. Download RWikience package and install it into R
  6. RWikience_path <- "path to where you downloaded RWikience package tar.gz";
    install.packages(RWikience_path, repos = NULL, type = "source")
     
    # Example (use "/" or "\\" in Windows):
    RWikience_path <- "C:/Users/User/WikienceFiles/RWikience_1.1-0.tar.gz"
    install.packages(RWikience_path, repos = NULL, type = "source")
  7. Launch Climate Wikience (RWikience will work only when Climate Wikience is currently running)

The following two commands are required to start working with RWikience

# Load RWikience package
library(RWikience)
 
# Connect to running instance of Climate Wikience on your PC
w<-WikienceConnect()

To retrieve global maps (raster data), use getFloatMatrix function:

# Retrieve global matrix of NO2 concentration for 1-st of October 2004
m <- getFloatMatrix(w, "OMI.Nitrogen dioxide.ColumnAmountNO2TropCloudScreened", "01 10 2004")

To enable many other ways of processing data, convert the matrix to “raster” type of “raster” package:

# Load "raster" package
library(raster)
 
# Convert to R type "raster"
r <- convertToRaster(m)

Simply type “r” to view the properties of newly created raster:

> r
class       : RasterLayer 
dimensions  : 720, 1440, 1036800  (nrow, ncol, ncell)
resolution  : 0.25, 0.25  (x, y)
extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 
data source : in memory
names       : layer 
values      : -6.343879e+15, 4.233803e+16  (min, max)

Create 2-D map of the global NO2 distribution:

# Visualize raster
plot(r)

You can retrieve other maps in the same way:

m <- getFloatMatrix(w, "MERRA.Wind.Eastward (u).10 m", "01 08 2010")
r <- convertToRaster(m)
plot(r)
 
m <- getFloatMatrix(w, "Modis L3 Atmosphere.AEROSOL.LAND AND OCEAN.Optical Depth.Maximum", "04 08 2005")
r <- convertToRaster(m)
plot(r)

You can take a full dataset name to forward in to “getFloatMatrix” by simply activating it in Climate Wikience and copying its names from Time Slider drop-down box or Properties drop-down box.

R code used in this tutorial [wpdm_file id=7]