#***************************************************************************** # Examples function: ShapeToMask # Source: https://earth.bsc.es/gitlab/es/esviz/-/blob/main/R/ShapeToMask.R # An-Chi & Eva (2023) #***************************************************************************** # Exmple (1): NUTS shp_file <- paste0('/esarchive/shapefiles/NUTS3/NUTS_RG_60M_2021_4326.shp/', 'NUTS_RG_60M_2021_4326.shp') ref_grid <- paste0('/esarchive/recon/ecmwf/era5land/monthly_mean/', 'tas_f1h/tas_201006.nc') # ref_grid <- list(lon = seq(10, 40, 0.5), lat = seq(40, 85, 0.5)) NUTS.id <- paste0("FI1D", c(1:3, 5, 7:9)) NUTS.name <- list(FI = c('Lappi', 'Kainuu'), SI = c('Pomurska', 'Podravska')) mask1 <- ShapeToMask(shp_file, ref_grid, reg_ids = NUTS.id) mask2 <- ShapeToMask(shp_file = shp_file, ref_grid = ref_grid, reg_names = NUTS.name) # Exmple (2): GADM shp_file <- "/esarchive/shapefiles/gadm_country_mask/gadm_country_ISO3166.shp" ref_grid <- paste0('/esarchive/exp/ecmwf/s2s-monthly_ensfor/weekly_mean/', 'tas_f6h/tas_20191212.nc') GADM.id <- c("ESP", "ITA") GADM.name <- c("Spain", "Italy") mask1 <- ShapeToMask(shp_file = shp_file, ref_grid = ref_grid, reg_ids = GADM.id, shp_system = "GADM") mask2 <- ShapeToMask(shp_file = shp_file, ref_grid = ref_grid, reg_names = GADM.name, shp_system = "GADM")