Search code examples
rdataframedownloadrow

Issues downloading CHIRPS data in R


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:

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

dt <- get_chirps(lonlat, dates)

Am I doing something wrong here?


Solution

  • 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