diff --git a/tutorials/R/AOP/Hyperspectral/RasterStack-RGB-Images-in-R-Using-HSI/RasterStack-RGB-Images-in-R-Using-HSI.R b/tutorials/R/AOP/Hyperspectral/RasterStack-RGB-Images-in-R-Using-HSI/RasterStack-RGB-Images-in-R-Using-HSI.R index a7e2eda0..b988edef 100644 --- a/tutorials/R/AOP/Hyperspectral/RasterStack-RGB-Images-in-R-Using-HSI/RasterStack-RGB-Images-in-R-Using-HSI.R +++ b/tutorials/R/AOP/Hyperspectral/RasterStack-RGB-Images-in-R-Using-HSI/RasterStack-RGB-Images-in-R-Using-HSI.R @@ -1,16 +1,16 @@ -## ----load-libraries---------------------------------------------------------------------------------------------------------------------------------------- +## ----load-libraries, results="hide"----------------------------------------------------------------------------------------------------------------------------- library(terra) library(rhdf5) library(neonUtilities) -## ----set-wd------------------------------------------------------------------------------------------------------------------------------------------------ +## ----set-wd----------------------------------------------------------------------------------------------------------------------------------------------------- # set working directory (this will depend on your local environment) wd <- "~/data/" setwd(wd) -## ----download-refl, eval=FALSE----------------------------------------------------------------------------------------------------------------------------- +## ----download-refl, eval=FALSE---------------------------------------------------------------------------------------------------------------------------------- ## byTileAOP(dpID = 'DP3.30006.001', ## site = 'SJER', ## year = '2021', @@ -19,16 +19,16 @@ setwd(wd) ## savepath = wd) -## ----define-h5, results="hide"----------------------------------------------------------------------------------------------------------------------------- +## ----define-h5, results="hide"---------------------------------------------------------------------------------------------------------------------------------- # Define the h5 file name to be opened h5_file <- paste0(wd,"DP3.30006.001/neon-aop-products/2021/FullSite/D17/2021_SJER_5/L3/Spectrometer/Reflectance/NEON_D17_SJER_DP3_257000_4112000_reflectance.h5") -## ----view-file-structure, eval=FALSE, comment=NA----------------------------------------------------------------------------------------------------------- +## ----view-file-structure, eval=FALSE, comment=NA---------------------------------------------------------------------------------------------------------------- View(h5ls(h5_file,all=T)) -## ----get-spatial-attributes-------------------------------------------------------------------------------------------------------------------------------- +## ----get-spatial-attributes------------------------------------------------------------------------------------------------------------------------------------- # define coordinate reference system from the EPSG code provided in the HDF5 file h5EPSG <- h5read(h5_file,"/SJER/Reflectance/Metadata/Coordinate_System/EPSG Code" ) @@ -54,7 +54,7 @@ h5NoDataValue <- as.integer(reflInfo$Data_Ignore_Value) cat('No Data Value:',h5NoDataValue) -## ----function-read-refl-data------------------------------------------------------------------------------------------------------------------------------- +## ----function-read-refl-data------------------------------------------------------------------------------------------------------------------------------------ # file: the hdf5 file # band: the band you want to process @@ -85,7 +85,7 @@ band2Raster <- function(file, band, noDataValue, extent, CRS){ -## ----create-raster-list------------------------------------------------------------------------------------------------------------------------------------ +## ----create-raster-list----------------------------------------------------------------------------------------------------------------------------------------- # create a list of the bands (R,G,B) we want to include in our stack rgb <- list(58,34,19) @@ -97,11 +97,11 @@ rgb_rast <- lapply(rgb,FUN=band2Raster, file = h5_file, CRS=h5CRS) -## ----rgb-rast-properties----------------------------------------------------------------------------------------------------------------------------------- +## ----rgb-rast-properties---------------------------------------------------------------------------------------------------------------------------------------- rgb_rast -## ----raster-stack------------------------------------------------------------------------------------------------------------------------------------------ +## ----raster-stack----------------------------------------------------------------------------------------------------------------------------------------------- rgbStack <- rast(rgb_rast) @@ -117,7 +117,7 @@ names(rgbStack) <- bandNames rgbStack -## ----scale-plot-refl--------------------------------------------------------------------------------------------------------------------------------------- +## ----scale-plot-refl-------------------------------------------------------------------------------------------------------------------------------------------- # scale the data as specified in the reflInfo$Scale Factor rgbStack <- rgbStack/as.integer(reflInfo$Scale_Factor) @@ -147,7 +147,7 @@ plotRGB(rgbStack, stretch = "lin") -## ----save-raster-geotiff, eval=FALSE, comment=NA----------------------------------------------------------------------------------------------------------- +## ----save-raster-geotiff, eval=FALSE, comment=NA---------------------------------------------------------------------------------------------------------------- # Write out final raster # Note: if you set overwrite to TRUE, then you will overwrite (and lose) any older version of the tif file! writeRaster(rgbStack, file=paste0(wd,"NEON_hyperspectral_tutorial_example_RGB_image.tif"), overwrite=TRUE) diff --git a/tutorials/R/AOP/Hyperspectral/RasterStack-RGB-Images-in-R-Using-HSI/RasterStack-RGB-Images-in-R-Using-HSI.Rmd b/tutorials/R/AOP/Hyperspectral/RasterStack-RGB-Images-in-R-Using-HSI/RasterStack-RGB-Images-in-R-Using-HSI.Rmd index 0aa0e40a..7699298c 100755 --- a/tutorials/R/AOP/Hyperspectral/RasterStack-RGB-Images-in-R-Using-HSI/RasterStack-RGB-Images-in-R-Using-HSI.Rmd +++ b/tutorials/R/AOP/Hyperspectral/RasterStack-RGB-Images-in-R-Using-HSI/RasterStack-RGB-Images-in-R-Using-HSI.Rmd @@ -93,7 +93,7 @@ These steps included loading required packages, downloading the data (optionally First, let's load the required R packages, `terra` and `rhdf5`. -```{r load-libraries} +```{r load-libraries, results="hide"} library(terra) library(rhdf5) library(neonUtilities) @@ -342,7 +342,13 @@ In this last part, we will calculate some vegetation indices using raster math i ### About NDVI -NDVI is a ratio between the near infrared (NIR) portion of the electromagnetic spectrum and the red portion of the spectrum. Please keep in mind that there are different ways to aggregate bands when using hyperspectral data. This example is using individual bands to perform the NDVI calculation. Using individual bands is not necessarily the best way to calculate NDVI from hyperspectral data! +NDVI is a ratio between the near infrared (NIR) portion of the electromagnetic spectrum and the red portion of the spectrum. + +$$ +NDVI = \frac{NIR-RED}{NIR+RED} +$$ + +Please keep in mind that there are different ways to aggregate bands when using hyperspectral data. This example is using individual bands to perform the NDVI calculation. Using individual bands is not necessarily the best way to calculate NDVI from hyperspectral data. ```{r create-NDVI, fig.cap=c("Raster plot of a portion of the SJER field site showing calculated NDVI values. The x-axis and y-axis values represent the extent, which range from 257500 to 258000 meters easting, and 4112500 to 4113000 meters northing, respectively. Plot legend goes from -1 to 1.","Raster plot of a portion of the SJER field site showing calculated NDVI values with predefined breaks at 0, 0.25, 0.5, 05, and 1. The x-axis and y-axis values represent the extent, which range from 257500 to 258000 meters easting, and 4112500 to 4113000 meters northing, respectively. Plot legend goes from 0 to 1.") } @@ -392,7 +398,7 @@ Try the following on your own: 1. Calculate the Normalized Difference Nitrogen Index (NDNI) using the following equation: $$ -\frac{log(\frac{1}{p_{1510}}) - log(\frac{1}{p_{1680}})}{log(\frac{1}{p_{1510}}) + log(\frac{1}{p_{1680}})} +NDNI = \frac{log(\frac{1}{p_{1510}}) - log(\frac{1}{p_{1680}})}{log(\frac{1}{p_{1510}}) + log(\frac{1}{p_{1680}})} $$ 2. Calculate the Enhanced Vegetation Index (EVI). Hint: Look up the formula, and apply the appropriate NEON bands. Hint: You can look at satellite datasets, such as USGS Landsat EVI. diff --git a/tutorials/R/AOP/Hyperspectral/RasterStack-RGB-Images-in-R-Using-HSI/RasterStack-RGB-Images-in-R-Using-HSI.html b/tutorials/R/AOP/Hyperspectral/RasterStack-RGB-Images-in-R-Using-HSI/RasterStack-RGB-Images-in-R-Using-HSI.html index 71ad990e..424db167 100644 --- a/tutorials/R/AOP/Hyperspectral/RasterStack-RGB-Images-in-R-Using-HSI/RasterStack-RGB-Images-in-R-Using-HSI.html +++ b/tutorials/R/AOP/Hyperspectral/RasterStack-RGB-Images-in-R-Using-HSI/RasterStack-RGB-Images-in-R-Using-HSI.html @@ -417,7 +417,11 @@

