This function downloads ERA5 historical weather data from the Open-Meteo API
for specified locations and dates. It mimics the functionality of get_nasapower
by fetching weather variables and returning a daily-aggregated data frame.
It uses the Open-Meteo Archive API and aggregates hourly data to daily values
to ensure all variables (including relative humidity and dew point) are available.
Usage
get_era5(
data,
days_around,
date_col,
study_col = "study",
pars = c("temperature_2m", "relative_humidity_2m", "precipitation", "dewpoint_2m"),
models = NULL,
direction = "both"
)Arguments
- data
A data frame containing the input data, including columns for
latitude,longitude, and the date column specified bydate_col.- days_around
An integer specifying the number of days before and after the date in the date column to download data.
- date_col
A character string specifying the name of the date column in the data frame.
- study_col
A character string specifying the name of the column containing the study identifier in the input data frame (default: "study").
- pars
A character vector specifying the weather variables to fetch from Open-Meteo. These are mapped to
nasapowerequivalents: "temperature_2m" (T2M), "relative_humidity_2m" (RH2M), "precipitation" (PRECTOTCORR), etc.- models
A character string specifying the reanalysis model(s) to use. If
NULL(default), Open-Meteo uses its "best_match" logic (ERA5, ERA5-Land, etc.).- direction
Character string specifying the direction of the date range relative to the reference date. Options are "both" (default), "back", or "forth". "back" retrieves data from
date - days_aroundtodate. "forth" retrieves data fromdatetodate + days_around. "both" retrieves data fromdate - days_aroundtodate + days_around.
Value
A data frame (tibble) with daily weather data. Columns are named to match
nasapower conventions: date, T2M, T2M_MAX, T2M_MIN, RH2M, PRECTOTCORR,
T2MDEW, longitude, latitude, and study.
Details
Since the Open-Meteo Archive API daily endpoint does not provide all variables
(like mean relative humidity) directly, this function fetches hourly data and
performs the daily aggregation manually:
T2M: Mean of hourlytemperature_2mT2M_MAX: Max of hourlytemperature_2mT2M_MIN: Min of hourlytemperature_2mRH2M: Mean of hourlyrelative_humidity_2mPRECTOTCORR: Sum of hourlyprecipitationT2MDEW: Mean of hourlydewpoint_2m
See also
Other Disease modeling:
get_brdwgd(),
get_nasapower(),
windowpane()
