You have two options with this package: you can test the images that are already in the package (1), or you can download via download_terraclimate function, the images that you want to analyze (2). In this tutorial we will explain the second option.
#devtools::install_github("FilgueirasR/cropDemand")
#install.packages("cropDemand")
library(cropDemand)
library(raster)
To see the areas that you can analyzed directly, you need to run the see_brazil_biomes or see_brazil_states. These functions have the purpose of guiding the users, when they are going to run the functions download_terraclimate and loadROI (not the case of this tutorial).
see_brazil_biomes()
## [1] "Use the corresponding number:"
## [1] "Caatinga = 1" "Cerrado = 2" "Pantanal = 3"
## [4] "Pampa = 4" "Amazonia = 5" "Mata Atlantica = 6"
see_brazil_states()
## [1] "Use the corresponding number:"
## [1] "Acre = 1" "Alagoas = 2"
## [3] "Amapa = 3" "Amazonas = 4"
## [5] "Bahia = 5" "Ceara = 6"
## [7] "Distrito Federal = 7" "Espirito Santo = 8"
## [9] "Goias = 9" "Maranhao = 10"
## [11] "Mato Grosso = 11" "Mato Grosso do Sul = 12"
## [13] "Minas Gerais = 13" "Parana = 14"
## [15] "Paraiba = 15" "Para = 16"
## [17] "Pernambuco = 17" "Piaui = 18"
## [19] "Rio Grande do Norte = 19" "Rio Grande do Sul = 20"
## [21] " Rio de Janeiro = 21" "Rondonia = 22"
## [23] "Roraima = 23" "Santa Catarina = 24"
## [25] "Sergipe = 25" "Sao Paulo = 26"
## [27] "Tocantins = 27"
The advanced process of running the cropDemand package (considering the download_terraclimate function). Now, you will see how you can download the TerraClimate images. The variable region = "biomes_brazil means that we are going to download some biome of Brazil and the sub_region variable identify what biome we are loading. The numbers of sub_region can be seen in see_brazil_biomes(). For this tutorial, we will download the cerrado (savanna) biome, whis is sub_region = 2.
img_eto <- download_terraclimate(dir_out = "C:/Users/betof/Desktop/teste1/eto", variable = "eto", years = c(2000:2001), region = "biomes_brazil" , sub_region = 2)
img_ppt <- download_terraclimate(dir_out = "C:/Users/betof/Desktop/teste1/ppt", variable = "ppt", years = c(2000:2001), region = "biomes_brazil" , sub_region = 2)
plot(img_eto)
plot(img_ppt)
If you want to calibrate the images for Brazilian conditions, you can use the function eto_calibration and ppt_calibration. As suggestion, you can enter with the slope and intercept values displayed in the examples of the functions. These values were obtained calibrating the Terraclimate images during 2000 to 2017 using all the automatic weather stations of National Meteorological Institute of Brazil (INMET).
img_eto_cal <- eto_calibration(slope = 0.930073, intercept = 22.399986, eto_stack = img_eto)
img_ppt_cal <- ppt_calibration(slope = 0.7000972, intercept = 23.753785, ppt_stack = img_ppt)
After the download or calibration, we need to generate the monthly mean eto and monthly mean ppt. So, this function will calculate the mean monthly air temperature based on the period of time selected (start_date and end_date).
start_date <- c('2000-01-01') # The start and end date will depend of the download period of the images
end_date <- c('2001-12-01')
monthly_eto <- cropDemand::monthly_stack(stack = img_eto_cal, start_date = start_date, end_date = end_date)
monthly_ppt <- monthly_stack(stack = img_ppt_cal, start_date = start_date, end_date = end_date)
Now, we can run the waterDemand function. This function will calculate the water balance parameters based on the available water capacity informed (AWC), which in this case is 100 (mm). The output of the water balance parameters for this function are:
1 ARM - storage;
2 ALT - alteration;
3 ETR - actual evapotranspiration;
4 DEF - deficit;
5 EXC - excess;
6 REP - replacement;
7 RET - withdrawal;
8 AWC_arm - percentage of storage compared to AWC.
- To run the function waterDemand consider to aggregate the ppt_stack and eto_stack first, since this process can take a long time (normal computer) if the area is too large.
monthly_ppt_agg <-raster::aggregate(monthly_ppt, fact = 3)
monthly_eto_agg <-raster::aggregate(monthly_eto, fact = 3)
cwd <- waterDemand(out_dir = "C:/Users/betof/Desktop/teste1/results", ppt_stack = monthly_ppt_agg, eto_stack = monthly_eto_agg, AWC = 100)
plot_AWC(AWC_stack = cwd)
More about Terraclimate can be found in 1. The methodology based to run the water balance was 2.
Hope that you enjoyed!
Abatzoglou, J.T., S.Z. Dobrowski, S.A. Parks, K.C. Hegewisch, 2018, Terraclimate, a high-resolution global dataset of monthly climate and climatic water balance from 1958-2015, Scientific Data.↩︎
Thornthwaite, C.W.; Mather, J.R. The water balance. Centerton, NJ: Drexel Institute of Technology - Laboratory of Climatology, 1955. 104p. (Publications in Climatology, vol. VIII, n.1).↩︎