GEDI学习1:H5文件所需各参数及波形的提取

目录

<1> 提取一个波束的信息

1.导入所需要的包

2.打开H5文件,读取数据

 3.设置提取参数

4.提取参数至列表

5.预览效果

<2> 提取一个光斑点的信息

1.数据读取

2.指定数据

3.设置提取参数

4.获取完整的波形和高程

5.匹配数值,进行输出

 6.预览效果


<1> 提取一个波束的信息

(以GEDI01_B_2019170155833_O02932_02_T02267_02_005_01_V002.h5文件中BEAM0110为例)

1.导入所需要的包

import h5py
import pandas as pd
from shapely.geometry import Point
import geopandas as gp
import numpy as np

2.打开H5文件,读取数据

  打开GEDI HDF5文件,并读取所需要的数据

L1B = 'GEDI01_B_2019170155833_O02932_02_T02267_02_005_01_V002.h5'  # 可以换成自己的h5文件
gediL1B = h5py.File(L1B, 'r')  
beamNames = ['BEAM0110']  # 以BEAM0110波束为例
gediL1B_objs = []
gediL1B.visit(gediL1B_objs.append)  
gediSDS = [o for o in gediL1B_objs if isinstance(gediL1B[o], h5py.Dataset)]  
lonSample, latSample, shotSample, srfSample, degradeSample, beamSample, meanSample  = [], [], [], [], [], [], []  # 设置列表以存储想要的数据

 3.设置提取参数

按照xx = gediL1B[f'{beamNames[0]}/xx位置'][()]的格式进行修改,可提取自己想要的参数,记得再第2步的时候在存储列表中同时添加

lats = gediL1B[f'{beamNames[0]}/geolocation/latitude_bin0'][()]
lons = gediL1B[f'{beamNames[0]}/geolocation/longitude_bin0'][()]
shots = gediL1B[f'{beamNames[0]}/shot_number'][()]
srf = gediL1B[f'{beamNames[0]}/stale_return_flag'][()]
degrade = gediL1B[f'{beamNames[0]}/geolocation/degrade'][()]
noise_mean_corrected = gediL1B[f'{beamNames[0]}/noise_mean_corrected'][()]

4.提取参数至列表

按照xxSample.append(xx(第3步)[i])的格式进行修改,读取数据并添加到列表中

# 每隔100个shot读取一次数据并添加到列表中
for i in range(len(shots)):
    if i % 100 == 0:
        shotSample.append(str(shots[i]))
        lonSample.append(lons[i])
        latSample.append(lats[i])
        srfSample.append(srf[i])
        degradeSample.append(degrade[i])
        beamSample.append(beamNames[0])
        meanSample.append(noise_mean_corrected[i])

latslons = pd.DataFrame({'Beam': beamSample, 'Shot Number': shotSample, 'Longitude': lonSample, 'Latitude': latSample,
                         'Stale Return Flag': srfSample, 'Degrade': degradeSample, 'noise_mean': meanSample})

5.预览效果

latslons

 运行结果如下图:

 

<2> 提取一个光斑点的信息

(以GEDI01_B_2019170155833_O02932_02_T02267_02_005_01_V002.h5文件中BEAM0110中shotnumber为shot = 29320600200465601的光斑点为例)

1.数据读取

import h5py
import pandas as pd
from shapely.geometry import Point
import geopandas as gp
import numpy as np

L1B = 'GEDI01_B_2019170155833_O02932_02_T02267_02_005_01_V002.h5'  
gediL1B = h5py.File(L1B, 'r')  
beamNames = ['BEAM0110']  
gediL1B_objs = []
gediL1B.visit(gediL1B_objs.append) 
gediSDS = [o for o in gediL1B_objs if isinstance(gediL1B[o], h5py.Dataset)] 

2.指定数据

# 获取特定shot的数据
shot = 29320600200465601
index = np.where(gediL1B[f'{beamNames[0]}/shot_number'][()]==shot)[0][0]  # Set the index for the shot identified above

3.设置提取参数

从SDS列表中找到想要提取的参数,以下面两种格式进行输入 

sdsCount = gediL1B[[g for g in gediSDS if g.endswith('/rx_sample_count') and beamNames[0] in g][0]]
sdsStart = gediL1B[[g for g in gediSDS if g.endswith('/rx_sample_start_index') and beamNames[0] in g][0]]
sdsWaveform = [g for g in gediSDS if g.endswith('/rxwaveform') and beamNames[0] in g][0]
wfCount = sdsCount[index]  
wfStart = int(sdsStart[index] - 1)  
wfShot = gediL1B[f'{beamNames[0]}/shot_number'][index]
wfLat = gediL1B[f'{beamNames[0]}/geolocation/latitude_bin0'][index]
wfLon = gediL1B[f'{beamNames[0]}/geolocation/longitude_bin0'][index]


print(f"The waveform located at: {str(wfLat)}, {str(wfLon)} (shot ID: {wfShot}, index {index}) is from beam {beamNames[0]} \
      and is stored in rxwaveform beginning at index {wfStart} and ending at index {wfStart + wfCount} ")
wfxx = gediL1B[f'{位置'][index]
sdsxx = gediL1B[[g for g in gediSDS if g.endswith('/xx名称') and beamNames[0] in g][0]]

4.获取完整的波形和高程

zStart = gediL1B[f'{beamNames[0]}/geolocation/elevation_bin0'][index]  
zEnd = gediL1B[f'{beamNames[0]}/geolocation/elevation_lastbin'][index]  
print("{:,}".format(gediL1B[sdsWaveform].shape[0]))

waveform = gediL1B[sdsWaveform][wfStart: wfStart + wfCount]
zStretch = np.add(zEnd, np.multiply(range(wfCount, 0, -1), ((zStart - zEnd) / int(wfCount))))

5.匹配数值,进行输出

wvDF = pd.DataFrame({'Amplitude (DN)': waveform, 'Elevation (m)': zStretch})
outName = gediL1B.filename.replace('.h5', '.csv')  # 使用输入文件名创建输出文件名
wvDF.to_csv(outName, index=False)

 6.预览效果

wvDF

 

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值