chirps icon indicating copy to clipboard operation
chirps copied to clipboard

Using get_chirps over a SFC, possible?

Open MariusHees opened this issue 3 years ago • 7 comments

Hello everyone and thank you very much for all of your amazing work,

I am trying to pull the chirps data for Ethiopia and I am struggling to advance.

This is my first time using CHIRPS, but I am really interested in working myself into the subject. My goal is to get CHIRPS data for ETHIOPIA, I will want to finally de-trend the precipitation averages (either daily or monthly) in order to find abnormalities, in order to identify regional droughts as the basis for me research. Hence, I would ideally have both the precipitation on a pixel by pixel basis and will also be able to connect the pixel to the respective districts.

I am using: https://geodata.lib.berkeley.edu/catalog/stanford-kz352sx7513 : as base input of Ethiopian districts over which I want get the chirps data.

#Problem I am reading in the ETHIPIA District Shapefile above as a SFC_Multipolygon, with the intention of pulling the CHIRPS data for each district over a given period of time. Am I correct in the assumption that the "get_chirps" command is currently only able to pull data for geographic points or is it somehow able to pull the CHIRPS data for entire districts?

I have been trying around a lot but can't figure which approach would work, if you guys have any insights or inputs I would be incredibly grateful. Even if the answer is an affirmation that what I want to do is not possible with the get_chirps command. (Would have to manually load in all the CHIRPS data images.)

The code (ETHIOPIA = The data input):

ETHIOPIA_shp <- st_read(ETHIOPIA)

ETHIOPIAREP_shp <-st_transform(ETHIOPIA_shp, CRS(OGP))

st_write( ETHIOPIAREP_shp, ETHIOPIAREP, format="GTiff", append=FALSE)

SPDF <- readOGR(dsn=ETHIOPIAREPP,layer="ETHIOPIAREP")

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

get_chirps(SPDF, dates, operation = 5)

yields the error :

Fehler in [.data.frame(lonlat, , 2) : undefined columns selected

and if I use:

get_chirps(ETHIOPIAREP_shp, dates, operation = 5)

in the last line, it runs forever without end. This is where I think it might not be possible to run it for multipolygons.

I hope this question / issue is not to far away from the intended use of get_chirps and that I am not wasting your time.

Thank you in advance for any help or input!

All the best, Marius

data(1).zip

MariusHees avatar Oct 21 '21 17:10 MariusHees

For clarity, this is the set up:

ETHIOPIA <- paste0(sourcepath, "/EthiopiaSHAPE")

ETHIOPIAREP <- paste0(datapath, "/IN_PROGRESS/ETHIOPIA/ETHIOPIAREP.shp")

ETHIOPIAREPP <- paste0(datapath, "/IN_PROGRESS/ETHIOPIA")

OGP <- "+proj=longlat +datum=WGS84 +no_defs"

MariusHees avatar Oct 21 '21 18:10 MariusHees

Hello dear team, hello @MariusHees ....

I am facing similar issue (how to retrieve data using get_chirps with a polygon as object input). Is there any update on this issue? @MariusHees, did you managed to work with your district polygons somehow?

Thank you! Kind regards Sllap

samyadelara avatar Jan 14 '22 17:01 samyadelara

Hi @samyadelara and @MariusHees sorry I missed this issue, but this is something that I asked to the ClimateSERV team with @billyz313 in this issue https://github.com/SERVIR/ClimateSERV/issues/3

@billyz313 do you know if this is already available? I tried to find at the API document but I didn't.

As an alternative option we could request the data from the other server CHC as COG files and handle it internally using terra and return either a raster or a sfc polygon. This might be a bit slow but good enough for reproducible analysis and workflows. What do you think @adamhsparks ?

kauedesousa avatar Jan 14 '22 17:01 kauedesousa

I worked in an alternative solution using CHC server. Remember that it may take a while to fetch the data if you request for many years data.

If you install chirps v0.1.4.001 from Github using devtools you will be able to run this example.

library(terra)
library(sf)
library(chirps)

data("tapajos")

area <- st_bbox(tapajos)

area <- as.vector(area)

area <- ext(area)

datas <- c("2010-01-01", "2010-01-15")

rain <- get_chirps(area, datas, server = "CHC")

Is this useful for you?

kauedesousa avatar Jan 14 '22 19:01 kauedesousa

@kauedesousa, I agree handling it internally with terra / sf with just regular rectangular data would be a fine compromise for reproducibility.

adamhsparks avatar Jan 15 '22 02:01 adamhsparks

Dear @kauedesousa and @adamhsparks , thank you so much for your prompt feedback on this and suggestions.

Indeed, working with the bbox, extented using terra, worked perfectly for me here. Thank you so much!

Cheers all!

samyadelara avatar Jan 17 '22 20:01 samyadelara

extnt <- as(extent(c(xmin= 31, xmax= 49, ymin= 2, ymax= 20)), 'SpatialPolygons') crs(extnt) <- "+proj=longlat +datum=WGS84 +no_defs" area <- ext(extnt) dates <- c("2017-12-15","2017-12-31") get_chirps(area, dates, server = "CHC", as.raster = TRUE)

this worked well for me to extract data for the given extent. However, I could not able to extract sample points from the domain. #43 spt <- st_sample(area, 30) spt <- st_as_sf(spt) dft <- get_chirps(spt, dates = c("1990-01-01","2018-12-31")) p_ind <- precip_indices(dft, timeseries = TRUE, intervals = 30)

I hope you found a way to solve this as well. Thank you in advance for any help or input!

All the best,

Markos

albirayi avatar Aug 01 '22 17:08 albirayi