Title: | Precipitation R Recipes |
---|---|
Description: | An open-access tool/framework to download, validate, visualize, and analyze multi-source precipitation data. More information and an example of implementation can be found in Vargas Godoy and Markonis (2023, <doi:10.1016/j.envsoft.2023.105711>). |
Authors: | Mijael Rodrigo Vargas Godoy [aut, cre] , Yannis Markonis [aut, ths] |
Maintainer: | Mijael Rodrigo Vargas Godoy <[email protected]> |
License: | GPL-3 |
Version: | 3.0.2 |
Built: | 2024-11-22 05:08:42 UTC |
Source: | https://github.com/mirovago/precipe |
The function crop_data
crops the data sets using a shapefile mask.
crop_data(x, y) ## S4 method for signature 'Raster' crop_data(x, y) ## S4 method for signature 'data.table' crop_data(x, y) ## S4 method for signature 'character' crop_data(x, y)
crop_data(x, y) ## S4 method for signature 'Raster' crop_data(x, y) ## S4 method for signature 'data.table' crop_data(x, y) ## S4 method for signature 'character' crop_data(x, y)
x |
Raster* object; data.table (see details); filename (character; see details) |
y |
filename (character). Path to a *.shp file |
If 'x' is a data.table, its columns should be named: "lon", "lat", "date", and "value"
If 'x' is a filename, it should point to a *.nc file.
Raster* object; data.table
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) s <- crop_data(r, "cze.shp") ## End(Not run)
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) s <- crop_data(r, "cze.shp") ## End(Not run)
Function for calculating the critical success index.
csi(x, ref, th)
csi(x, ref, th)
x |
a data.table generated by |
ref |
a data.table with data used for evaluation |
th |
numeric. The value for detection threshold |
numeric
The function download_data
downloads the selected data product.
download_data( dataset = "all", path = ".", domain = "raw", timestep = "monthly" )
download_data( dataset = "all", path = ".", domain = "raw", timestep = "monthly" )
dataset |
a character string with the name(s) of the desired data set. Suitable options are:
|
path |
a character string with the path where the database will be downloaded. |
domain |
a character string with the desired domain data set. Suitable options are:
|
timestep |
a character string with the desired time resolution. Suitable options are:
|
No return value, called to download the required data sets.
download_data("gldas-vic", tempdir(), timestep = "yearly")
download_data("gldas-vic", tempdir(), timestep = "yearly")
Function for downloading E-OBS.
download_e_obs(folder_path = ".", time_res = "monthly")
download_e_obs(folder_path = ".", time_res = "monthly")
folder_path |
a character string with the path where the data will be downloaded. |
time_res |
a character string with the desired time resolution. Suitable options are:
|
No return value, called to download the data set.
Function for calculating the false alarm rate.
far(x, ref, th)
far(x, ref, th)
x |
a data.table generated by |
ref |
a data.table with data used for evaluation |
th |
numeric. The value for detection threshold |
numeric
The function fldmean
computes the spatial weighted average for each timestep.
fldmean(x) ## S4 method for signature 'Raster' fldmean(x) ## S4 method for signature 'data.table' fldmean(x) ## S4 method for signature 'character' fldmean(x)
fldmean(x) ## S4 method for signature 'Raster' fldmean(x) ## S4 method for signature 'data.table' fldmean(x) ## S4 method for signature 'character' fldmean(x)
x |
Raster* object; data.table (see details); filename (character, see details) |
If 'x' is a data.table, its columns should be named: "lon", "lat", "date", and "value"
If 'x' is a filename, it should point to a *.nc file.
data.table
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) s <- fldmean(r) ## End(Not run)
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) s <- fldmean(r) ## End(Not run)
The function infoNC
displays the specification of the desired file.
infoNC(x) ## S4 method for signature 'Raster' infoNC(x) ## S4 method for signature 'character' infoNC(x)
infoNC(x) ## S4 method for signature 'Raster' infoNC(x) ## S4 method for signature 'character' infoNC(x)
x |
Raster* Object; character |
The function label
adds data set name and source type.
label(x, y)
label(x, y)
x |
data.table (see details) |
y |
character (see details) |
columns in 'x' should be named (if present): "lon", "lat", "date", and "value"
Available options are:
"20cr" for 20CR v3,
"chirps" for CHIRPS v2.0,
"cmap" for CMAP standard version,
"cmorph" for CMORPH,
"cpc" for CPC-Global,
"cru-ts" for CRU_TS v4.06,
"em-earth" for EM-EARTH,
"era20c" for ERA-20C,
"era5" for ERA5,
"fldas" for FLDAS,
"ghcn" for GHCN-M v2,
"gldas-clsm" for GLDAS CLSM,
"gldas-noah" for GLDAS NOAH,
"gldas-vic" for GLDAS VIC,
"gleam" for GLEAM v3.7a,
"gpcc" for GPCC v2020,
"gpcp" for GPCP v2.3,
"gpm_imerg" for GPM IMERGM Final v06,
"jra55" for JRA-55,
"merra2" for MERRA-2,
"mswep" for MSWEP v2.8,
"ncep-doe" for NCEP/DOE,
"ncep-ncar" for NCEP/NCAR,
"persiann" for PERSIANN-CDR,
"precl" for PREC/L,
"terraclimate" for TerraClimate,
"trmm-3b43" for TRMM 3B43 v7,
"udel" for UDEL v501.
data.table
## Not run: r <- data.table::data.table("date" = as.Date("2000-01-01"), "value" = 42) s <- label(r, "mswep") ## End(Not run)
## Not run: r <- data.table::data.table("date" = as.Date("2000-01-01"), "value" = 42) s <- label(r, "mswep") ## End(Not run)
The function muldpm
multiplies the value by days per month.
muldpm(x) ## S4 method for signature 'Raster' muldpm(x) ## S4 method for signature 'data.table' muldpm(x) ## S4 method for signature 'character' muldpm(x)
muldpm(x) ## S4 method for signature 'Raster' muldpm(x) ## S4 method for signature 'data.table' muldpm(x) ## S4 method for signature 'character' muldpm(x)
x |
Raster* object; data.table (see details); filename (character, see details) |
'x' object with monthly data in [units/day]
If 'x' is a data.table, its columns should be named: "lon", "lat", "date", and "value"
If 'x' is a filename, it should point to a *.nc file.
Raster* object; data.table
## Not run: tavg_brick <- raster::brick('terraclimate_tavg.nc') pet_od <- pet(method = "od", tavg = tavg_brick) pet_od <- muldpm(pet_od) ## End(Not run)
## Not run: tavg_brick <- raster::brick('terraclimate_tavg.nc') pet_od <- pet(method = "od", tavg = tavg_brick) pet_od <- muldpm(pet_od) ## End(Not run)
Function for calculating the Nash–Sutcliffe efficiency.
nse(x, ref)
nse(x, ref)
x |
a data.table generated by |
ref |
a data.table with data used for evaluation |
numeric
Convenient and aesthetic visualization of data in a boxplot.
plot_box(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'Raster' plot_box(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'data.table' plot_box(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'character' plot_box(x, var = "Precipitation", unit = "mm")
plot_box(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'Raster' plot_box(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'data.table' plot_box(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'character' plot_box(x, var = "Precipitation", unit = "mm")
x |
Raster* object; data.table (see details); filename (character, see details) |
var |
character (see details) |
unit |
character (see details) |
If 'x' is a data.table, its columns should be named: "lon", "lat", "date", and "value"
If 'x' is a filename, it should point to a *.nc file.
'var' is a character string describing the variable to be used for the plot title
'unit' is a character string describing the unit of measurement to be used for the plot title
ggplot object
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) s <- plot_box(r) ## End(Not run)
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) s <- plot_box(r) ## End(Not run)
Convenient and aesthetic visualization of data in a histogram.
plot_density(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'Raster' plot_density(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'data.table' plot_density(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'character' plot_density(x, var = "Precipitation", unit = "mm")
plot_density(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'Raster' plot_density(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'data.table' plot_density(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'character' plot_density(x, var = "Precipitation", unit = "mm")
x |
Raster* object; data.table (see details); filename (character, see details) |
var |
character (see details) |
unit |
character (see details) |
If 'x' is a data.table, its columns should be named: "lon", "lat", "date", and "value"
If 'x' is a filename, it should point to a *.nc file.
'var' is a character string describing the variable to be used for the axis title
'unit' is a character string describing the unit of measurement to be used for the axis title
ggplot object
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) s <- plot_density(r) ## End(Not run)
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) s <- plot_density(r) ## End(Not run)
Convenient and aesthetic visualization of data in a heatmap.
plot_heatmap(x, unit = "mm") ## S4 method for signature 'Raster' plot_heatmap(x, unit = "mm") ## S4 method for signature 'data.table' plot_heatmap(x, unit = "mm") ## S4 method for signature 'character' plot_heatmap(x, unit = "mm")
plot_heatmap(x, unit = "mm") ## S4 method for signature 'Raster' plot_heatmap(x, unit = "mm") ## S4 method for signature 'data.table' plot_heatmap(x, unit = "mm") ## S4 method for signature 'character' plot_heatmap(x, unit = "mm")
x |
Raster* object; data.table (see details); filename (character, see details) |
unit |
character (see details) |
If 'x' is a data.table, its columns should be named: "lon", "lat", "date", and "value"
If 'x' is a filename, it should point to a *.nc file.
'unit' is a character string describing the unit of measurement to be used for the axis title
ggplot object
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) s <- plot_heatmap(r) ## End(Not run)
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) s <- plot_heatmap(r) ## End(Not run)
Convenient and aesthetic visualization of data in a line plot.
plot_line(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'Raster' plot_line(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'data.table' plot_line(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'character' plot_line(x, var = "Precipitation", unit = "mm")
plot_line(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'Raster' plot_line(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'data.table' plot_line(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'character' plot_line(x, var = "Precipitation", unit = "mm")
x |
Raster* object; data.table (see details); filename (character, see details) |
var |
character (see details) |
unit |
character (see details) |
If 'x' is a data.table, its columns should be named: "lon", "lat", "date", and "value"
If 'x' is a filename, it should point to a *.nc file.
'var' is a character string describing the variable to be used for the axis title
'unit' is a character string describing the unit of measurement to be used for the axis title
ggplot object
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) s <- plot_line(r) ## End(Not run)
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) s <- plot_line(r) ## End(Not run)
Convenient and aesthetic visualization of data in a map
plot_map(x, layer = 1, unit = "mm", timestamp = TRUE) ## S4 method for signature 'Raster' plot_map(x, layer = 1, unit = "mm", timestamp = TRUE) ## S4 method for signature 'data.table' plot_map(x, layer = 1, unit = "mm", timestamp = TRUE) ## S4 method for signature 'character' plot_map(x, layer = 1, unit = "mm", timestamp = TRUE)
plot_map(x, layer = 1, unit = "mm", timestamp = TRUE) ## S4 method for signature 'Raster' plot_map(x, layer = 1, unit = "mm", timestamp = TRUE) ## S4 method for signature 'data.table' plot_map(x, layer = 1, unit = "mm", timestamp = TRUE) ## S4 method for signature 'character' plot_map(x, layer = 1, unit = "mm", timestamp = TRUE)
x |
Raster* object; data.table (see details); filename (character, see details) |
layer |
numeric |
unit |
character |
timestamp |
logical |
If 'x' is a data.table, its columns should be named: "lon", "lat", "date", and "value"
If 'x' is a filename, it should point to a *.nc file.
'unit' is a character string describing the unit of measurement to be used for the legend title
'layer' is the layer number to be plotted.
‘timestamp' if TRUE (default) the plot title is the layer’s date
ggplot object
Convenient and aesthetic visualization of data in a summary plot.
plot_summary(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'Raster' plot_summary(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'data.table' plot_summary(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'character' plot_summary(x, var = "Precipitation", unit = "mm")
plot_summary(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'Raster' plot_summary(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'data.table' plot_summary(x, var = "Precipitation", unit = "mm") ## S4 method for signature 'character' plot_summary(x, var = "Precipitation", unit = "mm")
x |
Raster* object; data.table (see details); filename (character, see details) |
var |
character (see details) |
unit |
character (see details) |
If 'x' is a data.table, its columns should be named: "lon", "lat", "date", and "value"
If 'x' is a filename, it should point to a *.nc file.
'var' is a character string describing the variable to be used for the axis title
'unit' is a character string describing the unit of measurement to be used for the axis title
ggplot object
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) s <- plot_summary(r) ## End(Not run)
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) s <- plot_summary(r) ## End(Not run)
Convenient and aesthetic visualization of data in a Taylor diagram.
plot_taylor(x, y, groups = "source", ...)
plot_taylor(x, y, groups = "source", ...)
x |
data.table |
y |
data.table |
groups |
character |
... |
see details |
'x' columns should be named: "lon", "lat", "date", "value", "dataset", and "source". The last two columns are added using the label
.
'y' columns should be named: "lon", "lat", "date", "value", "dataset", and "source". The last two columns are added using the label
.
'groups' character to define panels. Suitable options are:
"source" (default)
"seasons" (only works properly with monthly data)
'...' extra arguments passed on to openair::TaylorDiagram
plot object
Function for calculating the probability of detection.
pod(x, ref, th)
pod(x, ref, th)
x |
a data.table generated by |
ref |
a data.table with data used for evaluation |
th |
numeric. The value for detection threshold |
numeric
Function for various masks.
pRecipe_masks()
pRecipe_masks()
data.table
The function remap
aggregates data into a new grid resolution.
remap(x, y) ## S4 method for signature 'Raster' remap(x, y) ## S4 method for signature 'data.table' remap(x, y) ## S4 method for signature 'character' remap(x, y)
remap(x, y) ## S4 method for signature 'Raster' remap(x, y) ## S4 method for signature 'data.table' remap(x, y) ## S4 method for signature 'character' remap(x, y)
x |
Raster* object; data.table (see details); filename (character, see details) |
y |
numeric |
If 'x' is a data.table, its columns should be named: "lon", "lat", "date", and "value"
If 'x' is a filename, it should point to a *.nc file.
Raster* object; data.table
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) s <- remap(r, 1) ## End(Not run)
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) s <- remap(r, 1) ## End(Not run)
Function to save data compatible with pRecipe in .nc file
saveNC(x, file, name = "tp", longname = "Total precipitation", units = "mm")
saveNC(x, file, name = "tp", longname = "Total precipitation", units = "mm")
x |
Raster* object |
file |
character |
name |
character |
longname |
character |
units |
character |
No return value, called to save a file
## Not run: save_nc(dummie_brick, "gpcp_tp_mm_global_197901_202205_025_monthly.nc") ## End(Not run)
## Not run: save_nc(dummie_brick, "gpcp_tp_mm_global_197901_202205_025_monthly.nc") ## End(Not run)
The function subset_data
subsets the data in space within a bounding box, and/or in time within a year range.
subset_data(x, box = NULL, yrs = NULL) ## S4 method for signature 'Raster' subset_data(x, box = NULL, yrs = NULL) ## S4 method for signature 'data.table' subset_data(x, box = NULL, yrs = NULL) ## S4 method for signature 'character' subset_data(x, box = NULL, yrs = NULL)
subset_data(x, box = NULL, yrs = NULL) ## S4 method for signature 'Raster' subset_data(x, box = NULL, yrs = NULL) ## S4 method for signature 'data.table' subset_data(x, box = NULL, yrs = NULL) ## S4 method for signature 'character' subset_data(x, box = NULL, yrs = NULL)
x |
Raster* object; data.table (see details); filename (character, see details) |
box |
numeric. Bounding box in the form: (xmin, xmax, ymin, ymax) |
yrs |
numeric. Time range in the form: (start_year, end_year) |
If 'x' is a data.table, its columns should be named: "lon", "lat", "date", and "value"
If 'x' is a filename, it should point to a *.nc file.
If subsetting only in space or time then the arguments must be passed by name. I.e., subset_data(x, box = ...)
(space) or subset_data(x, yrs = ...)
(time)
Raster* object; data.table
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) sd <- subset_data(r, c(12.24, 18.85, 48.56, 51.12), c(2000, 2010)) ss <- subset_data(r, box = c(12.24, 18.85, 48.56, 51.12)) st <- subset_data(r, yrs = c(2000, 2010)) ## End(Not run)
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) sd <- subset_data(r, c(12.24, 18.85, 48.56, 51.12), c(2000, 2010)) ss <- subset_data(r, box = c(12.24, 18.85, 48.56, 51.12)) st <- subset_data(r, yrs = c(2000, 2010)) ## End(Not run)
Function to transform a raster brick into a data.table
tabular(x) ## S4 method for signature 'Raster' tabular(x) ## S4 method for signature 'character' tabular(x)
tabular(x) ## S4 method for signature 'Raster' tabular(x) ## S4 method for signature 'character' tabular(x)
x |
Raster* object; filename (character, see details) |
data.table
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) s <- tabular(r) ## End(Not run)
## Not run: download_data("gldas-vic", tempdir(), timestep = "yearly") r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_yearly.nc")) s <- tabular(r) ## End(Not run)
The function trend
computes linear slope.
trend(x) ## S4 method for signature 'Raster' trend(x) ## S4 method for signature 'data.table' trend(x) ## S4 method for signature 'character' trend(x)
trend(x) ## S4 method for signature 'Raster' trend(x) ## S4 method for signature 'data.table' trend(x) ## S4 method for signature 'character' trend(x)
x |
Raster* object; data.table (see details); filename (character, see details) |
If 'x' is a data.table, its columns should be named: "lon", "lat", "date", and "value"
If 'x' is a filename, it should point to a *.nc file.
Raster* object; data.table
The function yearstat
aggregates the data from monthly to yearly.
yearstat(x, stat = "sum") ## S4 method for signature 'Raster' yearstat(x, stat = "sum") ## S4 method for signature 'data.table' yearstat(x, stat = "sum") ## S4 method for signature 'character' yearstat(x, stat = "sum")
yearstat(x, stat = "sum") ## S4 method for signature 'Raster' yearstat(x, stat = "sum") ## S4 method for signature 'data.table' yearstat(x, stat = "sum") ## S4 method for signature 'character' yearstat(x, stat = "sum")
x |
Raster* object; data.table (see details); filename (character, see details) |
stat |
character |
If 'x' is a data.table, its columns should be named: "lon", "lat", "date", and "value"
If 'x' is a filename, it should point to a *.nc file.
'stat' is a character string describing the desired aggregation function. Suitable options are:
"max"
"mean"
"median"
"min"
"sum" (default)
Raster* object; data.table
## Not run: download_data("gldas-vic", path = tempdir()) r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_monthly.nc")) s <- yearstat(r, "mean") ## End(Not run)
## Not run: download_data("gldas-vic", path = tempdir()) r <- raster::brick(paste0(tempdir(), "/gldas-vic_tp_mm_land_194801_201412_025_monthly.nc")) s <- yearstat(r, "mean") ## End(Not run)