varunayanR varunayanR logo

varunayan is an R package. It downloads and processes ERA5 reanalysis data from the Copernicus Climate Data Store. It also downloads and processes IMD gridded climate data from the Indian Meteorological Department. The package gives an easy R interface to get temperature, precipitation, and other climate variables for a region. You can specify the region with a bounding box, a GeoJSON polygon, or point coordinates.

Installation

# Install from GitHub
# install.packages("devtools")
devtools::install_github("saketlab/varunayanR")

Quick Start

ERA5 climate data

library(varunayan)

# Set the CDS credentials (one time only)
# Get your API key from this site: https://cds.climate.copernicus.eu/how-to-api
setup_cds_credentials(key = "your-cds-api-key")

# Download the ERA5 temperature and precipitation for Mumbai
temperature_data <- era5ify_bbox(
  request_id = "mumbai_temp",
  variables = c("2m_temperature", "total_precipitation"),
  start_date = "2023-01-01",
  end_date = "2023-12-31",
  north = 19.2, south = 18.9,
  east = 72.9, west = 72.8,
  frequency = "daily"
)

head(temperature_data)

IMD rainfall data

# Download the IMD gridded rainfall data for Maharashtra
rainfall_data <- imd_rainfall_bbox(
  request_id = "maharashtra_rain",
  start_year = 2023,
  end_year = 2024,
  north = 22, south = 16,
  east = 80, west = 73,
  resolution = 0.25,
  frequency = "monthly"
)

GeoJSON regions

# Download data for the regions in a GeoJSON file
data <- era5ify_geojson(
  request_id = "indian_states",
  variables = c("2m_temperature", "surface_pressure"),
  start_date = "2024-01-01",
  end_date = "2024-01-31",
  json_file = "path/to/states.geojson",
  frequency = "daily"
)

Use cases

Monsoon analysis

# Download 20 years of rainfall data for a monsoon study
rainfall <- imd_rainfall_bbox(
  request_id = "monsoon_study",
  start_year = 2000,
  end_year = 2020,
  north = 28, south = 8,
  east = 92, west = 68,
  resolution = 0.25,
  frequency = "monthly"
)

# Analyze the monsoon rainfall (June to September)
library(dplyr)
monsoon <- rainfall %>%
  filter(month(date) %in% 6:9) %>%
  group_by(year(date), latitude, longitude) %>%
  summarise(monsoon_total = sum(rainfall))

Atmospheric data at pressure levels

# Download ERA5 data at more than one atmospheric level
atmos_data <- era5ify_bbox(
  request_id = "atmosphere",
  variables = c("temperature", "geopotential", "u_component_of_wind"),
  start_date = "2024-01-01",
  end_date = "2024-01-05",
  north = 30, south = 20,
  east = 80, west = 70,
  dataset_type = "pressure",
  pressure_levels = c("1000", "850", "500", "200")
)

Documentation

Contributing

We accept contributions. To send a change, open a Pull Request.