The nasadata R package

This package, written by Eduardo Flores, provides an attractive way to access some of NASA’s open-source API’s to build applications or models. This document is based on the package vignette.

The package is built around three API’s, but for the sake of clarity, the first two are grouped into one example.

EONET Webservice

The Earth Observatory Natural Event Tracker is a Webservice that feeds curated natural “events” that are tracked by a few sources.

An event is something like a storm, fire, drought, etc. So, let’s suppose we want to see some event that occured a few days ago.

Let’s start by installing the package.

#install.packages("devtools")
#devtools::install_github("Eflores89/nasadata")
#install.packages("nasadata")
#install.packages("DBI")
library(nasadata)

Including Plots

Now, we can query the webservice to find all of the available ones like this:

categories <- eonet_categories()
categories[,1:2]
##    id                title
## 1   6              Drought
## 2   7        Dust and Haze
## 3  16          Earthquakes
## 4   9               Floods
## 5  14           Landslides
## 6  19              Manmade
## 7  15     Sea and Lake Ice
## 8  10        Severe Storms
## 9  17                 Snow
## 10 18 Temperature Extremes
## 11 12            Volcanoes
## 12 13          Water Color
## 13  8            Wildfires

The sources reporting these events are very important, so we can see this with a similar function:

sources <- eonet_sources()
  # there are a few columns, I'll only show two...
names(sources)
## [1] "id"     "title"  "source" "link"
# [1] "id"     "title"  "source" "link" 
sources[,1:2]
##            id                                                       title
## 1      AU_BOM                             Australia Bureau of Meteorology
## 2  BCWILDFIRE                           British Columbia Wildfire Service
## 3     CALFIRE       California Department of Forestry and Fire Protection
## 4        CEMS                     Copernicus Emergency Management Service
## 5          EO                                           Earth Observatory
## 6       GDACS               Global Disaster Alert and Coordination System
## 7       GLIDE                            GLobal IDEntifier Number (GLIDE)
## 8     InciWeb                                                     InciWeb
## 9         IDC          International Charter on Space and Major Disasters
## 10        MRR                                        LANCE Rapid Response
## 11  NASA_ESRS                  NASA Earth Science and Remote Sensing Unit
## 12        PDC                                     Pacific Disaster Center
## 13  ReliefWeb                                                   ReliefWeb
## 14  SIVolcano            Smithsonian Institution Global Volcanism Program
## 15     NATICE                                    U.S. National Ice Center
## 16     UNISYS                                              Unisys Weather
## 17   USGS_CMT        USGS Emergency Operations Collection Management Tool
## 18       HDDS                       USGS Hazards Data Distribution System
## 19    DFES_WA Western Australia Department of Fire and Emergency Services

Now that we got this, let’s see if we can get several individual events. The earth_event() function does this in an intuitive way. We are going to bring the latest five events reported by InciWeb:

five_events <- earth_event(status = "all", 
                        sources = "InciWeb", 
                        category_id = "all", 
                        limit = 5,
                        LimitType = "limit")
class(five_events)
## [1] "list"
names(five_events)
## [1] "Events"     "Sources"    "Categories" "Geography"  "Meta"
five_events$Events$event_id
## [1] "EONET_2745" "EONET_2744" "EONET_2740" "EONET_2743" "EONET_2732"
five_events$Events$event_title
## [1] "283 Fire, OKLAHOMA"                       
## [2] "Starbuck Fire, OKLAHOMA"                  
## [3] "Perryton Fire , TEXAS"                    
## [4] "Northwest Oklahoma Complex Fire, OKLAHOMA"
## [5] "Rael Fire, NEW MEXICO"
five_events$Sources$source_url
## [1] "https://inciweb.nwcg.gov/incident/5136/"
## [2] "https://inciweb.nwcg.gov/incident/5135/"
## [3] "https://inciweb.nwcg.gov/incident/5133/"
## [4] "https://inciweb.nwcg.gov/incident/5138/"
## [5] "https://inciweb.nwcg.gov/incident/5132/"
five_events$Geography
## $EONET_2745
##                   date  type         coordinates
## 1 2017-03-07T01:30:00Z Point -99.83722, 36.71000
## 
## $EONET_2744
##                   date  type          coordinates
## 1 2017-03-07T00:30:00Z Point -100.17528, 36.77444
## 
## $EONET_2740
##                   date  type          coordinates
## 1 2017-03-06T16:00:00Z Point -100.53472, 36.09306
## 
## $EONET_2743
##                   date  type          coordinates
## 1 2017-03-06T12:30:00Z Point -100.17528, 36.44111
## 
## $EONET_2732
##                   date  type        coordinates
## 1 2017-03-02T11:30:00Z Point -108.3394, 33.8000

