The METsteps package provides functions to streamline the processing of gridded datasets in parallels through the 'sp', 'rgdal', 'raster', 'gdalUtils', and 'velox' packages. The 'velox' package is key in extracting cells by polygon, in that it operates ~150x faster than the 'raster' package and ~4x faster than the python 'rasterstats' module, though it is affected by the effects of in-memory processing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | library(METsteps)
library(parallel)
# Start timing
tic()
# Initialize cluster
cl <- makeCluster(25)
# Aggregate to HUC-10
x <- aggregateRasterToPolygons(dataPath = 'C:/.../SSEBop/',
dataName = 'SSEBop',
dataExtension = 'tif',
dataCategory = 'AET',
startDate = '2000-01-01',
timeStep = 'month',
MET.HUC10 = TRUE,
cl = cl)
# Downscale to HUCs 2-8 and create zoo objects
y <- downscaleHUC10(x)
# Save to folder to access via Shiny app
zooHUCtoFeather(zoo.obj = y,
Shiny.path = 'C:/.../folder/')
# Close cluster
stopCluster(cl)
# Report run time
toc()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.