Downloading rainfall data with nasapower

The nasapower package aims at making it quick and easy to automate downloading NASA POWER (NASA Prediction of Worldwide Energy Resource) global meteorology, surface solar energy and climatology data.

Installing nasapower package

We can install the package from either CRAN using

install.packages("nasapower")

or by using the devtools package directly from GitHub using the following code:

if (!require(devtools)) {
  install.packages("devtools")
}
devtools::install_github("ropensci/nasapower")
library(nasapower)

Using get_power() to fetch data

The get_power() function has five arguments and returns a data frame with a metadata header in the current R session. It has the following arguments:

  • pars: character vector of solar, meteorological or climatology parameters to download.

  • community: character vector providing community name. Supported values are "AG", "SB" or "SSE".

"AG": provides access to the agroclimatology archive, which contains industry-friendly parameters for input to crop models.

"SB": provides access to the sustainable buildings archive, which contains parameters for the building community.

"SSE": provides access to the renewable energy archive, which contains parameters very specific to assist in the design of solar and wind powered renewable energy systems.

  • temporal_average: temporal average for data being queried. Supported values are "DAILY", "INTERANNUAL" or "CLIMATOLOGY".

"DAILY": daily average of pars by day, month and year.

"INTERANNUAL": monthly average of pars by year.

"CLIMATOLOGY": monthly average of pars at the surface of the earth for a given month averaged for that month over the 30 year period.

  • lonlat: numeric vector of geographic coordinates for a cell or region or "GLOBAL" for global coverage.

For single point supply a length-two numeric vector giving the decimal degree longitude an dlatitude in that order for the data to download.

For regional coverage supply a length-four numeric as lower left (lon, lat) and upper right (lon, lat) coordinates as lonlat = c(xmin, ymin, ymax, ymax)

To get global coverage for CLIMATOLOGY, supply GLOBAL while also specifying CLIMATOLOGY for the argument temporal_average.

  • dates: start and end dates. If only one date is provided, it will be treated as both the start and the end date and only a day’s values will be returned. When the temporal_average is set to INTERANNUAL, use only two year values, e.g., dates = c(1983, 2010). This argument should not be used when temporal_average is set to "CLIMATOLOGY".

To know the different weather values from POWER provided within this function type ?get_power, and in the arguments section, click on the highlighted parameters, which goes to a page which has all the available parameters.

To download rainfall, we use the pars = "PRECTOT".

Fetching daily data for single point

data <- get_power(community = "SSE",
          lonlat = c(134.489563,-25.734968),
          dates = c("2000-01-01","2000-05-01"),
          temporal_average = "DAILY",
          pars = "PRECTOT")

data %>% datatable(extensions = c('Scroller','FixedColumns'), options = list(
  deferRender = TRUE,
  scrollY = 350,
  scrollX = 350,
  dom = 't',
  scroller = TRUE,
  fixedColumns = list(leftColumns = 3)
))

Fetching daily data for an area

daily_area <- get_power(community = "AG",
          lonlat = c(150.5, -28.5 , 153.5, -25.5),
          pars = "PRECTOT",
          dates = c("2004-09-19","2004-09-29"),
          temporal_average = "DAILY")

daily_area %>% datatable(extensions = c('Scroller','FixedColumns'), options = list(
  deferRender = TRUE,
  scrollY = 350,
  scrollX = 350,
  dom = 't',
  scroller = TRUE,
  fixedColumns = list(leftColumns = 3)
))

Fetching climatology data

Global data are only available for the climatology temporal_average like we discussed earlier, setting these arguments as such will fetch the global values.

climate_avg <- get_power(community = "AG",
                         pars = "PRECTOT",
                         lonlat = "GLOBAL",
                         temporal_average = "CLIMATOLOGY"
)

climate_avg %>% datatable(extensions = c('Scroller','FixedColumns'), options = list(
  deferRender = TRUE,
  scrollY = 350,
  scrollX = 350,
  dom = 't',
  scroller = TRUE,
  fixedColumns = list(leftColumns = 3)
))