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.
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)