diff --git a/MCWD.R b/RasterMCWD.R similarity index 60% rename from MCWD.R rename to RasterMCWD.R index 3f83cd1..8321276 100644 --- a/MCWD.R +++ b/RasterMCWD.R @@ -1,9 +1,11 @@ -## MCWD (Maximum Cumulative Water Deficit) Script ## +## MCWD (Maximun Cumulative Water Deficit) Script ## # Reference: https://agupubs.onlinelibrary.wiley.com/doi/10.1029/2006GL028946 # + # Library library(raster) +library(snow) -setwd("Working-Directory") # Directory with Monthly Rainfall Rasters +setwd("directory-here") # Directory with Monthly Rainfall Rasters # List of Monthly Rainfall Rasters month.rainfall = list.files("./", pattern = '.tif$', full.names = T) @@ -31,17 +33,19 @@ mcwd.f = function(x){ return(result) } - -# Applying the Function -cwd = calc(wd, fun = mcwd.f) - +# Applying the Function (Parallel) +beginCluster(n=10) #Change according to the number of core on your computer +cwd = clusterR(wd, calc, args=list(fun=mcwd.f)) +endCluster() +writeRaster(cwd, "./MCWD/CWD_1981_2020.tif") # Saving the Monthly CWD # Determining the Annual MCDW -ano = 2006 # Start Year of the Temporal Series -for (i in seq(1,132,12)) { # Replace 132 by the Total Months of the Time Series +ano = 1981 # Start Year of the Temporal Series +for (i in seq(1,Y_Y,12)) { # Replace "Y_Y" by the Total Months of the Time Series cwd.a = cwd[[i:(i+11)]] mcwd.a = min(cwd.a) - + j = 121188*(1980-ano) + mcwd.a[mcwd.a == j] = NA # Saving the Annual MCWD print(paste0(ano, " - ", Sys.time())) writeRaster(mcwd.a, paste0("./MCWD/MCWD_", ano, ".tif")) # Create a Folder Called "MCWD" in your Working Directory