Untitled
unknown
plain_text
3 years ago
1.9 kB
9
Indexable
library(sf) library(rgee) library(tidyverse) library(rgeeExtra) ee_Initialize() # 1. Global parameters ------------------------------------------------------------------------ shpfile <- "/home/csaybar/Downloads/pts_chiriluman/pts_chiriluman.shp" image_scale <- 27830 data <- ee$ImageCollection("NASA/NEX-GDDP") # 2. Define study area and create a grid ------------------------------------------------------ roi <- read_sf(shpfile) %>% st_bbox() %>% st_as_sfc() %>% st_make_grid(cellsize = image_scale/111111) # 3. Download data by chunks ------------------------------------------------------------------ downloader <- function(geometry, year, variable, mode, scenario) { # Create image collection ic <- data$select(variable) %>% ee$ImageCollection$filter( ee$Filter$date(sprintf('%s-01-01', year), sprintf('%s-01-01', year+1)) ) %>% ee$ImageCollection$filter( ee$Filter$eq("model", model) ) %>% ee$ImageCollection$filter( ee$Filter$eq("scenario", scenario) ) climdata <- ee$Image$reduceRegion( image = ic$toBands(), geometry = geometry, reducer = ee$Reducer$mean(), scale = image_scale ) %>% ee$Dictionary$getInfo() tibble(name=names(climdata), value=as.numeric(climdata)) } year <- 2011 # year geometry <- roi[1] %>% sf_as_ee() # area of study variable <- "pr" # pr, tasmin, tasmax model <- "MRI-CGCM3" # climate model: 'ACCESS1-0', 'bcc-csm1-1', 'BNU-ESM', 'CanESM2', 'CCSM4', 'CESM1-BGC', 'CNRM-CM5', 'CSIRO-Mk3-6-0', 'GFDL-CM3', 'GFDL-ESM2G', 'GFDL-ESM2M', 'inmcm4', 'IPSL-CM5A-LR', 'IPSL-CM5A-MR', 'MIROC-ESM', 'MIROC-ESM-CHEM', 'MIROC5', 'MPI-ESM-LR', 'MPI-ESM-MR', 'MRI-CGCM3', 'NorESM1-M' scenario <- "rcp45" # scenerio: historical rcp45 rcp85 ( where 'historical' designates retrospective model runs (pre-2006).) downloader(geometry, year, variable, mode, scenario)
Editor is loading...