在 python 中读取 Hyperion Satellite E-01 数据集(.L1R 文件)
Reading Hyperion Satellite E-01 dataset (.L1R file) in python
我正在尝试找到一种方法来读取文件扩展名为 .L1R 的 hyperion e-01 卫星数据(高光谱数据),在 python 中。请建议任何图书馆在 python.
中阅读此数据
这是一个从.L1R文件中读取HDF数据并保存为ENVI格式的函数。如果您只是想将数据作为 numpy 数组读取,请将其修改为 return 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)
我正在尝试找到一种方法来读取文件扩展名为 .L1R 的 hyperion e-01 卫星数据(高光谱数据),在 python 中。请建议任何图书馆在 python.
中阅读此数据这是一个从.L1R文件中读取HDF数据并保存为ENVI格式的函数。如果您只是想将数据作为 numpy 数组读取,请将其修改为 return 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)