Title: | Terrestrial Water Cycle |
---|---|
Description: | An open-access tool/framework that constitutes the core functions to analyze terrestrial water cycle data across various spatio-temporal scales. |
Authors: | Mijael Rodrigo Vargas Godoy [aut, cre] , Yannis Markonis [aut] |
Maintainer: | Mijael Rodrigo Vargas Godoy <[email protected]> |
License: | GPL-3 |
Version: | 0.0.1 |
Built: | 2024-12-07 03:07:48 UTC |
Source: | https://github.com/imarkonis/twc |
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
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 |
character
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
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)