Skip to content

Instantly share code, notes, and snippets.

@adamhsparks
Last active March 14, 2024 06:01
Show Gist options
  • Save adamhsparks/eac5983250226b10991590288a8a28ee to your computer and use it in GitHub Desktop.
Save adamhsparks/eac5983250226b10991590288a8a28ee to your computer and use it in GitHub Desktop.
Use a data frame of lonlat and date values to get data from POWER API using {nasapower}
library("nasapower")
library("purrr")
library("dplyr")
df <- data.frame(
stringsAsFactors = FALSE,
lon = c(151.81, 112.5, 115.5),
lat = c(-27.48, -55.5, -50.5),
date = c("3/3/2023", "5/12/2023", "1/3/2024")
)
xy_list <-
as.list(as.data.frame(t(df[, 1:2]),
stringsAsFactors = FALSE,
row.names = NA))
bind_rows(
map2(
.x = xy_list,
.y = df$date,
.f = get_power,
community = "ag",
pars = "RH2M",
temporal_api = "daily",
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment