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.
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
Character string with the reanalysis to use. One of
"era5_land"(default; 0.1 degree, ~9 km, land only),"era5"(0.25 degree, ~25 km),"era5_seamless"(ERA5-Land combined with ERA5) or"best_match"(Open-Meteo chooses; the source may change over time, which is not recommended for long series or bias correction). Use a single fixed model when series will be compared across years or calibrated against a reference.- 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, elevation, model, and study.
elevation is the elevation (m) Open-Meteo used for the statistical
elevation correction of temperature (90 m DEM by default).
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(),
plot_model_results(),
windowpane()
