extractcru: Function for extracting climate data from CRU datasets

Description Usage Arguments Value Examples

View source: R/extractcru.R

Description

A wrapper for raster() function, useful for extracting climate date from CRU datasets in a very straightforward way. All you need to do is put in the CRU dataset file, choose the variable that you want, enter the year and the month, and you will get a dataframe with the desired variable for the given time.

Usage

1
extractcru(file, lon, lat, var, year, month)

Arguments

file

The CRU dataset file, usually with "dat.nc" extension

lon

Longitude value of the coordinate of a given place

lat

Latitude value of the coordinate of a given place

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 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.).

Value

A dataframe with the desired climate parameter (precipitation, temperature, etc.) of a particular place with the given latitude and longitude on the requested year and month.

Examples

 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
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)

year <- 2000

month <- "December"

file <- ("cru_ts4.02.1991.2000.pre.dat.nc")

# Climate parameter (precipitation)
var <- "pre"

lon <- 2.4

lat <- 48.9

datres <- extractcru(file, lon, lat, var, year, month)

file.remove("cru_ts4.02.1991.2000.pre.dat.nc")

ahmad-alkadri/simpleRCRU documentation built on Aug. 15, 2019, 7:24 p.m.