Challenge: Other band combinationsRaster Math - Creating NDVI and other Vegetation Indices in R

In this last part, we will calculate some vegetation indices using raster math in R! We will start by creating NDVI or Normalized Difference Vegetation Index.

About NDVI

-

NDVI is a ratio between the near infrared (NIR) portion of the electromagnetic spectrum and the red portion of the spectrum. Please keep in mind that there are different ways to aggregate bands when using hyperspectral data. This example is using individual bands to perform the NDVI calculation. Using individual bands is not necessarily the best way to calculate NDVI from hyperspectral data!

+

NDVI is a ratio between the near infrared (NIR) portion of the electromagnetic spectrum and the red portion of the spectrum.

+

$$ +NDVI = \frac{NIR-RED}{NIR+RED} +$$

+

Please keep in mind that there are different ways to aggregate bands when using hyperspectral data. This example is using individual bands to perform the NDVI calculation. Using individual bands is not necessarily the best way to calculate NDVI from hyperspectral data.

# Calculate NDVI
 
 # select bands to use in calculation (red, NIR)
@@ -493,7 +497,7 @@ 

Challenge: Work with Indices

  • Calculate the Normalized Difference Nitrogen Index (NDNI) using the following equation:
  • $$ -\frac{log(\frac{1}{p_{1510}}) - log(\frac{1}{p_{1680}})}{log(\frac{1}{p_{1510}}) + log(\frac{1}{p_{1680}})} +NDNI = \frac{log(\frac{1}{p_{1510}}) - log(\frac{1}{p_{1680}})}{log(\frac{1}{p_{1510}}) + log(\frac{1}{p_{1680}})} $$ 2. Calculate the Enhanced Vegetation Index (EVI). Hint: Look up the formula, and apply the appropriate NEON bands. Hint: You can look at satellite datasets, such as USGS Landsat EVI.

      diff --git a/tutorials/R/AOP/Hyperspectral/RasterStack-RGB-Images-in-R-Using-HSI/RasterStack-RGB-Images-in-R-Using-HSI.md b/tutorials/R/AOP/Hyperspectral/RasterStack-RGB-Images-in-R-Using-HSI/RasterStack-RGB-Images-in-R-Using-HSI.md index b14a0be9..a9875f5e 100644 --- a/tutorials/R/AOP/Hyperspectral/RasterStack-RGB-Images-in-R-Using-HSI/RasterStack-RGB-Images-in-R-Using-HSI.md +++ b/tutorials/R/AOP/Hyperspectral/RasterStack-RGB-Images-in-R-Using-HSI/RasterStack-RGB-Images-in-R-Using-HSI.md @@ -433,7 +433,13 @@ In this last part, we will calculate some vegetation indices using raster math i ### About NDVI -NDVI is a ratio between the near infrared (NIR) portion of the electromagnetic spectrum and the red portion of the spectrum. Please keep in mind that there are different ways to aggregate bands when using hyperspectral data. This example is using individual bands to perform the NDVI calculation. Using individual bands is not necessarily the best way to calculate NDVI from hyperspectral data! +NDVI is a ratio between the near infrared (NIR) portion of the electromagnetic spectrum and the red portion of the spectrum. + +$$ +NDVI = \frac{NIR-RED}{NIR+RED} +$$ + +Please keep in mind that there are different ways to aggregate bands when using hyperspectral data. This example is using individual bands to perform the NDVI calculation. Using individual bands is not necessarily the best way to calculate NDVI from hyperspectral data. # Calculate NDVI @@ -517,7 +523,7 @@ Try the following on your own: 1. Calculate the Normalized Difference Nitrogen Index (NDNI) using the following equation: $$ -\frac{log(\frac{1}{p_{1510}}) - log(\frac{1}{p_{1680}})}{log(\frac{1}{p_{1510}}) + log(\frac{1}{p_{1680}})} +NDNI = \frac{log(\frac{1}{p_{1510}}) - log(\frac{1}{p_{1680}})}{log(\frac{1}{p_{1510}}) + log(\frac{1}{p_{1680}})} $$ 2. Calculate the Enhanced Vegetation Index (EVI). Hint: Look up the formula, and apply the appropriate NEON bands. Hint: You can look at satellite datasets, such as USGS Landsat EVI.