Learn R Programming

chirps (version 0.1.4)

get_chirps: Get CHIRPS precipitation data

Description

Get daily precipitation data from the "Climate Hazards Group". Two server sources are available. The first, "CHC" (default) is recommended for multiple data-points, while "ClimateSERV" is recommended when few data-points are required (~ 50).

Usage

get_chirps(object, dates, server, ...)

# S3 method for default get_chirps(object, dates, server, as.matrix = FALSE, ...)

# S3 method for SpatVector get_chirps(object, dates, server = "CHC", as.raster = TRUE, ...)

# S3 method for SpatRaster get_chirps( object, dates, server = "CHC", as.matrix = TRUE, as.raster = FALSE, ... )

# S3 method for sf get_chirps(object, dates, server, as.sf = FALSE, ...)

# S3 method for geojson get_chirps(object, dates, server, as.geojson = FALSE, ...)

Arguments

object

input, an object of class data.frame (or any other object that can be coerced to data.frame), SpatVector, SpatRaster, sf or geojson

dates

a character of start and end dates in that order in the format "YYYY-MM-DD"

server

a character that represent the server source "CHC" or "ClimateSERV"

...

additional arguments passed to terra or sf methods See details

as.matrix

logical, returns an object of class matrix

as.raster

logical, returns an object of class SpatRaster

as.sf

logical, returns an object of class sf

as.geojson

logical, returns an object of class geojson

Value

A matrix, raster or a data frame of CHIRPS data:

id

the index for the rows in object

dates

the dates from which CHIRPS was requested

lon

the longitude as provided in object

lat

the latitude as provided in object

chirps

the CHIRPS value in mm

Details

Data description at https://data.chc.ucsb.edu/products/CHIRPS-2.0/README-CHIRPS.txt

Additional arguments when using server = "CHC"

resolution: numeric, resolution of CHIRPS tiles either 0.05 (default) or 0.25 degrees

Additional arguments when using server = "ClimateSERV"

dist: numeric, buffer distance for each object coordinate

nQuadSegs: integer, number of segments per buffer quadrant

operation: supported operations for ClimateSERV are:

operation value
max = 0
min = 1
median = 2
sum = 4
average = 5 (default value)

References

Funk C. et al. (2015). Scientific Data, 2, 150066. 10.1038/sdata.2015.66

Examples

Run this code
# NOT RUN {
library("chirps")
library("terra")

# Case 1: return as a data.frame
dates <- c("2017-12-15","2017-12-31")
lonlat <- data.frame(lon = c(-55.0281,-54.9857), lat = c(-2.8094, -2.8756))

r1 <- get_chirps(lonlat, dates, server = "CHC")

# Case 2: return a matrix
r2 <- get_chirps(lonlat, dates, server = "CHC", as.matrix = TRUE)

# Case 3: input SpatVector and return raster
f <- system.file("ex/lux.shp", package = "terra")
v <- vect(f)
r3 <- get_chirps(v, dates, server = "CHC", as.raster = TRUE)

# Case 4: using the server "ClimateSERV"
r4 <- get_chirps(lonlat, dates, server = "ClimateSERV")

# Case 5: from "ClimateSERV" and return as a matrix
r5 <- get_chirps(lonlat, dates, server = "ClimateSERV", as.matrix = TRUE)

# }

Run the code above in your browser using DataLab