nasapower

Adam H Sparks

Introduction

nasapower aims to make it quick and easy to automate downloading NASA POWER global meteorology, surface solar energy amd climatology data data in your R session as a tidy data frame for analysis and use in modelling or other purposes using get_power(). POWER (Prediction Of Worldwide Energy Resource) data are freely available for download through a web interface at a resolution of 1/2 arc degree longitude by 1/2 arc degree latitude. Two other functions are provided to quickly and easily generate weather.met files from the POWER data for use in the Agricultural Production Systems sIMulator (APSIM), create_met() and International Consortium for Agricultural Systems Applications (ICASA) format text files for use in the Decision Support System for Agrotechnology Transfer (DSSAT) framework, create_met().

Using get_power to Fetch POWER Data

The get_power() function has five arguments as seen in this example and returns a data frame with a metadata header in the current R session.

Example fetching daily data for a single point

Fetch daily “AG” community temperature, relative humidity and precipitation for January 1985 for Kingsthorpe, Queensland, Australia.

library(nasapower)
daily_single_ag <- get_power(community = "AG",
                             lonlat = c(151.81, -27.48),
                             pars = c("RH2M", "T2M", "PRECTOT"),
                             dates = c("1985-01-01", "1985-01-31"),
                             temporal_average = "DAILY"
                            )

daily_single_ag
#> NASA/POWER SRB/FLASHFlux/MERRA2/GEOS 5.12.4 (FP-IT) 0.5 x 0.5 Degree Daily Averaged Data  
#>  Dates (month/day/year): 01/01/1985 through 01/31/1985  
#>  Location: Latitude  -27.48   Longitude 151.81  
#>  Elevation from MERRA-2: Average for 1/2x1/2 degree lat/lon region = 434.55 meters   Site = na  
#>  Climate zone: na (reference Briggs et al: http://www.energycodes.gov)  
#>  Value for missing model data cannot be computed or out of model availability range: -99  
#>  
#>  Parameters: 
#>  PRECTOT MERRA2 1/2x1/2 Precipitation (mm day-1) ;
#>  RH2M MERRA2 1/2x1/2 Relative Humidity at 2 Meters (%) ;
#>  T2M MERRA2 1/2x1/2 Temperature at 2 Meters (C)  
#>  
#> # A tibble: 31 x 10
#>      LON   LAT  YEAR    MM    DD   DOY YYYYMMDD    RH2M   T2M PRECTOT
#>    <dbl> <dbl> <dbl> <int> <int> <int> <date>     <dbl> <dbl>   <dbl>
#>  1  152. -27.5  1985     1     1     1 1985-01-01  48.9  25.1    1.07
#>  2  152. -27.5  1985     1     2     2 1985-01-02  41.8  28.4    0.5 
#>  3  152. -27.5  1985     1     3     3 1985-01-03  40.4  27.5    0.03
#>  4  152. -27.5  1985     1     4     4 1985-01-04  46.4  24.6    0.1 
#>  5  152. -27.5  1985     1     5     5 1985-01-05  50.8  26.5    2.13
#>  6  152. -27.5  1985     1     6     6 1985-01-06  58.6  26.8    5.32
#>  7  152. -27.5  1985     1     7     7 1985-01-07  61.1  27.0   11.9 
#>  8  152. -27.5  1985     1     8     8 1985-01-08  66.5  25.1    8.69
#>  9  152. -27.5  1985     1     9     9 1985-01-09  55.8  26.1    2.45
#> 10  152. -27.5  1985     1    10    10 1985-01-10  41.2  27.0    0.36
#> # … with 21 more rows

Example fetching daily data for an area

Fetch daily “AG” community relative humidity and temperature for south east Queensland region.

Example fetching interannual data for an area

Fetch interannual solar cooking parameters for south east Queensland region.

interannual_sse <- get_power(community = "SSE",
                             lonlat = c(150.5, -28.5 , 153.5, -25.5),
                             dates = c("1984", "1985"),
                             temporal_average = "INTERANNUAL",
                             pars = c("CLRSKY_SFC_SW_DWN",
                                      "ALLSKY_SFC_SW_DWN")
                            )

