forked from ropensci/FedData
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
275 lines (235 loc) · 11.1 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
---
output: github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
dpi = 72
)
```
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![CRAN version](https://www.r-pkg.org/badges/version/FedData)](https://cran.r-project.org/package=FedData)
[![CRAN downloads per month](https://cranlogs.r-pkg.org/badges/FedData)](https://github.com/metacran/cranlogs.app)
[![CRAN downloads](https://cranlogs.r-pkg.org/badges/grand-total/FedData)](https://github.com/metacran/cranlogs.app)
[![Build Status](https://api.travis-ci.org/ropensci/FedData.png)](https://travis-ci.org/ropensci/FedData)
[![Coverage Status](https://img.shields.io/codecov/c/github/ropensci/FedData/master.svg)](https://codecov.io/github/ropensci/FedData?branch=master)
[![Zenodo DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.596344.svg)](https://doi.org/10.5281/zenodo.596344)
[![ROpenSci Status](https://badges.ropensci.org/13_status.svg)](https://github.com/ropensci/onboarding/issues/13)
`FedData` is an *R* package implementing functions to automate downloading geospatial data available from several federated data sources (mainly sources maintained by the US Federal government).
**FedData version 2.5 will be the final minor CRAN release of FedData 2. FedData 3 will be released in the coming months, but some code built on FedData 2 will not be compatible with FedData 3.**
Currently, the package enables extraction from seven datasets:
* The [National Elevation Dataset (NED)](http://ned.usgs.gov) digital elevation models (1 and 1/3 arc-second; USGS)
* The [National Hydrography Dataset (NHD)](http://nhd.usgs.gov) (USGS)
* The [Soil Survey Geographic (SSURGO) database](http://websoilsurvey.sc.egov.usda.gov/) from the National Cooperative Soil Survey (NCSS), which is led by the Natural Resources Conservation Service (NRCS) under the USDA
* The [Global Historical Climatology Network (GHCN)](http://www.ncdc.noaa.gov/data-access/land-based-station-data/land-based-datasets/global-historical-climatology-network-ghcn), coordinated by National Climatic Data Center at NOAA
* The [Daymet](https://daymet.ornl.gov/) gridded estimates of daily weather parameters for North America, version 3, available from the Oak Ridge National Laboratory's Distributed Active Archive Center (DAAC)
* The [International Tree Ring Data Bank (ITRDB)](http://www.ncdc.noaa.gov/data-access/paleoclimatology-data/datasets/tree-ring), coordinated by National Climatic Data Center at NOAA
* The [National Land Cover Database (NLCD)](https://www.mrlc.gov/)
* The [NASS Cropland Data Layer](https://www.nass.usda.gov/Research_and_Science/Cropland/SARS1a.php) from the National Agricultural Statistics Service
This package is designed with the large-scale geographic information system (GIS) use-case in mind: cases where the use of dynamic web-services is impractical due to the scale (spatial and/or temporal) of analysis. It functions primarily as a means of downloading tiled or otherwise spatially-defined datasets; additionally, it can preprocess those datasets by extracting data within an area of interest (AoI), defined spatially. It relies heavily on the [**sp**](https://cran.r-project.org/package=sp), [**raster**](https://cran.r-project.org/package=raster), and [**rgdal**](https://cran.r-project.org/package=rgdal) packages.
This package has been built and tested on a source (Homebrew) install of *R* on macOS 10.14 (High Sierra), and has been successfully run on Ubuntu 14.04.5 LTS (Trusty), Ubuntu 16.04.1 LTS (Xenial) and binary installs of *R* on Mac OS 10.14 and Windows 10.
### Development
+ [Kyle Bocinsky](http://bocinsky.io) - Crow Canyon Archaeological Center, Cortez, CO
### Contributors
+ Dylan Beaudette - USDA-NRCS Soil Survey Office, Sonora, CA
+ Scott Chamberlain - ROpenSci and Museum of Paleontology at UC Berkeley
### Install `FedData`
+ From CRAN:
```{r eval = FALSE}
install.packages('FedData')
```
+ Development version from GitHub:
```{r eval = FALSE}
install.packages("devtools")
devtools::install_github("ropensci/FedData")
```
+ Linux (Ubuntu 14.04.5 or 16.04.1):
First, in terminal:
```bash
sudo add-apt-repository ppa:ubuntugis/ppa -y
sudo apt-get update -q
sudo apt-get install libssl-dev libcurl4-openssl-dev netcdf-bin libnetcdf-dev gdal-bin libgdal-dev
```
Then, in R:
```{r eval = FALSE}
update.packages("survival")
install.packages("devtools")
devtools::install_github("ropensci/FedData")
```
### Demonstration
This demonstration script is available as an R Markdown document in the GitHub repository: [https://github.com/ropensci/FedData](https://github.com/ropensci/FedData).
#### Load `FedData` and define a study area
```{r results="hide", message=FALSE}
# FedData Tester
library(FedData)
library(magrittr)
# Extract data for the Village Ecodynamics Project "VEPIIN" study area:
# http://veparchaeology.org
vepPolygon <- polygon_from_extent(raster::extent(672800, 740000, 4102000, 4170000),
proj4string = "+proj=utm +datum=NAD83 +zone=12")
```
#### Get and plot the National Elevation Dataset for the study area
```{r results="hide", message=FALSE}
# Get the NED (USA ONLY)
# Returns a raster
NED <- get_ned(template = vepPolygon,
label = "VEPIIN")
# Plot with raster::plot
raster::plot(NED)
```
#### Get and plot the Daymet dataset for the study area
```{r results="hide", message=FALSE, warning=FALSE}
# Get the DAYMET (North America only)
# Returns a raster
DAYMET <- get_daymet(template = vepPolygon,
label = "VEPIIN",
elements = c("prcp","tmax"),
years = 1980:1985)
# Plot with raster::plot
raster::plot(DAYMET$tmax$X1985.10.23)
```
#### Get and plot the daily GHCN precipitation data for the study area
```{r results="hide", message=FALSE}
# Get the daily GHCN data (GLOBAL)
# Returns a list: the first element is the spatial locations of stations,
# and the second is a list of the stations and their daily data
GHCN.prcp <- get_ghcn_daily(template = vepPolygon,
label = "VEPIIN",
elements = c('prcp'))
# Plot the NED again
raster::plot(NED)
# Plot the spatial locations
sp::plot(GHCN.prcp$spatial,
pch = 1,
add = TRUE)
legend('bottomleft',
pch = 1,
legend="GHCN Precipitation Records")
```
#### Get and plot the daily GHCN temperature data for the study area
```{r results="hide", message=FALSE}
# Elements for which you require the same data
# (i.e., minimum and maximum temperature for the same days)
# can be standardized using standardize==T
GHCN.temp <- get_ghcn_daily(template = vepPolygon,
label = "VEPIIN",
elements = c('tmin','tmax'),
years = 1980:1985,
standardize = TRUE)
# Plot the NED again
raster::plot(NED)
# Plot the spatial locations
sp::plot(GHCN.temp$spatial,
add = TRUE,
pch = 1)
legend('bottomleft',
pch = 1,
legend = "GHCN Temperature Records")
```
#### Get and plot the National Hydrography Dataset for the study area
```{r results="hide", message=FALSE}
# Get the NHD (USA ONLY)
NHD <- get_nhd(template = vepPolygon,
label = "VEPIIN")
# Plot the NED again
raster::plot(NED)
# Plot the NHD data
NHD %>%
lapply(sp::plot,
col = 'black',
add = TRUE)
```
#### Get and plot the NRCS SSURGO data for the study area
```{r results="hide", message=FALSE, warning=FALSE}
# Get the NRCS SSURGO data (USA ONLY)
SSURGO.VEPIIN <- get_ssurgo(template = vepPolygon,
label = "VEPIIN")
# Plot the NED again
raster::plot(NED)
# Plot the SSURGO mapunit polygons
plot(SSURGO.VEPIIN$spatial,
lwd = 0.1,
add = TRUE)
```
#### Get and plot the NRCS SSURGO data for particular soil survey areas
```{r results="hide", message=FALSE}
# Or, download by Soil Survey Area names
SSURGO.areas <- get_ssurgo(template = c("CO670","CO075"),
label = "CO_TEST")
# Let's just look at spatial data for CO675
SSURGO.areas.CO675 <- SSURGO.areas$spatial[SSURGO.areas$spatial$AREASYMBOL=="CO075",]
# And get the NED data under them for pretty plotting
NED.CO675 <- get_ned(template = SSURGO.areas.CO675,
label = "SSURGO_CO675")
# Plot the SSURGO mapunit polygons, but only for CO675
plot(NED.CO675)
plot(SSURGO.areas.CO675,
lwd = 0.1,
add = TRUE)
```
#### Get and plot the ITRDB chronology locations in the study area
```{r results="hide", message=FALSE}
# Get the ITRDB records
ITRDB <- get_itrdb(template = vepPolygon,
label = "VEPIIN",
recon.years = 850:2000,
calib.years = 1924:1983,
measurement.type = "Ring Width",
chronology.type = "ARSTND")
# Plot the NED again
raster::plot(NED)
# Map the locations of the tree ring chronologies
plot(ITRDB$metadata$geometry,
pch = 1,
add = TRUE)
legend('bottomleft',
pch = 1,
legend = "ITRDB chronologies")
```
#### Get and plot the National Land Cover Dataset for the study area
```{r results="hide", message=FALSE}
# Get the NLCD (USA ONLY)
# Returns a raster
NLCD <- get_nlcd(template = vepPolygon,
year = 2016,
dataset = "Land_Cover",
label = "VEPIIN")
# Plot with raster::plot
raster::plot(NLCD)
# You can also download the Canopy (2011 only) or impervious datasets:
NLCD_canopy <- get_nlcd(template = vepPolygon,
year = 2011,
dataset = "Tree_Canopy",
label = "VEPIIN")
# Plot with raster::plot
raster::plot(NLCD_canopy)
NLCD_impervious <- get_nlcd(template = vepPolygon,
year = 2016,
dataset = "Impervious",
label = "VEPIIN")
# Plot with raster::plot
raster::plot(NLCD_impervious)
```
#### Get and plot the NASS Cropland Data Layer for the study area
```{r results="hide", message=FALSE}
# Get the NASS (USA ONLY)
# Returns a raster
NASS <- get_nass(template = vepPolygon,
year = 2016,
label = "VEPIIN")
# Plot with raster::plot
raster::plot(NASS)
# Get the NASS classification table
raster::levels(NASS)[[1]]
```
-----------
### Acknowledgements
This package is a product of SKOPE ([Synthesizing Knowledge of Past Environments](http://www.openskope.org)) and the Village Ecodynamics Project. This software is licensed under the [MIT license](https://opensource.org/licenses/MIT).
FedData was reviewed for [rOpenSci](https://ropensci.org) by [\@jooolia](https://github.com/jooolia), and was greatly improved as a result. [rOpenSci](https://ropensci.org) onboarding was coordinated by [\@sckott](https://github.com/sckott).
<!-- [![ropensci_footer](https://ropensci.org/public_images/ropensci_footer.png)](https://ropensci.org) -->