X
15764 Rate this article:
2.8

Batch Processing using an ENVITask

Anonym

Last week, Brian Griglak outlined how to subset an ENVIRaster for use with an ENVITask on IDL Data Point. This functionality is used frequently, but what if you need to go the other direction? What if you need to process multiple files in a single script?

By running a batch process in the ENVI API, you can run a single process (or a chain of processes for that matter) on a list of files, and output the results to a location of your choosing.

An ENVI batch script using ENVITasks must contain 5 elements to run properly:

  • Start the ENVI application, preferably in HEADLESS mode since the UI is not needed.
  • Initialize the ENVITask and set constant parameters.
  • Generate a list of input files to do processing on.
  • Create an output filename - one for each input file.
  • Run the processing over each file in a loop with the parameters of your choice.

 

A lot of the work in creating a batch script does not stem from doing processing, but rather from managing input and output files. The code below outlines how this minimum framework can be setup using the RadiometricCalibration task.

 

pro batch_radiometric_calib

 compile_opt idl2

 

 ;Start ENVI in headless mode

 e = envi(/headless)

 

 ;Instantiate the ENVITask, set constant parameters.

 task = ENVITask('Radiometric')

 task.CALIBRATION_TYPE = 1

 

 ;Find all the files with .dat extensions in a directory.

 search_dir = 'Directory of files to calibrate'

 filelist = file_search(search_dir + '*.dat')

 ;Set a base for your output files that will be appended to.

 outbase = 'C:\Scratch\Reflectance_Cal_'

 

 ;Loop over every file.

 ;Open the raster, set parameters, and execute the task.

 foreach file, filelist, index do begin

   raster = e.OpenRaster(file)

   task.input_raster = raster

   task.output_raster_uri = outbase + strtrim(index, 2)

   task.Execute

 endforeach

end

 

One cool thing about using an ENVITask for batch processing is that each time through the loop, you only have to change the parameters that... well.. change!

 

In the example above, the CALIBRATION_TYPE is set to 1 (to calibrate to top of atmosphere reflectance) outside the loop so it is only set one time. The input_raster and output_raster are set inside the loop - they will change for each file.

At the end of the loop, with the new parameters in place, task.Execute is called. This kicks off processing of the ENVITask with the current parameters, but leaves the task unchanged for subsequent use.

 

To access the current list of ENVITasks:

IDL> e=envi()

ENVI> e.TASK_NAMES

 

For help on functions used in the example:

STRTRIM, FILE_SEARCH, OPENRASTER, COMPILE_OPT
 

 

Happy batching!