knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(lfcdata)
library(dplyr)

CatDrought database

CatDrought database offers access to drought stress, soil water content and other modeled variables for Catalunya, powered by the medfate R package.

catdroughtdb <- catdrought()
catdroughtdb

Access to the data

CatDrought offers precalculated data at 1km resolution as rasters. This spatial data can be accesed with the catdrought_get_raster function:

Raster formats

This function allows to access the raster for a specified date (as character), and returns a spatial object, whose class depends on the spatial argument. Available classes are raster (a RasterBrick object) and stars (a stars object).

catdrought_get_raster(
  catdroughtdb,
  date = as.character(Sys.Date() - 1),
  spatial = 'stars'
)
catdrought_get_raster(
  catdroughtdb,
  date = as.character(Sys.Date() - 1),
  spatial = 'raster'
)

Dates available

Only a natural year (365 days from the day before current date) are available

catdrought_get_raster(
  catdroughtdb,
  date = as.character(Sys.Date() - 365),
  spatial = 'stars'
)

Time series data for spatial points or polygons

Instead of rasters, we can obtain a table with the time series for a specified variable. This time series covers all the available dates. For this, we can use the catdrought_get_current_time_series function.

Points

This will extract the values for the desired variable on all the dates available, for the set of points provided:

# points spatial object, obtained from fes database
points_sf <- lfcdata::fes()$get_data('plot_nfi_4_results', spatial = TRUE) |>
  slice(1:5)

catdrought_get_current_time_series(
  catdroughtdb,
  sf = points_sf,
  variable = 'Eplant'
)

NOTE: This can take some time depending on the number of features.

The output is a tibble with the following variables:

Polygons

The process is exactly the same as for points:

# points spatial object, obtained from fes database
polygons_sf <- lfcdata::lidar()$get_data('lidar_municipalities', 'AB') |>
  slice(1:5)

catdrought_get_current_time_series(
  catdroughtdb,
  sf = polygons_sf,
  variable = 'Eplant'
)

Here, the mean value for the variable and the 0.1 and 0.9 quantiles are returned for all polygons and dates.

NOTE: This can take some time depending on the number of features.

The output is a tibble with the following variables:

Variables description

Information about Variables available can be accessed with catdroght_describe_var() function:

catdrought_describe_var(catdroughtdb, c('REW', 'DDS'))


MalditoBarbudo/lfcdata documentation built on May 2, 2023, 10:30 p.m.