You are on page 1of 5

Metadata Tutorial

The term metadata generally refers to information that describes the contents of a data file. In the context of ENVI programming, it refers to the following:

User-defined metadata that provides extra information about a raster file. An example would be a new "Vendor" field that lists the data provider for the image. User-defined metadata are listed under the "Supplementary Metadata" category in ENVI's Metadata Viewer. Standard fields (or tags) that provide additional information about an image (raster) file such as band names, percentage of cloud cover, and center wavelengths in each band. See the "ENVIRasterMetadata" topic in ENVI Help for a list of standard metadata fields. Standard fields are also listed in the Metadata Viewer.

Standard and user-defined metadata are contained in a metadata object associated with a given raster object. Other characteristics of a raster file that are required for ENVI to open the file are stored as properties of the raster object, rather than metadata. Examples include data type, number of bands, and acquisition time. See the "ENVIRaster" topic in ENVI Help for a list of these properties.

Example 1:User-Defined Metadata

This example demonstrates some basic concepts of working with metadata in the ENVI application programming interface(API). You will create an empty metadata object and populate it with user-defined metadata tags. You will then override the metadata of a raster file with the new metadata object and save the raster and metadata to a new file on disk. This is an interactive example that involves editing metadata, so you should run each command individually at the IDL command line. 1. Start the ENVI application without displaying the user interface. e = ENVI(/HEADLESS) 2. Use ENVI::CreateRasterMetadata to create a new metadata object. UserMetadata = e.CreateRasterMetadata() 3. Populate the metadata object with new fields, where the first item is the tag and the second item is the value for the tag. UserMetadata.AddItem, 'wavelength units', 'micrometers'

Page 1 of 5 Metadata Tutorial 2012 Exelis Visual Information Solutions, Inc. All Rights Reserved.

UserMetadata.AddItem, UserMetadata.AddItem, UserMetadata.AddItem, UserMetadata.AddItem,

'wavelength', [0.660, 0.560, 0.485] 'production date', '2012-10-24' 'location', 'Boulder, Colorado, U.S.A.' 'vendor', 'Acme, Inc.'

4. Update one of the metadata tags. UserMetadata.UpdateItem, 'production date', '2012-10-23' 5. Delete one of the metadata tags. UserMetadata.RemoveItem, 'vendor' 6. Print the contents of the metadata object to verify that the tags are correct. The results are displayed in the IDL Console. PRINT, UserMetadata 7. Open the file qb_boulder_msi (included in the ENVI installation path) and override its metadata with your new metadata object. The metadata for this raster will consist of the new metadata object plus any existing metadata within the raster. file = FILEPATH('qb_boulder_msi', ROOT_DIR = e.ROOT_DIR, $ SUBDIRECTORY = ['data']) raster = e.OpenRaster(file, METADATA_OVERRIDE = UserMetadata) 8. The raster object now contains a METADATAproperty. Print this property to see the metadata tags. metadata = raster.METADATA PRINT, metadata.TAGS Notice how the metadata consists of tags from your metadata object plus others that were already part of the raster object (such as DESCRIPTION, SENSOR TYPE, and BAND NAMES). 9. Retrieve a specific value for one of the metadata tags (production date) and store it as a variable. Then print the variable. Sensor = metadata['sensor type'] PRINT, Sensor 10. Save the raster file to disk as an ENVI-format file. The file is saved in the output directory specified in the ENVI preferences. enviOutDir = e.GetPreference('output_directory') outFile = enviOutDir+File_Basename(file)+'_metadata.dat' e.ExportRaster, raster, outFile, 'envi' 11. Close the ENVI session. e.Close

Page 2 of 5 Metadata Tutorial 2012 Exelis Visual Information Solutions, Inc. All Rights Reserved.

12. Open ENVI with the user interface. e = ENVI() 13. Open the new output raster file. raster = e.OpenRaster(outFile) 14. Get the active view. view = GetView() 15. Load the raster as a new layer. layer = view.CreateLayer(raster)

