UKCP18 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", "61-vis-stars.R"))
speed_meta <- readr::read_csv(file.path(path_cleaned, "ukcp18-speed_01_metadata.csv"))
#> Parsed with column specification:
#> cols(
#> file = col_character(),
#> rcp = 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
rcps <- unique(speed_meta$rcp)
periods <- unique(subset(speed_meta, select = c("from_year", "to_year")))
for (x in rcps) {
meta_rcp <- subset(speed_meta, rcp == x)
purrr::walk2(periods$from_year, periods$to_year,
~ soil_moisture_metadata(meta_rcp, .x, .y, awc, vars = c("pr", "peti"),
path_cleaned, path_processed))
}
Visualize soil moisture surplus
for (x in rcps) {
cat("\n\n")
cat(paste0("## ", toupper(x), "\n\n"))
pattern <- paste("^ukcp18-speed", x, "01_sms_uk", sep = "_")
sms <- read_sce_var(path_processed, pattern)
plot_sms(sms, nbreaks = 15, uk, main = paste0(toupper(x), " SMS:"))
}
RCP85
Visualize soil moisture deficit
for (x in rcps) {
cat("\n\n")
cat(paste0("### ", toupper(x), "\n\n"))
pattern <- paste("^ukcp18-speed", x, "01_smd_uk", sep = "_")
smd <- read_sce_var(path_processed, pattern)
plot_smd(smd, nbreaks = 15, uk, main = paste0(toupper(x), " SMD:"))
}
RCP85
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 112.814 10.986 123.626