Masthead

Lab 6: ENVI Modeler

Introduction

The ENVI Modeler is a visual programming tool that you can use to create custom task-based workflows in ENVI. The user interface is designed to help users build workflows without any knowledge of ENVI programming. You can easily create custom workflows and batch process data with the ENVI Modeler.

Example ENVI Models From NV5 Geospatial

Examples ENVI Models from GitHub

About the Data
The primary data used in the lab are Landsat 8/9 Collection 2 Level 2 Surface Reflectance data. The images are of the northern California and were acquired by Landsat satellites in July of 2021, 2022 and 2023. In late July 2021, a series of lightening storms ignited multiple fires across the region. The Monument Fire started on July 30th near Monument Peak in Trinity County and burned over 200,000 acres. Per US Forest Services reports, the fire burned within the footprints of several previous fires: the 2006 Pigeon Fire, 2015 Happy Fire and 2008 Cedar, Eagle, Miners, and Buckhorn Fires. Also included is a shapefile showing the final fire perimeter of the Monument Fire. The file was extracted from the CalFire fire perimeter database (available at https://frap.fire.ca.gov/mapping/gis-data/ and https://hub-calfire-forestry.hub.arcgis.com/).

ENVI Modeler Introduction

 

  1. Create a new folder for your lab work and make subfolders for the original data, models and final products (three total). Transfer the data from the lab data folder to your original folder and extract the data.

  2. Start ENVI then start the ENVI Modeler using one of these options:

ENVI Modeler Interface

  1. In the modeler window, save your model as ‘subset’ in your folder titled Models. Be sure the save frequently as you work on your model.
  2. Double click (or drag into the model layout window) the Input Parameters under Basic nodes menu. This node will create a window that will pop-up when the model is launched that will allow the user to specify certain input files and parameters to use in the model. We will edit the parameters in a later step.Add Node

  3. Next we will add a Task to the model. Add the Create Subrects from Vector. A subrect is a bounding box (series of coordinates) used to spatially subset a raster. A subrect can be created from a vector or ROI file. In our case we will use a vector (shapefile) to create a subrect and then subset images.

  4. Add a connector and connect the Input Parameters node to the Create Subrects from Vector node. The Connect Parameters window should open automatically. Click the Add New Inputs button under the Input Parameters and then click Input Vector. This creates an input box that will ask the user to specify a vector file, the connection then feeds this specified vector into the task. Click OK.
    Connections
  5. Now add another task node, selecting Subset Raster. We need to make two connections to this node. For the task to work we will need to connect an input raster file and subrect coordinates from the create subrects from vector node.
  6. Connect the Create Subrect from Vector to the Subset Raster. In the Connect Parameters dialog connect the Subrect Array to the Subrect under Subset raster. The Subrect Array contains the coordinates extracted from the vector file which will be used to subset the selected raster.
    Connect  nodes
  7. You may want to adjust the location of your nodes so you can clearly see the all of the connections. Now add a connection between the Subset Raster and the Input Parameters. Click the Add New Inputs and connect it to the Input Raster under the Subset Raster. Before closing the window add another connection by clicking the Add New Inputs and connecting this to the Output Raster URI.  This will allow you to specify the name and location that the subset raster will be saved.
  8. Mulitiple Connections
  9. The last node we will add is a node to add the subsetted raster to the viewer. Under the Basic Nodes select View.  Connect the View to the Subset Raster.  This will add the subsetted raster to the view when the model is run.

  10. Click on the list icon Iconon the Input Parameters node. This shows all of the inputs and descriptions. You can update the descriptions as you see fit, for example you might update the description from Input Raster to Select raster to subset. The order of the parameters can be moved using the arrows to the right of the inputs.

  1. The last thing we will do before saving and running the model is to validate the model to check for errors or missing connections. In the ENVI Modeler window select Code >Validate Model. The validation report indicates that the model is missing a required parameter.  We need to specify the raster to use for the Create Subrects node. The subrects task needs both a vector and raster input.

  1. Double click or right click on the connection from the Input Parameter node to the Create Subrects. In the Edit Connection Parameters Window connect the Input Rasters (from the input parameters to the create subrect)
  1. Now run the model validation again. If there are no errors save the model. After saving click Run to start the model.

  2. The input parameters will pop up and you can now select the input raster and vector. Select the Fire shapefile as the vector and the 2021 Surface Reflectance data as the input raster. Keep the output as Virtual Raster, this won’t permanently save the raster but will open the image in the viewer, the image will be saved in ENVI’s temp folder.This is en excellent way to test a model. After running the model you should see the subsetted Landsat image appear in the viewer.

Adding a Spectral Index to the Model

Now we will update our model so in addition to subsetting the image, the model also calculates a spectral index.  In this case we will calculate the Normalized Burn Ratio using the NIR and SWIR2 bands. 

  1. First we will save a copy of our model, in the ENVI Modeler window select File >Save As and save the model as subset-nbr (or something similar). 

  2.  Now we will add a task to calculate the Normalized Burn Ratio. Add Spectral Index task to the model.

  3. Connect the output of the Subset Raster node to the input of the Spectral Index node. Double click on the connection, the output subsetted raster should automatically be connected to the Spectral Index node.

  4. Click the list icon Iconin the Spectral Index node to display the task parameter dialog. In the window select NBR as the index and press OK.

  1. We will add one more connection to the Spectral Index node, connect the Input Parameters to the Spectral Index node. In the Connect Parameters window click the Add New Inputs in the Input Parameters and connect it to the Output Raster URI.  This will allow the user to specify the file name/location of to save the NBR file created.

  1. The last thing is to add the files created to the view and data manager. Under Basic Nodes add View and Data Manager nodes. Create  a connection between the Spectral Index output node and the View node. This will add the output NBR raster to the view. Add a connection between the Spectral Index node and the Data Manager as well.

  1. Validate the model and save the model. If there are no errors in the model, run the model. Select the same files as before (step 16) and create virtual rasters rather than saving the files. If everything works you should see the subsetted raster and NBR file appear in the view.
  2. Check on  the statistics on the images, note that there are extremely high and low values that need to be addresses. For example all values less than  should be set to 0 and all values greater than 1 should be set to 1. We could build this into our existing model, but for this example we will learn how to create a batch processing model to apply our pre-processing steps.

Create a Custom Batch Processing Model 

Use an Iterator node to batch-process multiple datasets or, in general, to loop through a group of elements. The output of an Iterator node will be executed as many times as the number of elements passed in, iterating through each of them one-by-one. In this model we won’t use the Input Parameters, rather directly add the data.

  1. Save your existing model and create a new mode and save it as batch-process.

  2. In your new model add a Dataset node under Basic Nodes. This allows you to add data to model directly (rather than through an input dialog).  Select Raster as the type and add all three of the Surface reflectance datasets.

  3. Now add an Iterator node from the Basic Nodes list and connect it to the Rasters node. The connection should automatically connect the three rasters to the iterator.  Everything past the iterator node will be repeated on for all of the input rasters (as many as specified in the Raster input).

  4. Add a Create Subrect from Vector node and connect to the output of the Iterator. Click the button in the Create subrects and specify the vector file as the fire perimeter shapefile.

  5.  Add a Subset Raster and connect it to the outpost of the Subrects, connect the Subrect Array to the Subrect input in the Subset Raste node.

  6. Add another connection from the Iterator output to the Subset Raster and connect to the Iterator Raster outpost to the Input Raster.

  7. Add  High Clip and Low Clip taks nodes to the model. Connect the Low Clip node to the Subset Raster. Click the button in the Low Clip node. 
  8. In the Low Clip window you set the threshold for each band. The threshold need to set for each band (seven total for this data). Set the threshold to 0 for each band (see below).  This will set any pixels with negative values to 0.

  1.  Connect the High Clip to the output of the Low Clip node.  Set the threshold to 1 for all of the bands.

  1. Add View and Data Manager nodes and connect the output of the High Clip to these nodes. Check for errors by validating your model.

  2. Run the model but don’t save the files (they will be virtual rasters by default).  Check to make sure that all of the subset images look correct and don’t have data values less than 0 or greater than 1. Remove all of the files after checking.

  3. Add a Generate Filename node to the output of the Iterator node. Draw a connector between the two. In the Edit Connection Parameters dialog, connect the Iteration Index parameter of the Iterator node to the Number to Append parameter of the Generate Filename node. 

  1. Next connect the output of the Generate Filename node to the input of the High Clip node. The Output Filename parameter of Generate Filename connects to the Output Raster URI parameter of High Clip node.

  2. Click the button in the Generate Filename node, and set the Directory, Filename Prefix, and Extension parameters. In this example, the Append Random Number option is set to No. Set the directory to be your Finals folder.  The file name prefix should be Monument and specify the extension as a .dat.  The number to Append should be connected to the Iterator.  Each iteration will add one to the number at the end of the file name.

  1. Validate your model one more time and save the model. Run your model. When it is complete you should have three subsetted, processed rasters in your viewer and in your final folder.

  1. Now create or edit your model to create a batch process to calculate and save a normalized spectral index (can be NBR/NDVI/NDBI/SAVI) for each of the subsetted raster files.  You could create a separate model for the batch spectral index or append your existing model and add it to the batch workflow to create a single workflow that subsets the imagery and calculates the spectral index.  Save your model. When you are done you should have three spectral index files generated from the processed imagery.

Create a Model to Calculate a Difference Raster and Classify 

  1.  Create a new model and save it as raster-difference. 

  2. Add the Input Parameters node and Image Band Difference task and connect the two nodes. Click Add New Inputs and connect to the Input Raster 1 and click OK.

  3. Click on the connection again and Click Add New Inputs and connect to the Input Raster 2 and click OK. 

  4. We want to classify the results of the Band Difference task, in this case the classes will represent the magnitude of change between the time periods. Add the Color Slice Classification task node and connect it to the output of the Image Band Difference node.  This feeds the difference raster into the color slice classifier. Save your model.

  5.  We want to create a custom color slice range(s) to use in the model. We will do this in the main ENVI interface, minimize the model so you can see the Main ENVI window and files. From the toolbox select Raster Color Slice.

  6. When prompted for data selection, select one of the spectral index files. It doesn't matter which, this data is ‘dummy’ data to create the classes and ranges.

  7. ;In the Raster Color Slice window select New Default Color Slicesslice . If you are choosing the create a dNBR and burn severity classification use the below specific class values for the severity classes. If you are using another normalized index use the other generic classes (although you may choose to alter the classes as you see fit). Change the number of slice (classes) depending on your classification scheme (5-7 classes).

  8. Change the min and max values for the slices/classes based on the values in the table below. Change the colors for the classes as well.


Burn Severity Classes

Class

Min

Max

High Re-Growth

-2

-0.25

Low Re-Growth

-0.25

-0.1

Unburned

-0.1

0.1

Low Severity

0.1

0.27

Mod-Low Severity

0.27

0.44

Mod-High Severity

0.44

0.66

High

0.66

2

General Difference Classes

Class

Min

Max

High Increase

-2

-0.25

Mod-Low Increase

-0.25

-0.1

No Change

-0.1

0.1

Low Decrease

0.1

0.25

High Increase

0.25

2

 

 


  1. When you are done, Click the Save icon and select Save Color Slice to File. Save the file as in your Finals folder. The file type is .dsr and this file just saves the colors and value ranges for the slices/classes, not the actual image file. This allows you to import the file and use the same values ranges and colors with other data sets. After you have saved the dsr classification file you can hit cancel and close the tool as we don't need to apply the classification at this point.

  2. Go back to the ENVI Modeler window. Add the Get Color Slice Ranges from DSR task. Click the button  on the Get Color Slice node and select the DSR file you created in the previous step.

  3. Connect the  Get Color Slice Ranges from DSR node to the Color Slice Classification. Connect the Colors and Ranges and click OK.  Set the Color Slise DSR file location in the parameter window or create an input parameter for the user the specify the color slice file to use.

  1. Add the Mask Raster by Vector Task and connect the input  to Color Slice Classification output. The output raster from the color slice classification should automatically be connected to the Mask Raster by Vector.

  2. Add another connection from the Input Parameters to the input of the Mask Raster by Vector.  Click Add New Inputs and connect it to the Input Mask Vector.  This will allow the user to select the vector file to be used for masking. Click OK.

  3. Double click on the same connection again, this time clicking Add New Inputs and connecting it to the Output Raster URI and click OK.  This will create a prompt in the input dialog to save the file.

  1. Click the button in the Mask Raster by Vector. Set the Data Ignore value to -9999 and click OK.

  2. The final step is Add the View and Data Manager nodes and connect the output of the Mask Raster by Vector to these nodes.  This will add the masked, classified image to the viewer and data manager. Below is an example of the final model.

  1. Validate the model to check for errors, then save the model. Run the model. 

  2. Select the Pre and Post fire index (either the 1 year or 2 year) as the input raster (pre fire or intial condition should be raster 2 and post fire raster 1) and the Fire perimeter shapefile as the vector.  Save the file as a .dat in your finals folder and run the model!

  3. Create a map showing the results of the classification.  The map should include basic cartographic elements and a legend with the classes. Indicate whether the results are for one year or two year post-fire. 


Turn In

  1. Map showing the results of the difference classification (dNBR/dNDVI etc).  The map should include basic cartographic elements and a legend with the classes. Indicate whether the results are for one year or two years post-fire
  2. Model(s) that batch process the files to subsetted images and spectral indices (step 40).  Submit the .model files, this can be one model or two separate models.





Contact Info

Humboldt State University
1 Harpst Street Arcata, CA 95521
skh28@humboldt.edu

© Copyright 2020 HSU - All rights reserved.