Example 2:Use Standard Metadata Tags to Calibrate Landsat Data

This example queries a Landsat metadata file for gain and bias factors. It uses these factors to compute at-sensor spectral radiance using the following equation from Chander, Markham, and Helder (2009): L =G





l l l l

L = Spectral radiance in units of [W/(m2 * sr * m)]

rescale cal

= Rescaling gain factor for each band.


= Quantized calibrated pixel value = Rescaling bias factor for each band.


Reference: Chander, G., B. Markham, and D. Helder, "Summary of current radiometric calibration coefficients for Landsat MSS, TM, ETM+, and EO-1 ALI sensors," Remote Sensing of the Environment 113 (2009): 893-903. Note: This is a simple example of using the ENVI application programming interface (API) to query raster metadata to compute radiance for one sensor. Use ENVI's Radiometric Calibration tool to calibrate data from various sensors to spectral radiance, top-of-atmosphere reflectance, or brightness temperatures. 1. Copy and paste the code below into a new file and save it as landsat_ in your IDL workspace directory. 2. Compile and run the program.

Page 3 of 5 Metadata Tutorial 2012 Exelis Visual Information Solutions, Inc. All Rights Reserved.

3. When prompted, select a Landsat TM or ETM+ metadata file (_MTL.txt). This example will not work with other Landsat metadata formats. The original Landsat image displays on the left, and the calibrated image displays on the right. You can use the Cursor Value or Spectral Profile tools to verify the data values from both images. PRO LandsatCalibrate ; Open the application e = ENVI() ; Select an input file file = DIALOG_PICKFILE(TITLE = 'Select a Landsat _MTL.txt metadata file') ; Create a raster object raster = e.OpenRaster(file) ; Landsat data are stored in a three-element array, where the first ; element contains multispectral data, the second element contains ; thermal data, and the third element contains panchromatic data. ; You only need the multispectral data to compute spectral radiance. MSIRaster = raster[0] NumBands = MSIRaster.NBANDS ; Retrieve all data from the input raster data = DOUBLE(MSIRaster.GetData()) ; Create a metadata object MetResult = MSIRaster.metadata ; Query the metadata for gain values. ENVI reads the gain factors ; for each band from the RADIANCE_MULT_BAND_x field of the ; Landsat metadata file and stores them in a 'data gain values' ; metadata tag. gain = MetResult['data gain values'] PRINT, 'Gain factors: ',gain

Page 4 of 5 Metadata Tutorial 2012 Exelis Visual Information Solutions, Inc. All Rights Reserved.

; Query the metadata for bias values. ENVI reads the bias factors ; for each band from the RADIANCE_ADD_BAND_x field of the ; Landsat metadata file and stores them in a 'data offset values' ; metadata tag. bias = MetResult['data offset values'] PRINT, 'Bias factors: ',bias ; compute spectral radiance. FOR i=0, NumBands-1 DO BEGIN data(*,*,i) = data(*,*,i) * gain[i] + bias[i] ENDFOR ; Create an output raster with a double-precision data type. ; Save it to the system's temporary directory. newFile = e.GetTemporaryFilename() newRaster = e.CreateRaster(newFile, data, DATA_TYPE = 5, INHERITS_FROM = MSIRaster) newRaster.SetData, data newRaster.Save ; Display the original raster in the first view view1 = e.GetView() layer1 = view1.CreateLayer(MSIRaster) ; Display the radiance raster in the second view view2 = e.CreateView() layer2 = view2.CreateLayer(newRaster) ; Link the views by pixel coordinates view1.PixelLink, /LINK_ALL, /ZOOM_LINK view1.Zoom, /FULL_EXTENT END

Page 5 of 5 Metadata Tutorial 2012 Exelis Visual Information Solutions, Inc. All Rights Reserved.