1/1
3 files

R code for SPI calculations from monthly gridded or point rainfall data

Download all (9 kB)
software
posted on 16.09.2021, 11:40 by Stefaan ConradieStefaan Conradie, Bruce Hewitson, Piotr Wolski
This item contains three R scripts: two with functions for SPI calculations, the other demonstrating the procedure used to compute and store SPI values for GPCC and CRU data over South-Western Southern Africa.

The script `station_SPI.R` contains a function used to compute SPI at a list of point locations, `SPI_grid.R` contains functions to read in a gridded netCDF monthly rainfall file, compute SPI series at all grid points and write the result to RDS and netCDF files on disk. The code in `run_SPI.R` uses the functions in `SPI_grid.R` to compute SPI values at various timescales.

When a function `fun` for a script file have been sourced, documentation for it can be viewed using:
`docstring(fun)`

Suggested directory structure:
scripts should be run from ${root}/R_scripts as the working directory


|-- data
| |-- CRU_404_05deg_SWSA_16-28E_-35--23N.nc
| `-- gpcc_V2020_SWSA_025deg_14-26E_-35.5--26N.nc
|-- figures
`-- R_scripts
|-- run_SPI.R
|-- SPI_grid.R
`-- station_SPI.R

Required R pacakges:
SCI
tidyverse
data.table
metR
docstring
magrittr
ncdf4

GPCC data may be obtained from: http://dx.doi.org/10.5676/DWD_GPCC/FD_M_V2020_025
CRU data are available from: https://crudata.uea.ac.uk/cru/data/hrg/

Using cdo (https://code.mpimet.mpg.de/projects/cdo)
the GPCC data (for example, if the original download is named gpcc.nc) can be processed to the required domain using:

`cdo sellonlatbox,14,26,-35.5,-26 gpcc.nc gpcc_V2020_SWSA_025deg_14-26E_-35.5--26N `

Funding

South African National Research Foundation (NRF) grant 121047

History

Department/Unit

Climate System Analysis Group