interannual_sse
#> NASA/POWER SRB/FLASHFlux/MERRA2/GEOS 5.12.4 (FP-IT) 0.5 x 0.5 Degree Interannual Averages/Sums  
#>  Dates (month/day/year): 01/01/1984 through 12/31/1985  
#>  Location: Regional  
#>  Elevation from MERRA-2: Average for 1/2x1/2 degree lat/lon region = na meters   Site = na  
#>  Climate zone: na (reference Briggs et al: http://www.energycodes.gov)  
#>  Value for missing model data cannot be computed or out of model availability range: NA  
#>  
#>  Parameters: 
#>  ALLSKY_SFC_SW_DWN SRB/FLASHFlux 1/2x1/2 All Sky Insolation Incident on a Horizontal Surface (kW-hr/m^2/day) ;
#>  CLRSKY_SFC_SW_DWN SRB/FLASHFlux 1/2x1/2 Clear Sky Insolation Incident on a Horizontal Surface (kW-hr/m^2/day)  
#>  
#> # A tibble: 196 x 17
#>      LON   LAT PARAMETER  YEAR   JAN   FEB   MAR   APR   MAY   JUN   JUL
#>    <dbl> <dbl> <chr>     <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#>  1  151. -28.2 CLRSKY_S…  1984  8.5   7.96  6.92  5.54  4.49  3.89  4.14
#>  2  151. -28.2 CLRSKY_S…  1985  8.87  8.1   6.94  5.6   4.44  4.03  4.2 
#>  3  151. -28.2 ALLSKY_S…  1984  6.11  6.83  6.28  4.6   4.02  3.46  2.58
#>  4  151. -28.2 ALLSKY_S…  1985  8.2   7.15  6.02  4.79  3.89  3.44  3.8 
#>  5  151. -28.2 CLRSKY_S…  1984  8.45  8.09  6.77  5.5   4.41  3.95  4.15
#>  6  151. -28.2 CLRSKY_S…  1985  8.76  8.03  6.93  5.57  4.39  3.93  4.2 
#>  7  151. -28.2 ALLSKY_S…  1984  5.82  6.43  5.95  4.41  3.89  3.54  2.43
#>  8  151. -28.2 ALLSKY_S…  1985  7.98  6.86  5.74  4.46  3.67  3.34  3.8 
#>  9  152. -28.2 CLRSKY_S…  1984  8.45  8.09  6.77  5.5   4.41  3.95  4.15
#> 10  152. -28.2 CLRSKY_S…  1985  8.76  8.03  6.93  5.57  4.39  3.93  4.2 
#> # … with 186 more rows, and 6 more variables: AUG <dbl>, SEP <dbl>,
#> #   OCT <dbl>, NOV <dbl>, DEC <dbl>, ANN <dbl>

Example fetching climatology data

Global data are only available for the climatology temporal_average, setting this argument as such will fetch global data.

Fetch global “AG”" climatology for temperature and relative humidity.

climatology_ag <- get_power(community = "AG",
                            pars = c("T2M", "RH2M"),
                            lonlat = "GLOBAL",
                            temporal_average = "CLIMATOLOGY"
                           )

