SPEED escenarios: compute soil moisture deficit and surplus
Computing soil moisture deficit and surplus using:
- total monthly potential evapotranspiration
- total monthly precipitation
- available water-holding capacity
Load packages, read data and source custom scripts
rm(list = ls())
library(stars)
#> Loading required package: abind
#> Loading required package: sf
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
path_proj <- day2day::git_path()
path_data <- file.path(path_proj, "data")
path_cleaned <- file.path(path_data, "cleaned")
path_processed <- file.path(path_data, "processed")
source(file.path(path_proj, "src", "32-soil-moisture.R"))
source(file.path(path_proj, "src", "34-read-sce-var.R"))
source(file.path(path_proj, "src", "60-vis-stars.R"))
speed_meta <- readr::read_csv(file.path(path_cleaned, "ukcp18-speed_rcp85_01_metadata.csv"))
#> Parsed with column specification:
#> cols(
#> file = col_character(),
#> variable = col_character(),
#> summary = col_character(),
#> temp_resolution = col_character(),
#> from = col_double(),
#> to = col_double(),
#> from_year = col_double(),
#> from_month = col_double(),
#> to_year = col_double(),
#> to_month = col_double(),
#> description = col_character()
#> )
awc <- read_stars(file.path(path_processed, "ukcp18_uk_1km_soilparams_awc_bc.tif"))
uk <- st_read(file.path(path_cleaned, "uk_simple.gpkg"), "union")
#> Reading layer `union' from data source `/home/rstudio/Documents/Projects/land-suitability/data/cleaned/uk_simple.gpkg' using driver `GPKG'
#> Simple feature collection with 1 feature and 0 fields
#> geometry type: MULTIPOLYGON
#> dimension: XY
#> bbox: xmin: -116.1923 ymin: 7054.099 xmax: 655644.8 ymax: 1218625
#> projected CRS: OSGB 1936 / British National Grid
Compute soil moisture deficit and surplus
periods <- unique(subset(speed_meta, select = c("from_year", "to_year")))
purrr::walk2(periods$from_year, periods$to_year,
~ soil_moisture_metadata(speed_meta, .x, .y, awc, vars = c("pr", "peti"),
path_cleaned, path_processed))
Visualize soil moisture surplus
sms <- read_sce_var(path_processed, "ukcp18-speed_rcp85_01_sms")
plot_sms(sms, nbreaks = 15, uk, main = "sms:")
Visualize soil moisture deficit
smd <- read_sce_var(path_processed, "ukcp18-speed_rcp85_01_smd")
plot_smd(smd, nbreaks = 15, uk, main = "smd:")
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 112.982 10.788 123.770