knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Will provide brief background of what SPI is and how it's used (i.e 1mo, 3mo, 6mo, 9mo, etc)
step 1 - load the libraries, custom function, and initialing the GEE API. step 2 - load area of interest, by setting path. If no path is provided we will the Somalia data set that is part of this package
library(surveyGEER) library(rgee) library(tidyverse) library(tidyrgee) library(sf) devtools::load_all() ee_Initialize() adm_zone_of_interest_path <- NULL # here is where you can input a new admin zone for graphing SPI by zone if(!is.null(adm_zone_of_interest_path)){ adm_zone_of_interest <- sf::st_read(adm_zone_of_interest_path) } # if user supplies no zone of interest path - we can use data built into surveyGEER if(is.null(adm_zone_of_interest_path)){ adm_zone_of_interest <- som_adm1 }
We can simply use the ee_chirps_spi
function below to do all the calculations for us. This function loads the chirps
daily data set directly from the GEE API and performs the calculations. Currently, it only accepts window_unit
as month. However, we will soon be updating this to allow days. Nonetheless, month
tends to be the most common window_unit used. It's worth noting that you can moi
can be set to more than 1 month if you are interesting calculating SPI for multiple months. Remember you can always run ?ee_chirps_spi
for additional information
Below we are calculating the 3 month SPI for March. It can take a few minutes. What this will return is an tidyee class object which holds an ee$ImageCollection
. The ImageCollection will contains images where each image is the 3 month (FMA) SPI for April for each year on record.
spi_3<- ee_chirps_spi(window = 3,window_unit = "month",moi = c(3,4,5)) # debugonce(ee_chirps_spi) spi_3<- ee_chirps_spi(window = 3,window_unit = "month",moi = c(5))
# from sample_pt GEE script # https://code.earthengine.google.com/81b35aeecd53a8eaa3f24b58287d6f25?noload=true sample_pt <- data.frame(y =c(48.8768913678698,48.86701823455106,48.82226063783573), x=c(7.405370766109236,6.530191390323885,6.527364875888308) )|> st_as_sf(coords=c("y","x"), crs=4326) sample_pt_ee <- sf_as_ee(sample_pt) leaflet::leaflet(sample_pt) |> leaflet::addTiles() |> leaflet::addMarkers() sample_pt_val <- spi_3 |> filter(year==2022) |> ee_extract_tidy(y = sample_pt_ee,stat = "median",scale = 5500, via = "getInfo") sample_pt_val_from_survey <- sample_pt_val |> pull(value) options(digits=8) sample_vals_from_unosat_img <- c(-1.5136904122787513,1.3624714490958623,-1.3612546106517207) ?float sample_pt_val_from_survey[1]==sample_vals_from_unosat_img[1]
Now that you have this collection of SPI images. Let's extract it to our areas of interest.
To extract our area of interest we can run some zonal statistics with ee_extract_tidy
, For each zone in our area of interest we will calculate the median SPI for each image.
Note: zonal stats using GEE are time-consuming. This could take several minutes, go have a coffee (my first run using the SOM admin 1 zones took 6.8 minutes)
spi_3_adm1 <- spi_3 |> ee_extract_tidy(y= adm_zone_of_interest, stat = "median", scale=5500, via="drive")
Once complete we have a nice tidy data frame containing all the extracted value for each zone. Time to visualize
You might be interested in looking at the JFA 3 month April SPI over time. If you are interested in just looking at one zone at a time you can filter the results data.frame to a specific zone and run spi_bar_plot
awdal_spi_3_april <- spi_3_adm1 |> filter(admin1name=="Awdal") spi_bar_plot(awdal_spi_3_april)
If you have several zones ad want to chart them all at once you can run spi_bar_plot_faceted
making sure to specify the zone
argument as the column with the zone names
spi_bar_plot_faceted(spi_3_adm1,zone ="admin1name")
This part not done!
spi3_202204 <- spi_3 |> filter(month==04, year==2022) |> as_ee() spi3_201504 <- spi_3 |> filter(month==04, year==2015) |> as_ee() sp3_202204_bounded <- spi3_202204$filterBounds(bbox_fc) sp3_201504_bounded <- spi3_201504$filterBounds(bbox_fc) spi3_202204_ee <- ee$Image(sp3_202204_bounded$first()) spi3_201504_ee <- ee$Image(sp3_201504_bounded$first()) spi_vis_params = list(min=-3, max=3, palette=c('#9ecae1, #ffffff, #ffeda0, #feb24c, #f03b20') ) # sp3_202204_bounded$getInfo()] Map$centerObject(bbox_fc,10) Map$addLayer(eeObject = spi3_202204_ee,visParams = spi_vis_params)+ Map$addLayer(eeObject = spi3_201504_ee,visParams = spi_vis_params)
"More than 100 drought indices—such as the SPI [17], Erinç index [18], Percentage of the normal index [19], Palmer drought severity index [20,21], and Exploration drought index (RDI)—are used to determine drought in the world [22]. Among these indices, only the SPI is preferred more because of its use of the fewest meteorological variables (precipitation) and ease and simplicity of calculation at different time intervals. In addition, it allows the determination of both short-term and long-term meteorological and agricultural droughts [23]." Rolbiecki et. al.,2022
good discussion of pros and cons: FAO SWALIM
GRIDMET DROUGHT: CONUS Drought Indices use 1980-2016 as there baseline to calculate SPI.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.