---
title: "SWDI vignette"
author: "Scott Chamberlain"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{SWDI vignette}
  %\VignetteEngine{knitr::rmarkdown}
  \usepackage[utf8]{inputenc}
---

```{r, echo = FALSE, warning = FALSE, message = FALSE}
knitr::opts_chunk$set(
  collapse  =  TRUE,
  comment  =  "#>",
  purl  =  FALSE,
  eval  =  FALSE
)
```
```

`SWDI` is the Severe Weather Data Inventory. SWDI is an (quoting)

> integrated database of severe weather records for the United States. The records in SWDI come from a variety of sources in the NCDC archive. SWDI provides the ability to search through all of these data to find records covering a particular time period and geographic region, and to download the results of your search in a variety of formats. The formats currently supported are Shapefile (for GIS), KMZ (for Google Earth), CSV (comma-separated), and XML.

Data available in SWDI are:

* Storm Cells from NEXRAD (Level-III Storm Structure Product)
* Hail Signatures from NEXRAD (Level-III Hail Product)
* Mesocyclone Signatures from NEXRAD (Level-III Meso Product)
* Digital Mesocyclone Detection Algorithm from NEXRAD (Level-III MDA Product)
* Tornado Signatures from NEXRAD (Level-III TVS Product)
* Preliminary Local Storm Reports from the NOAA National Weather Service
* Lightning Strikes from Vaisala NLDN

Find out more about SWDI at [http://www.ncdc.noaa.gov/swdi/#Intro](http://www.ncdc.noaa.gov/swdi/#Intro).


## Load rnoaa

```{r load, message=FALSE, warning=FALSE}
library('rnoaa')
```

## Search for nx3tvs data from 5 May 2006 to 6 May 2006

```{r}
swdi(dataset='nx3tvs', startdate='20060505', enddate='20060506')
```

## Use an id

```{r}
out <- swdi(dataset='warn', startdate='20060506', enddate='20060507', id=533623)
list(out$meta, head(out$data), head(out$shape))
```

## Get all 'plsr' within the bounding box (-91,30,-90,31)

```{r}
swdi(dataset='plsr', startdate='20060505', enddate='20060510', bbox=c(-91,30,-90,31))
```

## Get all 'nx3tvs' within the tile -102.1/32.6 (-102.15,32.55,-102.25,32.65)

```{r}
swdi(dataset='nx3tvs', startdate='20060506', enddate='20060507', tile=c(-102.12,32.62))
```

## Counts

Notes:

* stat='count' will only return metadata, nothing in the data or shape slots
* stat='tilesum:...' returns counts in the data slot for each date for that tile, and shape data
* Get number of 'nx3tvs' within 15 miles of latitude = 32.7 and longitude = -102.0

Get daily count nx3tvs features on .1 degree grid centered at `latitude = 32.7` and `longitude = -102.0`

```{r}
swdi(dataset='nx3tvs', startdate='20060505', enddate='20090516', stat='tilesum:-102.0,32.7')
```

## Get data in different formats

### CSV format

```{r}
head(swdi(dataset='nx3tvs', startdate='20060505', enddate='20060506', format='csv')$data)
```

### SHP format

```{r}
swdi(dataset='nx3tvs', startdate='20060505', enddate='20060506', format='shp', filepath='myfile')
```

### KMZ format

```{r}
swdi(dataset='nx3tvs', startdate='20060505', enddate='20060506', format='kmz', radius=15, filepath='myfile.kmz')
```


```{r echo=FALSE}
# cleanup
unlink("myfile")
unlink("myfile.kmz")
```
