UKCP18 SPEED scenarios: create metadata and convert to tif
Create metadata of datasets corresponding to environmental scenarios for periods of 20
years from UKCP18 SPEED project, and convert them to tif
format. The scenarios
correspond to different assumptions for Representative Concentration Pathway (RCP) which
is related to greenhouse gas concentrations.
Load packages, read data and source custom scripts
rm(list = ls())
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
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_raw <- file.path(path_data, "raw")
path_cleaned <- file.path(path_data, "cleaned")
path_sce <- file.path(path_raw, "ukcp18-speed")
source(file.path(path_proj, "src", "22-nc-to-tif.R"))
Create metadata
regex_extract <- paste(
"ukcp18-speed_(rcp[[:digit:]]+)", "01_(.+)",
"uk_1km_20yr-([[:alpha:]]+)-([[:alpha:]]+)", "([[:digit:]]+)-([[:digit:]]+)\\.nc",
sep = "_"
)
metadata <- create_metadata(path_sce, regex_extract)
Convert to tif
purrr::walk2(metadata$file, metadata$variable,
~ nc_to_tif(.x, .y, path_sce, path_cleaned))
Save metadata
write.csv(metadata, file.path(path_sce, "metadata.csv"), row.names = FALSE)
metadata <- mutate(metadata, file = sub("\\.nc$", "\\.tif", file))
write.csv(metadata, file.path(path_cleaned, "ukcp18-speed_01_metadata.csv"), row.names = FALSE)
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 195.927 10.398 209.502