| Title: | Climate Data of Mexico from the NASA POWER API |
|---|---|
| Description: | Climate data of Mexico from the NASA POWER API (daily, monthly or climatological temperature, precipitation, humidity, wind and radiation) for the 2,465 municipalities of Mexico or any set of points. One request per point with all the period, up to five at a time, with retries; the download can be stopped and resumed, and the result has one row per point and date. |
| Authors: | Felipe Antonio Dzul Manzanilla [aut, cre] (ORCID: <https://orcid.org/0000-0002-2085-9141>), Fabián Correa-Morales [aut] (ORCID: <https://orcid.org/0000-0002-6193-1242>), Emmanuel Morales García [aut] (ORCID: <https://orcid.org/0000-0002-6837-9227>), Cecilia Cruz López [aut] (ORCID: <https://orcid.org/0000-0002-9156-5669>), Héctor Gómez-Dantés [aut] (ORCID: <https://orcid.org/0000-0002-2025-3641>) |
| Maintainer: | Felipe Antonio Dzul Manzanilla <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-11-23 04:37:10 UTC |
| Source: | https://github.com/fdzul/climex |
URL of one NASA POWER request for a point
build_url( latitude, longitude, parameters, temporal_resolution = "daily", community = "RE", start = NULL, end = NULL )build_url( latitude, longitude, parameters, temporal_resolution = "daily", community = "RE", start = NULL, end = NULL )
latitude, longitude
|
Coordinates of the point (decimal degrees, WGS84). |
parameters |
NASA POWER parameters, e.g. |
temporal_resolution |
|
community |
|
start, end
|
Dates as |
A character string with the URL.
build_url(20.97, -89.62, c("T2M", "PRECTOTCORR"), "daily", "AG", "20240101", "20241231")build_url(20.97, -89.62, c("T2M", "PRECTOTCORR"), "daily", "AG", "20240101", "20241231")
Uses the representative point of each polygon (sf::st_point_on_surface()),
which is always inside it; the centroid of a curved municipality can fall
outside.
centroids(x, id_col)centroids(x, id_col)
x |
An |
id_col |
Column with the identifier of each polygon (e.g. |
A data frame with id_col, latitude and longitude (WGS84),
ready for download_nasa_power_data().
One request per point with all the period, up to five at a time. Each
point is saved as <identifier>.csv in output_folder; a point whose CSV
already has all the period (with data in every row) is not downloaded
again, so an interrupted download can be run again and continues where it
stopped, and with a later end_date (an update) the point is downloaded
again. Busy answers of the API (429, 5xx) and network errors are retried;
the points that still fail get a second round at the end.
download_nasa_power_data( df, lat_col = "latitude", lon_col = "longitude", start_date = "20150101", end_date = "20150305", parameters = c("T2M", "T2M_MAX", "T2M_MIN"), temporal_resolution = "daily", community = "RE", processes = 5, output_folder = "./nasa_power_data", start_col = NULL, end_col = NULL, id_col = NULL, return_consolidated = TRUE, overwrite = FALSE, verbose = TRUE )download_nasa_power_data( df, lat_col = "latitude", lon_col = "longitude", start_date = "20150101", end_date = "20150305", parameters = c("T2M", "T2M_MAX", "T2M_MIN"), temporal_resolution = "daily", community = "RE", processes = 5, output_folder = "./nasa_power_data", start_col = NULL, end_col = NULL, id_col = NULL, return_consolidated = TRUE, overwrite = FALSE, verbose = TRUE )
df |
Data frame with one row per point, e.g. |
lat_col, lon_col
|
Columns with the coordinates (decimal degrees, WGS84). |
start_date, end_date
|
Period as |
parameters |
NASA POWER parameters. Temperature: |
temporal_resolution |
|
community |
|
processes |
Simultaneous requests (NASA asks for at most 5). |
output_folder |
Folder for the CSV of each point. |
start_col, end_col
|
Optional columns with a different period for each point. |
id_col |
Optional column with the identifier of each point (else
|
return_consolidated |
If |
overwrite |
Download again every point, even if its CSV already has the period. |
verbose |
Show the progress and the final report. |
A data frame with identifier, latitude, longitude, the date
(date; year and month; or period) and one column per parameter,
only for the period requested and with one row per point and date,
sorted by point and date. Missing values (-999 in NASA POWER) are NA.
## Not run: yuc <- municipalities("31") clima <- download_nasa_power_data(yuc, id_col = "CVEGEO", parameters = c("T2M", "PRECTOTCORR"), start_date = "20240101", end_date = "20241231", community = "AG") ## End(Not run)## Not run: yuc <- municipalities("31") clima <- download_nasa_power_data(yuc, id_col = "CVEGEO", parameters = c("T2M", "PRECTOTCORR"), start_date = "20240101", end_date = "20241231", community = "AG") ## End(Not run)
The table comes with the package (2,465 municipalities), so no download is
needed; it is ready for download_nasa_power_data() with
id_col = "CVEGEO".
municipalities(cve_edo = NULL, point = c("inside", "centroid"))municipalities(cve_edo = NULL, point = c("inside", "centroid"))
cve_edo |
State code(s) ( |
point |
|
A data frame with CVEGEO, CVE_ENT, state, CVE_MUN,
municipality, latitude, longitude (WGS84), centroid_lat,
centroid_lon, centroid_inside and area_km2.
yuc <- municipalities("31") # the 106 municipalities of Yucatán head(yuc[, c("CVEGEO", "municipality", "latitude", "longitude")]) nrow(municipalities()) # all the countryyuc <- municipalities("31") # the 106 municipalities of Yucatán head(yuc[, c("CVEGEO", "municipality", "latitude", "longitude")]) nrow(municipalities()) # all the country
Table from the JSON answer of NASA POWER
parse_response(js, temporal_resolution = "daily")parse_response(js, temporal_resolution = "daily")
js |
The JSON answer, as text or as the list of |
temporal_resolution |
|
A data frame with one row per day (date), year and month
(year, month; the annual value 13 is dropped) or period (period),
and one column per parameter. Missing values (-999) are NA.