-1

I am trying to find a way to read hyperion e-01 satellite data (hyperspectral data) which has .L1R file extension , in python. Kindly suggest any library to read this data in python.

KHIZER
  • 21
  • 4

1 Answers1

0

Here is a function to read the HDF data from the .L1R file and save it in ENVI format. If you simply want to read the data as a numpy array, modify it to return data and omit the rest of the function definition.

from pyhdf.SD import SD
import spectral as spy
import os

def hdf4_to_envi(hdf4_filename, envi_hdr=None, outdir=None, inhdr=None,
                 **kwargs):
    '''Converts an Hyperion HDF4 file to ENVI format.

    Arguments:

        `hdf4_filename` (str):

            Name of the HDF4 file (often ends with ".LR1"

        `envi_hdr` (str, default None):

            Name of the ENVI header file to create. A ".img" file will also
            be created. If not specified, the header will have the same name
            as the HDF file with '.hdr' appended.

        `outdir` (str, default None):

            Directory in which to create the new file. If not specifed, new
            file will be created in the same directory as the HDF4 file.

        `inhdr` (str, default None):

            Name of optional ENVI header file from which to extract additional
            metadata, which will be added to the new image header file.

    Keyword Arguments:

        All keyword arguments are passed to `spectral.envi.save_image`.
    '''
    (indir, infile) = os.path.split(hdf4_filename)
    if envi_hdr is None:
        header = infile + '.hdr'
    else:
        header = envi_hdr
    if outdir is None:
        outdir = indir
    fin = SD(hdf4_filename)
    ds = fin.select(0)
    data = ds.get()
    data = data.transpose(0, 2, 1)
    if inhdr is None:
        metadata = {}
    else:
        metadata = spy.envi.read_envi_header(inhdr)
    outfile = os.path.join(outdir, header)
    spy.envi.save_image(outfile, data, ext='.img', metadata=metadata)
bogatron
  • 18,639
  • 6
  • 53
  • 47
  • thanks, can you suggest how to read band wavelength information in python. – KHIZER Oct 04 '20 at 18:15
  • Wavelengths are in the .hdr file that accompanies the .L1R file. In the code provided in my answer, the wavelengths are in the "wavelengths" key of the `metadata` variable. Alternatively, if you use `spy.open_image` open the ENVI file produced by the function, then the wavelengths will be in the `bands.centers` attribute of the returned image object. – bogatron Oct 04 '20 at 22:19
  • Sorry, the metadata field is "wavelength", not "wavelengths". – bogatron Oct 04 '20 at 22:25