For the work, we have to load the following libraries:
packages <- c("terra", "ggplot2", "rgdal", "raster", "ncdf4")
The daily rainfall for previous years can be downloaded as netcdf from https://www.imdpune.gov.in/Clim_Pred_LRF_New/Grided_Data_Download.html. We use the Gridded Rainfall (0.25 x 0.25) NetCDF File. Since the ML is for monsoon months (may to october) we consider the rainfall trends of only these months.
#read the netCDF file for each year
nc_data <- nc_open('~/rainfall/historical/rainfall/2021.nc')
nf <- terra::rast('~/rainfall/historical/rainfall/2021.nc')
#plot(nf)
#rain data from may to october
#days : non-leap (jan - april) 31 + 28 + 31 + 30
# days : non-leap (may to october) (31 + 28 + 31 + 30 = 120): (120 + 31+30 +31+31+30+31 = 304)
# days : leap (may to october) 121: 305
monsooon <- nf[[121:305]]
#crop to assam state boundary and project to study boundary
#mean daily rainfall to get annual rainfall
#we take mean daily rainfall of rains in monsson as floods happen during monsoon
nf_sum <- mean(monsooon, na.rm = T)
plot(nf_sum, main = "Rainfall")