HLS: HDF to ENVI

This page describes how to convert HLS data from the HDF-formatted files downloadable here (https://hls.gsfc.nasa.gov/) to ENVI-formatted files.


  1. At the command line, make sure gdal and hdf4 packages are installed

  2. Navigate to the directory where the HLS files are located

  3. For L30 (Landsat) HLS images, run the following line of code:

for i in *L30*.hdf; do gdal_merge.py -o ${i%??????}_e -of ENVI -ot Int16 -n 0 -separate HDF4_EOS:EOS_GRID:"${i}":Grid:band01 HDF4_EOS:EOS_GRID:"${i}":Grid:band02 HDF4_EOS:EOS_GRID:"${i}":Grid:band03 HDF4_EOS:EOS_GRID:"${i}":Grid:band04 HDF4_EOS:EOS_GRID:"${i}":Grid:band05 HDF4_EOS:EOS_GRID:"${i}":Grid:band06 HDF4_EOS:EOS_GRID:"${i}":Grid:band07 ; done


for i in *L30*.hdr; do do mv -v ${i} ${i%????}.v1_e.hdr; done


for i in *L30*/*_e.hdr; do echo 'wavelength units = Micrometers' >> ${i}; done


for i in *L30*/*_e.hdr; do echo 'wavelength = {0.44, 0.48, 0.56, 0.665, 0.83, 1.6, 2.2}' >> ${i}; done


  1. For S30 (Landsat) HLS images, run the following lines of code:

for i in *S30*.hdf; do gdal_merge.py -o ${i%??????}_e -of ENVI -ot Int16 -n 0 -separate HDF4_EOS:EOS_GRID:"${i}":Grid:B01 HDF4_EOS:EOS_GRID:"${i}":Grid:B02 HDF4_EOS:EOS_GRID:"${i}":Grid:B03 HDF4_EOS:EOS_GRID:"${i}":Grid:B04 HDF4_EOS:EOS_GRID:"${i}":Grid:B05 HDF4_EOS:EOS_GRID:"${i}":Grid:B06 HDF4_EOS:EOS_GRID:"${i}":Grid:B07 HDF4_EOS:EOS_GRID:"${i}":Grid:B08 HDF4_EOS:EOS_GRID:"${i}":Grid:B8A HDF4_EOS:EOS_GRID:"${i}":Grid:B11 HDF4_EOS:EOS_GRID:"${i}":Grid:B12 ; done

for i in *S30*.hdr; do do mv -v ${i} ${i%????}.v1_e.hdr; done

for i in *S30*_e.hdr; do echo 'wavelength units = Micrometers' >> ${i}; done

for i in *S30*_e.hdr; do echo 'wavelength = {0.443, 0.490, 0.560, 0.665, 0.705, 0.740, 0.783, 0.842, 0.865, 1.610, 2.190}' >> ${i}; done

  1. [Optional] Compute spatial subset using the following line of code:

for i in *_e; do gdal_translate -of ENVI -projwin 766080 3851220 775800 3838680 ${i} ${i}_sub; done

    1. Here, the first two numbers are the x and y coordinates of the upper left pixel, and the last two numbers and the x and y coordinates of the lower right pixel. Example here shown for a box bounding Sedgwick Reserve.

  1. The files are now in ENVI format.


  1. [If the code is not working, you can also manually extract header information in ENVI, then copy to the rest of the files]. You can do this for a single file by:

    1. Open ENVI Classic

    2. Open any HDF file (File > Open Image File > Select HDF File)

    3. Select any band

    4. Now open any output file from the code above (File > Open Image File > Select HDF File)

    5. Header information will be requested.

      1. Go to Input Header Info From > Other File > Select the HDF Band you just opened > OK

      2. Change the number of bands from 1 to either 7 (L30) or 11 (S30)

      3. Change "filetype" to "ENVI Standard"

      4. Select OK


  1. Now copy this to all the other HLS files using the following commands, where xxx.hdr and yyy.hdr are the header files you just created for the single L30 and S30 files in the previous step:

for i in *L30*_e; do cp -v xxx.hdr ${i}.hdr; done

for i in *S30*_e; do cp -v yyy.hdr ${i}.hdr; done


  1. You are now done.