knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
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.
You can install the development version of neonhs via:
#install.packages('devtools') devtools::install_github('earthlab/neonhs')
This is a basic example which shows you how to read some bands from L3 hyperspectral reflectance data as a multi-layer raster:
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
plot(r, col = cividis(100), axes = FALSE, box = FALSE)
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.
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
:
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.,
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')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.