| Title: | Download, Process and Visualize IMD Gridded Meteorological Data |
|---|---|
| Description: | Interface to India Meteorological Department (IMD) gridded daily rainfall (0.25 degree, 1901-present) and temperature (1.0 degree, 1951-present) binary data. Provides functions to download, read, extract by point or boundary, compute climate indices, perform trend analysis, and produce publication-quality maps with Survey of India approved boundaries. |
| Authors: | Subhradip Bhattacharjee [aut, cre], Amitava Panja [aut], Ankita Chakraborty [aut], Basavareddy [aut] |
| Maintainer: | Subhradip Bhattacharjee <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-06-23 16:33:25 UTC |
| Source: | https://github.com/cran/imdR |
Computes 11 indices per grid cell per year. Handles single-year SpatRasters and multi-year named lists from get_data().
compute_rainfall_indices( rain_raster, level = NULL, name = NULL, file_dir, save_csv = TRUE )compute_rainfall_indices( rain_raster, level = NULL, name = NULL, file_dir, save_csv = TRUE )
rain_raster |
A SpatRaster or named list from get_data("rain",...). |
level |
NULL, "state", or "district". |
name |
State or district name. |
file_dir |
Output directory for CSV. |
save_csv |
Save results as CSV? Default TRUE. |
Invisible data frame with columns year, cell, dr, d64, d115, rx1day, rx5day, rtwd, sdii, total, cwd, cdd, pci.
# Full India rainfall indices for 2020 r <- get_data("rain", 2020, 2020, tempdir()) idx <- compute_rainfall_indices(r, file_dir = tempdir()) # State level indices goa_idx <- compute_rainfall_indices(r, level = "state", name = "Goa", file_dir = tempdir()) # Multi-year indices for trend analysis r_3yr <- get_data("rain", 2018, 2020, tempdir()) idx_3yr <- compute_rainfall_indices(r_3yr, file_dir = tempdir())# Full India rainfall indices for 2020 r <- get_data("rain", 2020, 2020, tempdir()) idx <- compute_rainfall_indices(r, file_dir = tempdir()) # State level indices goa_idx <- compute_rainfall_indices(r, level = "state", name = "Goa", file_dir = tempdir()) # Multi-year indices for trend analysis r_3yr <- get_data("rain", 2018, 2020, tempdir()) idx_3yr <- compute_rainfall_indices(r_3yr, file_dir = tempdir())
Computes 13 indices per grid cell per year from daily tmax and tmin.
compute_temp_indices( tmax_raster, tmin_raster, level = NULL, name = NULL, file_dir, save_csv = TRUE )compute_temp_indices( tmax_raster, tmin_raster, level = NULL, name = NULL, file_dir, save_csv = TRUE )
tmax_raster |
A SpatRaster or named list for tmax. |
tmin_raster |
A SpatRaster or named list for tmin. |
level |
NULL, "state", or "district". |
name |
State or district name. |
file_dir |
Output directory for CSV. |
save_csv |
Save results as CSV? Default TRUE. |
Invisible data frame with columns year, cell, mean_tmax, mean_tmin, mean_dtr, txx, txn, tnx, tnn, su35, su40, tr10, tr25, wsdi, csdi.
# Full India temperature indices for 2020 tx <- get_data("tmax", 2020, 2020, tempdir()) tn <- get_data("tmin", 2020, 2020, tempdir()) idx <- compute_temp_indices(tx, tn, file_dir = tempdir()) # State level indices goa_idx <- compute_temp_indices(tx, tn, level = "state", name = "Goa", file_dir = tempdir()) # Multi-year temperature indices tx_3yr <- get_data("tmax", 2018, 2020, tempdir()) tn_3yr <- get_data("tmin", 2018, 2020, tempdir()) idx_3yr <- compute_temp_indices(tx_3yr, tn_3yr, file_dir = tempdir())# Full India temperature indices for 2020 tx <- get_data("tmax", 2020, 2020, tempdir()) tn <- get_data("tmin", 2020, 2020, tempdir()) idx <- compute_temp_indices(tx, tn, file_dir = tempdir()) # State level indices goa_idx <- compute_temp_indices(tx, tn, level = "state", name = "Goa", file_dir = tempdir()) # Multi-year temperature indices tx_3yr <- get_data("tmax", 2018, 2020, tempdir()) tn_3yr <- get_data("tmin", 2018, 2020, tempdir()) idx_3yr <- compute_temp_indices(tx_3yr, tn_3yr, file_dir = tempdir())
Crops and masks an IMD SpatRaster to any named state or district using bundled SOI-approved boundaries. Supports three output formats:
"netcdf" – CF-1.7 compliant NetCDF
"geotiff" – Multi-band GeoTIFF, opens in QGIS/ArcGIS
"csv" – Long-format table: date, lat, lon, value
extract_by_boundary( imd_raster, level = "state", name = NULL, variable = "rain", save = FALSE, format = "netcdf", file_dir )extract_by_boundary( imd_raster, level = "state", name = NULL, variable = "rain", save = FALSE, format = "netcdf", file_dir )
imd_raster |
A SpatRaster or named list from get_data(). |
level |
"state" (default) or "district". |
name |
State or district name (partial match allowed). |
variable |
Variable name for output column and filename. |
save |
Save output to disk? Default FALSE. |
format |
"netcdf" (default), "geotiff", or "csv". |
file_dir |
Output directory. |
Invisible masked SpatRaster.
r <- get_data("rain", 2020, 2020, tempdir()) # Return masked raster without saving nagaland_rain <- extract_by_boundary(r, "state", "Nagaland", "rain") # State — NetCDF extract_by_boundary(r, "state", "Nagaland", "rain", save = TRUE, format = "netcdf", file_dir = tempdir()) # State — GeoTIFF (QGIS/ArcGIS) extract_by_boundary(r, "state", "Nagaland", "rain", save = TRUE, format = "geotiff", file_dir = tempdir()) # State — CSV (all grid points x all days) extract_by_boundary(r, "state", "Nagaland", "rain", save = TRUE, format = "csv", file_dir = tempdir()) # District — all formats work the same way extract_by_boundary(r, "district", "North Goa", "rain", save = TRUE, format = "csv", file_dir = tempdir())r <- get_data("rain", 2020, 2020, tempdir()) # Return masked raster without saving nagaland_rain <- extract_by_boundary(r, "state", "Nagaland", "rain") # State — NetCDF extract_by_boundary(r, "state", "Nagaland", "rain", save = TRUE, format = "netcdf", file_dir = tempdir()) # State — GeoTIFF (QGIS/ArcGIS) extract_by_boundary(r, "state", "Nagaland", "rain", save = TRUE, format = "geotiff", file_dir = tempdir()) # State — CSV (all grid points x all days) extract_by_boundary(r, "state", "Nagaland", "rain", save = TRUE, format = "csv", file_dir = tempdir()) # District — all formats work the same way extract_by_boundary(r, "district", "North Goa", "rain", save = TRUE, format = "csv", file_dir = tempdir())
Crops IMD raster data to a user-defined latitude/longitude bounding box. Useful for custom regions such as the Indo-Gangetic Plains, Western Ghats, or any area not matching a state or district boundary. Supports three output formats: NetCDF, GeoTIFF, and long-format CSV.
get_bbox( lat_min, lat_max, lon_min, lon_max, variable, start_yr, end_yr, file_dir, format = "netcdf", save = TRUE )get_bbox( lat_min, lat_max, lon_min, lon_max, variable, start_yr, end_yr, file_dir, format = "netcdf", save = TRUE )
lat_min |
Numeric. Minimum latitude. |
lat_max |
Numeric. Maximum latitude. |
lon_min |
Numeric. Minimum longitude. |
lon_max |
Numeric. Maximum longitude. |
variable |
One of "rain", "tmax", "tmin". |
start_yr |
Integer. Start year. |
end_yr |
Integer. End year. |
file_dir |
Character. Directory for files. |
format |
"netcdf" (default), "geotiff", or "csv". |
save |
Logical. Save output? Default TRUE. |
Invisible SpatRaster of the cropped region.
# Indo-Gangetic Plains -- NetCDF get_bbox(lat_min = 24, lat_max = 30, lon_min = 73, lon_max = 88, variable = "rain", start_yr = 2020, end_yr = 2020, file_dir = tempdir(), format = "netcdf") # Western Ghats -- GeoTIFF get_bbox(lat_min = 8, lat_max = 21, lon_min = 73, lon_max = 78, variable = "rain", start_yr = 2020, end_yr = 2020, file_dir = tempdir(), format = "geotiff") # Northeast India -- CSV (all grid points x all days) get_bbox(lat_min = 22, lat_max = 29, lon_min = 89, lon_max = 97, variable = "rain", start_yr = 2020, end_yr = 2020, file_dir = tempdir(), format = "csv")# Indo-Gangetic Plains -- NetCDF get_bbox(lat_min = 24, lat_max = 30, lon_min = 73, lon_max = 88, variable = "rain", start_yr = 2020, end_yr = 2020, file_dir = tempdir(), format = "netcdf") # Western Ghats -- GeoTIFF get_bbox(lat_min = 8, lat_max = 21, lon_min = 73, lon_max = 78, variable = "rain", start_yr = 2020, end_yr = 2020, file_dir = tempdir(), format = "geotiff") # Northeast India -- CSV (all grid points x all days) get_bbox(lat_min = 22, lat_max = 29, lon_min = 89, lon_max = 97, variable = "rain", start_yr = 2020, end_yr = 2020, file_dir = tempdir(), format = "csv")
Get the sf boundary for a named state or district
get_boundary(level = "state", name)get_boundary(level = "state", name)
level |
"state" (default) or "district". |
name |
State or district name (partial match allowed). |
An sf object with the matching boundary.
goa <- get_boundary("state", "Goa") north_goa <- get_boundary("district", "North Goa")goa <- get_boundary("state", "Goa") north_goa <- get_boundary("district", "North Goa")
Downloads binary .grd files from IMD Pune and converts them to terra SpatRaster objects. Single year returns a SpatRaster directly. Multi-year returns a named list of SpatRasters (one per year) because leap and non-leap years have different layer counts.
get_data(variable, start_yr, end_yr, file_dir, overwrite = FALSE)get_data(variable, start_yr, end_yr, file_dir, overwrite = FALSE)
variable |
One of "rain", "tmax", "tmin". |
start_yr |
Start year (rain: 1901+, temp: 1951+). |
end_yr |
End year. |
file_dir |
Directory to save downloaded .grd files. |
overwrite |
Re-download even if file exists? Default FALSE. |
A SpatRaster (single year) or named list of SpatRasters (multi-year).
# Download single year rainfall rain2020 <- get_data("rain", 2020, 2020, tempdir()) # Download multiple years (returns named list) rain_3yr <- get_data("rain", 2018, 2020, tempdir()) # Download temperature data tmax2020 <- get_data("tmax", 2020, 2020, tempdir()) tmin2020 <- get_data("tmin", 2020, 2020, tempdir())# Download single year rainfall rain2020 <- get_data("rain", 2020, 2020, tempdir()) # Download multiple years (returns named list) rain_3yr <- get_data("rain", 2018, 2020, tempdir()) # Download temperature data tmax2020 <- get_data("tmax", 2020, 2020, tempdir()) tmin2020 <- get_data("tmin", 2020, 2020, tempdir())
Extract daily time series for a single variable at a point
get_point(lat, lon, variable, start_yr, end_yr, file_dir, save_csv = TRUE)get_point(lat, lon, variable, start_yr, end_yr, file_dir, save_csv = TRUE)
lat |
Latitude in decimal degrees. |
lon |
Longitude in decimal degrees. |
variable |
One of "rain", "tmax", "tmin". |
start_yr |
Start year. |
end_yr |
End year. |
file_dir |
Directory for .grd files. |
save_csv |
Save output as CSV? Default TRUE. |
Invisible data frame with columns date, lat, lon, variable.
# Extract daily rainfall at Panaji, Goa df <- get_point(lat = 15.5, lon = 73.8, variable = "rain", start_yr = 2020, end_yr = 2020, file_dir = tempdir()) head(df) # Extract temperature df_tmax <- get_point(lat = 15.5, lon = 73.8, variable = "tmax", start_yr = 2020, end_yr = 2020, file_dir = tempdir())# Extract daily rainfall at Panaji, Goa df <- get_point(lat = 15.5, lon = 73.8, variable = "rain", start_yr = 2020, end_yr = 2020, file_dir = tempdir()) head(df) # Extract temperature df_tmax <- get_point(lat = 15.5, lon = 73.8, variable = "tmax", start_yr = 2020, end_yr = 2020, file_dir = tempdir())
Downloads or reads rain, tmax, and tmin at a location and merges them into a single data frame that also includes diurnal temperature range (DTR). Extraction is done year by year to avoid memory issues with long time series on Windows.
get_point_all(lat, lon, start_yr, end_yr, file_dir, save_csv = TRUE)get_point_all(lat, lon, start_yr, end_yr, file_dir, save_csv = TRUE)
lat |
Latitude in decimal degrees. |
lon |
Longitude in decimal degrees. |
start_yr |
Start year. |
end_yr |
End year. |
file_dir |
Directory for .grd files. |
save_csv |
Save merged output as CSV? Default TRUE. |
Invisible data frame with columns date, lat, lon, rain, tmax, tmin, dtr.
# Extract rain, tmax, tmin and DTR at Panaji, Goa df <- get_point_all(lat = 15.5, lon = 73.8, start_yr = 2020, end_yr = 2020, file_dir = tempdir()) head(df) # Long time series -- works on Windows without memory errors df <- get_point_all(lat = 15.5, lon = 73.8, start_yr = 1985, end_yr = 2020, file_dir = tempdir()) nrow(df)# Extract rain, tmax, tmin and DTR at Panaji, Goa df <- get_point_all(lat = 15.5, lon = 73.8, start_yr = 2020, end_yr = 2020, file_dir = tempdir()) head(df) # Long time series -- works on Windows without memory errors df <- get_point_all(lat = 15.5, lon = 73.8, start_yr = 1985, end_yr = 2020, file_dir = tempdir()) nrow(df)
An sf object with boundaries for 808 Indian districts, sourced from Survey of India (SOI) shapefiles, reprojected to WGS84.
india_districtsindia_districts
An sf data frame with 808 rows and columns state_name, district_name, and geometry.
An sf object with boundaries for all 36 Indian states and union territories, sourced from Survey of India (SOI) shapefiles, reprojected to WGS84.
india_statesindia_states
An sf data frame with 36 rows and columns state_name and geometry.
List district names, optionally filtered by state
list_districts(state = NULL)list_districts(state = NULL)
state |
Character or NULL. Partial match, case-insensitive. |
A sorted character vector of district names.
list_districts() list_districts("Goa")list_districts() list_districts("Goa")
List all state names in the bundled SOI shapefile
list_states()list_states()
A sorted character vector of 36 state/UT names.
list_states()list_states()
Read cached IMD .grd files from disk
open_data(variable, start_yr, end_yr, file_dir)open_data(variable, start_yr, end_yr, file_dir)
variable |
One of "rain", "tmax", "tmin". |
start_yr |
Start year. |
end_yr |
End year. |
file_dir |
Directory containing the variable sub-folder. |
A SpatRaster (single year) or named list (multi-year).
rain2020 <- open_data("rain", 2020, 2020, tempdir()) rain_3yr <- open_data("rain", 2018, 2020, tempdir())rain2020 <- open_data("rain", 2020, 2020, tempdir()) rain_3yr <- open_data("rain", 2018, 2020, tempdir())
Publication-quality map with SOI boundaries. Supports full-India, state-level, and district-level zoom.
plot_imd( imd_raster, date, variable = "rain", level = NULL, name = NULL, title = NULL, save_path = NULL, width = 7, height = 8 )plot_imd( imd_raster, date, variable = "rain", level = NULL, name = NULL, title = NULL, save_path = NULL, width = 7, height = 8 )
imd_raster |
A SpatRaster or named list from get_data(). |
date |
Date to plot (must match a layer name). |
variable |
One of "rain", "tmax", "tmin". |
level |
NULL, "state", or "district" for zoom. |
name |
State or district name for zoom. |
title |
Custom title. Auto-generated if NULL. |
save_path |
File path to save PNG/PDF. NULL = no save. |
width |
Plot width in inches. Default 7. |
height |
Plot height in inches. Default 8. |
Invisible ggplot2 object.
r <- get_data("rain", 2020, 2020, tempdir()) # Full India map plot_imd(r, "2020-06-28", "rain") # Zoom to Kerala plot_imd(r, "2020-06-28", "rain", level = "state", name = "Kerala") # Zoom to North Goa district plot_imd(r, "2020-06-28", "rain", level = "district", name = "North Goa") # Save to file plot_imd(r, "2020-06-28", "rain", save_path = file.path(tempdir(), "rain_20200628.png"))r <- get_data("rain", 2020, 2020, tempdir()) # Full India map plot_imd(r, "2020-06-28", "rain") # Zoom to Kerala plot_imd(r, "2020-06-28", "rain", level = "state", name = "Kerala") # Zoom to North Goa district plot_imd(r, "2020-06-28", "rain", level = "district", name = "North Goa") # Save to file plot_imd(r, "2020-06-28", "rain", save_path = file.path(tempdir(), "rain_20200628.png"))
Plot a daily time series with 30-day rolling mean
plot_timeseries( df, variable = "rain", title = NULL, save_path = NULL, width = 10, height = 5 )plot_timeseries( df, variable = "rain", title = NULL, save_path = NULL, width = 10, height = 5 )
df |
Data frame with columns date and the variable. |
variable |
Column name to plot. |
title |
Plot title. Auto-generated if NULL. |
save_path |
File path to save PNG. NULL = no save. |
width |
Width in inches. Default 10. |
height |
Height in inches. Default 5. |
Invisible ggplot2 object.
# Extract point data and plot df <- get_point(lat = 15.5, lon = 73.8, variable = "rain", start_yr = 2020, end_yr = 2020, file_dir = tempdir(), save_csv = FALSE) plot_timeseries(df, variable = "rain") # Plot temperature with custom title df_tmax <- get_point(lat = 15.5, lon = 73.8, variable = "tmax", start_yr = 2020, end_yr = 2020, file_dir = tempdir(), save_csv = FALSE) plot_timeseries(df_tmax, variable = "tmax", title = "Goa Maximum Temperature 2020")# Extract point data and plot df <- get_point(lat = 15.5, lon = 73.8, variable = "rain", start_yr = 2020, end_yr = 2020, file_dir = tempdir(), save_csv = FALSE) plot_timeseries(df, variable = "rain") # Plot temperature with custom title df_tmax <- get_point(lat = 15.5, lon = 73.8, variable = "tmax", start_yr = 2020, end_yr = 2020, file_dir = tempdir(), save_csv = FALSE) plot_timeseries(df_tmax, variable = "tmax", title = "Goa Maximum Temperature 2020")
Extracts daily values from an IMD SpatRaster at the nearest grid cell to the specified latitude/longitude and returns a data frame.
to_csv(imd_raster, lat, lon, file_path = NULL)to_csv(imd_raster, lat, lon, file_path = NULL)
imd_raster |
A terra SpatRaster from get_data(). |
lat |
Latitude in decimal degrees (WGS84). |
lon |
Longitude in decimal degrees (WGS84). |
file_path |
Character or NULL. If provided, saves output as CSV. |
An invisible data frame with columns date and value.
r <- get_data("rain", 2020, 2020, tempdir()) df <- to_csv(r, lat = 15.5, lon = 73.8) head(df) # Save directly to file to_csv(r, lat = 15.5, lon = 73.8, file_path = file.path(tempdir(), "panaji_rain_2020.csv"))r <- get_data("rain", 2020, 2020, tempdir()) df <- to_csv(r, lat = 15.5, lon = 73.8) head(df) # Save directly to file to_csv(r, lat = 15.5, lon = 73.8, file_path = file.path(tempdir(), "panaji_rain_2020.csv"))
Writes a multi-layer terra SpatRaster to a DEFLATE-compressed, tiled GeoTIFF suitable for use in QGIS, ArcGIS, Python (rasterio), and other spatial software.
to_geotiff(imd_raster, file_path)to_geotiff(imd_raster, file_path)
imd_raster |
A terra SpatRaster. |
file_path |
Character. Output .tif file path. |
Invisible character: the file path written.
r <- get_data("rain", 2020, 2020, tempdir()) to_geotiff(r, file.path(tempdir(), "rain_2020.tif")) # Save a boundary-extracted region goa <- extract_by_boundary(r, "state", "Goa", "rain") to_geotiff(goa, file.path(tempdir(), "rain_Goa_2020.tif"))r <- get_data("rain", 2020, 2020, tempdir()) to_geotiff(r, file.path(tempdir(), "rain_2020.tif")) # Save a boundary-extracted region goa <- extract_by_boundary(r, "state", "Goa", "rain") to_geotiff(goa, file.path(tempdir(), "rain_Goa_2020.tif"))
Writes a multi-layer terra SpatRaster to a CF-1.7 compliant NetCDF file with correct time, latitude, and longitude dimensions and standard metadata attributes.
to_netcdf(imd_raster, file_path, variable = "rain")to_netcdf(imd_raster, file_path, variable = "rain")
imd_raster |
A terra SpatRaster. |
file_path |
Character. Output .nc file path. |
variable |
One of "rain", "tmax", "tmin". |
Invisible character: the file path written.
r <- get_data("rain", 2020, 2020, tempdir()) to_netcdf(r, file.path(tempdir(), "rain_2020.nc"), "rain") # Save a boundary-extracted region goa <- extract_by_boundary(r, "state", "Goa", "rain") to_netcdf(goa, file.path(tempdir(), "rain_Goa_2020.nc"), "rain")r <- get_data("rain", 2020, 2020, tempdir()) to_netcdf(r, file.path(tempdir(), "rain_2020.nc"), "rain") # Save a boundary-extracted region goa <- extract_by_boundary(r, "state", "Goa", "rain") to_netcdf(goa, file.path(tempdir(), "rain_Goa_2020.nc"), "rain")
Aggregates multi-cell index data to spatial means per year, then performs Mann-Kendall test and Sen's slope estimation.
trend_analysis( index_df, index_col, level = NULL, name = NULL, file_dir, save_csv = TRUE, plot = TRUE )trend_analysis( index_df, index_col, level = NULL, name = NULL, file_dir, save_csv = TRUE, plot = TRUE )
index_df |
Data frame from compute_rainfall_indices() or compute_temp_indices(). |
index_col |
Column name to analyse (e.g. "total", "dr"). |
level |
Not used in computation; passed to filename. |
name |
Region name for output filename. |
file_dir |
Output directory. |
save_csv |
Save results table as CSV? Default TRUE. |
plot |
Produce and save a trend plot? Default TRUE. |
Invisible data frame with tau, S, pvalue, significance, sens_slope, trend_direction, total_change.
# Download 10 years of rainfall r <- get_data("rain", 2011, 2020, tempdir()) idx <- compute_rainfall_indices(r, file_dir = tempdir()) # Trend in annual total rainfall trend_analysis(idx, index_col = "total", file_dir = tempdir()) # Trend in rainy days trend_analysis(idx, index_col = "dr", file_dir = tempdir()) # Region-specific trend goa_idx <- compute_rainfall_indices(r, level = "state", name = "Goa", file_dir = tempdir()) trend_analysis(goa_idx, index_col = "total", name = "Goa", file_dir = tempdir()) # Temperature trend tx <- get_data("tmax", 2011, 2020, tempdir()) tn <- get_data("tmin", 2011, 2020, tempdir()) tidx <- compute_temp_indices(tx, tn, file_dir = tempdir()) trend_analysis(tidx, index_col = "mean_tmax", file_dir = tempdir())# Download 10 years of rainfall r <- get_data("rain", 2011, 2020, tempdir()) idx <- compute_rainfall_indices(r, file_dir = tempdir()) # Trend in annual total rainfall trend_analysis(idx, index_col = "total", file_dir = tempdir()) # Trend in rainy days trend_analysis(idx, index_col = "dr", file_dir = tempdir()) # Region-specific trend goa_idx <- compute_rainfall_indices(r, level = "state", name = "Goa", file_dir = tempdir()) trend_analysis(goa_idx, index_col = "total", name = "Goa", file_dir = tempdir()) # Temperature trend tx <- get_data("tmax", 2011, 2020, tempdir()) tn <- get_data("tmin", 2011, 2020, tempdir()) tidx <- compute_temp_indices(tx, tn, file_dir = tempdir()) trend_analysis(tidx, index_col = "mean_tmax", file_dir = tempdir())