在python中读取Hyperion Satellite E-01数据集.L1R文件

问题描述

我正在尝试找到一种方法来读取扩展名为.L1R的hyperion e-01高光谱数据,请在python中,建议使用任何方法

解决方法

这是从.L1R文件中读取HDF数据并将其保存为ENVI格式的功能。如果您只是想将数据读取为numpy数组,请对其进行修改以返回data并忽略其余的函数定义。

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)