-
Notifications
You must be signed in to change notification settings - Fork 5
/
README.Rmd
102 lines (79 loc) · 3.37 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
---
output: github_document
---
<!-- 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%"
)
```
# neonhs
[![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)
[![R-CMD-check](https://github.com/earthlab/neonhs/workflows/R-CMD-check/badge.svg)](https://github.com/earthlab/neonhs/actions)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/earthlab/neonhs?branch=master&svg=true)](https://ci.appveyor.com/project/earthlab/neonhs)
[![Coverage status](https://codecov.io/gh/earthlab/neonhs/branch/master/graph/badge.svg)](https://codecov.io/github/earthlab/neonhs?branch=master)
[![DOI](https://zenodo.org/badge/168047013.svg)](https://zenodo.org/badge/latestdoi/168047013)
The goal of neonhs is to make data from the National Ecological Observatory Network (NEON) Airborne Observation Platform (AOP) hyperspectral instrument easier to use.
The NEON AOP collects hyperspectral imagery via its at a 1 meter spatial resolution for 426 different wavelengths.
## Installation
You can install the development version of neonhs via:
```r
#install.packages('devtools')
devtools::install_github('earthlab/neonhs')
```
## Examples
### Create raster objects from hyperspectral images
This is a basic example which shows you how to read some bands from
L3 hyperspectral reflectance data as a multi-layer raster:
```{r example, message=FALSE}
library(neonhs)
library(raster)
library(viridis)
library(sp)
library(tidyverse)
path_to_file <- system.file('extdata', 'ex.h5', package = 'neonhs')
r <- hs_read(path_to_file, bands = c(1, 50, 100, 400))
r
```
```{r plot}
plot(r, col = cividis(100), axes = FALSE, box = FALSE)
```
### Extract spectra at spatial point locations
If you need to extract spectra at spatial points, there is a `hs_extract_pts`
function that extracts values from bands efficiently, without needing to first
create a raster object.
For example, we may want to extract spectra for every band at the following
two points, defined in a `SpatialPointsDataFrame`.
Note also that we can use the `hs_proj4string` function to get the proj4string
representation of the coordinate reference system used in the hyperspectral
image.
```{r plot_points}
pts <- SpatialPointsDataFrame(coords = data.frame(x = c(257025, 257011),
y = c(4111982, 4111991)),
data = data.frame(id = 1:2),
proj4string = CRS(hs_proj4string(path_to_file)))
plot(r[[1]], axes = FALSE, box = FALSE)
plot(pts, add = TRUE)
```
To do this efficiently, you can use `hs_extract_pts`:
```{r extract_pts}
vals <- hs_extract_pts(path_to_file, pts = pts, bands = 1:426)
vals
```
Now we have columns with band indices and wavelengths, which we can use to
plot spectra, e.g.,
```{r plot_spectra}
vals %>%
as_tibble() %>%
select(id, starts_with('band')) %>%
gather(band, reflectance, -id) %>%
separate(band, c('index', 'wavelength')) %>%
mutate(wavelength = parse_number(wavelength)) %>%
ggplot(aes(wavelength, reflectance, group = id)) +
geom_line() +
xlab('Wavelength (nm)') +
ylab('Reflectance')
```