Imagery and Assets API’s

The Earth Imagery API lets users access imagery that is being retrieved from Landsat 8 Satellites and stored in Google Earth Engine. From what we will see, the images are poor quality but one obvious solution here is to obtain before and after images and detect large variations from them.

The Assets API is basically a helper for the Imagery API: it gives us dates of available coordinates, so that we can query the latter and retrieve the image.

Let’s see if we can see one of the “five events” we recorded earlier. specifically the one identified as EONET_2732

First, we want to see if there is any images recorded in that time frame (the Landsat frecuency is roughly every 16 days).

# coordinates of event
coordenadas <- five_events$Geography


coordenadas$EONET_2732$coordinates[[1]]
## [1] -108.3394   33.8000
coord_long <-  coordenadas$EONET_2732$coordinates[[1]][1]

coord_lat <- coordenadas$EONET_2732$coordinates[[1]][2]


coordenadas$EONET_2732$date
## [1] "2017-03-02T11:30:00Z"

In the following code the key must correspond to your NASA API key. It’s free and you can get it at api.nasa.gov

# images available
images <- earth_asset(key, 
                      lon = coord_long, 
                      lat = coord_lat, 
                      start_date = "2016-03-01", 
                      end_date = "2017-03-12")
names(images)
## [1] "date"        "id"          "type"        "coordinates"
images$date
##  [1] 2016-05-04T17:44:41 2016-03-01T17:45:21 2016-03-17T17:45:16
##  [4] 2016-04-02T17:45:07 2016-04-18T17:45:01 2016-05-04T17:45:05
##  [7] 2016-05-20T17:45:03 2016-06-05T17:45:08 2016-06-21T17:45:13
## [10] 2016-07-07T17:45:22 2016-07-23T17:45:27 2016-08-08T17:45:29
## [13] 2016-08-24T17:45:36 2016-09-09T17:45:41 2016-09-25T17:45:42
## [16] 2016-10-11T17:45:46 2016-10-27T17:45:49 2016-11-12T17:45:48
## [19] 2016-11-28T17:45:48 2016-12-14T17:45:44 2017-01-31T17:45:31
## [22] 2017-02-16T17:45:24 2017-03-04T17:45:17 2016-03-08T17:51:07
## [25] 2016-03-24T17:50:59 2016-04-09T17:50:52 2016-04-25T17:50:46
## [28] 2016-05-11T17:50:47 2016-05-27T17:50:53 2016-06-12T17:50:56
## [31] 2016-06-28T17:51:04 2016-07-14T17:51:12 2016-07-30T17:51:16
## [34] 2016-08-15T17:51:19 2016-08-31T17:51:26 2016-09-16T17:51:29
## [37] 2016-10-02T17:51:30 2016-10-18T17:51:35 2016-11-03T17:51:35
## [40] 2016-11-19T17:51:35 2016-12-05T17:51:34 2016-12-21T17:51:29
## [43] 2017-01-06T17:51:26 2017-01-22T17:51:22 2017-02-07T17:51:13
## [46] 2017-02-23T17:51:08 2016-03-08T17:51:31 2016-03-24T17:51:23
## [49] 2016-04-09T17:51:16 2016-04-25T17:51:10 2016-05-11T17:51:11
## [52] 2016-05-27T17:51:17 2016-06-12T17:51:20 2016-06-28T17:51:28
## [55] 2016-07-14T17:51:35 2016-07-30T17:51:39 2016-08-15T17:51:43
## [58] 2016-08-31T17:51:50 2016-09-16T17:51:53 2016-10-02T17:51:54
## [61] 2016-10-18T17:51:59 2016-11-03T17:51:59 2016-11-19T17:51:59
## [64] 2016-12-05T17:51:58 2016-12-21T17:51:53 2017-01-06T17:51:50
## [67] 2017-01-22T17:51:45 2017-02-07T17:51:37 2017-02-23T17:51:32
## 69 Levels: 2016-03-01T17:45:21 2016-03-08T17:51:07 ... 2017-03-04T17:45:17

So, it seems we are lucky. The fire ocurred before the last picture taken. Thus, let’s see how we can download this last image.

img <- earth_image(key, 
                  lon = coord_long, 
                  lat = coord_lat, 
                  date = "2017-03-04", plot = TRUE)

The above image has a poor spatial resolution. It’s very hard to recognize what is going on. Let’s try seeing an image before the event:

img <- earth_image(key, 
                  lon = coord_long, 
                  lat = coord_lat, 
                  date = "2017-02-23", plot = TRUE)