Python で .L1R ファイル拡張子を持つハイペリオン e-01 衛星データ (ハイパースペクトル データ) を読み取る方法を見つけようとしています。Pythonでこのデータを読み取るライブラリを親切に提案してください。
1 に答える
0
.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)
于 2020-10-04T14:15:35.513 に答える