climatology_ag
#> NASA/POWER SRB/FLASHFlux/MERRA2/GEOS 5.12.4 (FP-IT) 0.5 x 0.5 Degree Climatologies  
#>  22-year Additional Solar Parameter Monthly & Annual Climatologies (July 1983 - June 2005), 30-year Meteorological and Solar Monthly & Annual Climatologies (January 1984 - December 2013)  
#>  Location: Global  
#>  Value for missing model data cannot be computed or out of model availability range: -99  
#>  Parameter(s):  
#>  RH2M MERRA2 1/2x1/2 Relative Humidity at 2 Meters (%)  
#>  
#>  Parameters: 
#>  NA;
#>  T2M MERRA2 1/2x1/2 Temperature at 2 Meters (C)  
#>  
#> # A tibble: 518,400 x 16
#>      LON   LAT PARAMETER   JAN   FEB   MAR   APR   MAY   JUN   JUL   AUG
#>    <dbl> <dbl> <chr>     <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#>  1 -180. -89.8 T2M       -29.0 -40.7 -52.9 -57.8 -59.1 -59.6 -61.3 -61.8
#>  2 -180. -89.8 RH2M       70.3  64.3  63.5  63.2  63.9  64.2  63.9  63.9
#>  3 -179. -89.8 T2M       -29.0 -40.7 -52.9 -57.8 -59.1 -59.6 -61.3 -61.8
#>  4 -179. -89.8 RH2M       70.3  64.3  63.4  63.2  63.9  64.2  63.9  63.9
#>  5 -179. -89.8 T2M       -29.0 -40.7 -52.9 -57.8 -59.1 -59.6 -61.3 -61.8
#>  6 -179. -89.8 RH2M       70.3  64.3  63.4  63.2  63.9  64.2  63.9  63.9
#>  7 -178. -89.8 T2M       -29.0 -40.7 -52.9 -57.8 -59.1 -59.6 -61.3 -61.8
#>  8 -178. -89.8 RH2M       70.3  64.3  63.4  63.2  63.9  64.2  63.9  63.9
#>  9 -178. -89.8 T2M       -29.0 -40.7 -52.9 -57.8 -59.1 -59.6 -61.3 -61.8
#> 10 -178. -89.8 RH2M       70.3  64.3  63.4  63.2  63.9  64.2  63.8  63.9
#> # … with 518,390 more rows, and 5 more variables: SEP <dbl>, OCT <dbl>,
#> #   NOV <dbl>, DEC <dbl>, ANN <dbl>

Note the associated metadata in the data frame header are not saved if the data are exported to a file format other than an R data format, e.g., .Rdata, .rda or .rds.

Description of parameters for get_power

Using create_met

The create_met() function wraps get_power(), prepareMet() and writeMet() from the APSIM package to simplify creating .met files from POWER data for use in the APSIM modelling framework.

Four arguments are passed to this function, lonlat, dates, dsn and file_out.

Get POWER values for a single point, Kingsthorpe, Queensland for 1985 and create an APSIM weather.met object suitable for use in APSIM for crop modelling and save it to local disk for use in APSIM modelling.

create_met(lonlat = c(151.81, -27.48),
           dates = c("1985-01-01", "1985-12-31"),
           dsn = tempdir(),
           file_out = "Kingsthorpe.met")
#> [1] "Required column name check:"
#> [1] "maxt" "mint" "radn" "rain" "year" "day" 
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE

Using create_icasa

The create_icasa() simplifies a get_power() query to create an ICASA file for use in DSSAT modelling.

Four arguments are passed to this function, lonlat, dates, dsn and file_out.

Get POWER values for a single point, Kingsthorpe, Queensland for 1985 and create an ICASA text file suitable for use in DSSAT for crop modelling and save it to local disk.

create_icasa(lonlat = c(151.81, -27.48),
             dates = c("1985-01-01", "1985-12-31"),
             dsn = tempdir(),
             file_out = "Kingsthorpe_ICASA.txt")

Creating Spatial Objects from get_power

If you require spatial objects to work with, it is rather simple to convert the resulting tidy data frame from get_power() to a spatial object in R using raster::rasterFromXYZ().

Converting Regional Data to a raster Object

Using lapply and split it is easy to create stacks of raster objects from a regional query.

Plot all the items in the stack.

Converting Global Climatology to a raster Object

Converting global climatology to a raster objects is as simple as querying and then converting the resulting tibble to a raster object using raster::rasterFromXYZ()*. Illustrated here using the climatology_ag object previously created are two methods.

*: You may experience issues if you have <16GB RAM available converting the entire object to a raster::brick().

For systems with more available memory

For systems with RAM of ~16GB or more, it is possible to create a raster::brick() of the resulting POWER query. To do so, subset the tibble() for the desired parameter and drop the PARAMETER column.

References

https://power.larc.nasa.gov

https://power.larc.nasa.gov/documents/POWER_Data_v9_methodology.pdf