Description Usage Arguments Value Examples
View source: R/extractmatcru.R
A wrapper for raster() function, useful for extracting climate date of a rectangular area from CRU datasets.
1 2  | extractareacru(file, lonmin, lonmax,
latmin, latmax, var, year, month, precision)
 | 
file | 
 The CRU dataset file, usually with ".dat.nc" extension  | 
lonmin | 
 The minimum longitude value of the rectangular area  | 
lonmax | 
 The maximum longitude value of the rectangular area  | 
latmin | 
 The minimum latitude value of the rectangular area  | 
latmax | 
 The maximum latitude value of the rectangular area  | 
var | 
 The variable from the CRU dataset that we would like to obtain, could be "tmp" for temperature, "pre" for precipitation, and so on.  | 
year | 
 A single given year, must be within the span measured in the CRU dataset.  | 
month | 
 A given month, must be from the Gregorian calendar and can be written either in English ("January", "February", etc.) or number (1, 2, 3, etc.).  | 
A matrix with the desired climate values (precipitation, temperature, etc.) of the rectangular region on the requested year and month. Rows refer to latitude and columns refer to longitude.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35  | # Selected time
year <- 2000
month <- "December"
# Selected area: a rectangular region
# from the Central Java island, Indonesia
lonmin <- 104.0
lonmax <- 118.0
latmin <- -9.0
latmax <- -5.0
# Climate parameter (precipitation)
var <- "pre"
# CRU dataset
library(simpleRCRU)
library(R.utils)
# Download the climate dataset
download.file("https://crudata.uea.ac.uk/cru/data/hrg/cru_ts_4.02/cruts.1811131722.v4.02/pre/cru_ts4.02.1991.2000.pre.dat.nc.gz",
              destfile = "cru_ts4.02.1991.2000.pre.dat.nc.gz")
# Unzipping the dataset
gunzip("cru_ts4.02.1991.2000.pre.dat.nc.gz",
remove = TRUE, overwrite = TRUE)
file <- ("cru_ts4.02.1991.2000.pre.dat.nc")
# Coordinate precision of 1 digit behind decimal
precision <- 1
# Matrix with results
matReg <- extractareacru(file, lonmin, lonmax, latmin, latmax,
          var, year, month, precision)
file.remove("cru_ts4.02.1991.2000.pre.dat.nc")
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.