Issues downloading CHIRPS data in R

Viewed 142

I'm trying to download monthly precipitation data from CHIRPS, but my code keeps throwing an error saying arguments imply differing number of rows. I even tried using the example query from the chirps documentation and I get the same error.

Example:

librray(chirps)

lonlat <- data.frame(lon = c(-55.0281,-54.9857),
                     lat = c(-2.8094, -2.8756))

dates <- c("2017-12-15", "2017-12-31")

dt <- get_chirps(lonlat, dates)

Am I doing something wrong here?

2 Answers

The API developers changed how the API works and we had to update the entire code. We fixed the issue and it is working fine, also for the CRAN version v0.1.4 https://CRAN.R-project.org/package=chirps. Now you can also download data directly from CHG using the argument server. And also download chirts data.

library("chirps")

lonlat <- data.frame(lon = -67.5, lat = -24.5)
dates <- c("1981-01-02", "2020-12-31")
data <- get_chirps(lonlat, dates, server = "ClimateSERV")

data

I recommend using server = "CHC" when you deal with multiple points (>500) and dates at the same time, as it downloads the entire GeoTIFF files using terra

lonlat <- data.frame(lon = -67.5, lat = -24.5)
dates <- c("1981-01-02", "1981-01-04")
data <- get_chirps(lonlat, dates, server = "CHC")

data

The CRAN version is giving the same error. So, we installed the github version and it is working

> library(remotes)
> install_github("ropensci/chirps", build_vignettes = TRUE)
> library(chirps)
> lonlat <- data.frame(lon = c(-55.0281,-54.9857),
+                      lat = c(-2.8094, -2.8756))
> 
> dates <- c("2017-12-15", "2017-12-31")
> 
> get_chirps(lonlat, dates)
Fetching data from CHC server 

Getting CHIRPS in a .05 deg resolution 

       id    lon   lat       date chirps
    <int>  <dbl> <dbl>     <date>  <dbl>
1:      1 -55.03 -2.81 2017-12-15   0.00
2:      1 -55.03 -2.81 2017-12-16   0.00
3:      1 -55.03 -2.81 2017-12-17  13.69
4:      1 -55.03 -2.81 2017-12-18  13.69
5:      1 -55.03 -2.81 2017-12-19   0.00
---                                     
30:     2 -54.99 -2.88 2017-12-27  35.34
31:     2 -54.99 -2.88 2017-12-28  17.67
32:     2 -54.99 -2.88 2017-12-29   0.00
33:     2 -54.99 -2.88 2017-12-30   8.84
34:     2 -54.99 -2.88 2017-12-31   8.84
Related