Skip to content

Instantly share code, notes, and snippets.

@jscarto
Created January 24, 2020 18:08
Show Gist options
  • Save jscarto/fe2aedc48ef6499dcbcb3fc9af09d527 to your computer and use it in GitHub Desktop.
Save jscarto/fe2aedc48ef6499dcbcb3fc9af09d527 to your computer and use it in GitHub Desktop.
Example: Reading GEDI Level 2A data in Python
import h5py
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# read file
file = 'GEDI02_A_2019138044926_O02428_T03843_02_001_01.h5'
f = h5py.File(file, 'r')
# get some variables for BEAM0000 (change to other beam/vars as needed)
elev = f['BEAM0000']['elev_highestreturn'][:]
lat = f['BEAM0000']['lat_highestreturn'][:]
lon = f['BEAM0000']['lon_highestreturn'][:]
# subset transect to specific range of lats
idx = np.where((lat >= 0.0) & (lat <= 21.0))
elev = elev[idx[0][0]:idx[0][-1]]
lat = lat[idx[0][0]:idx[0][-1]]
lon = lon[idx[0][0]:idx[0][-1]]
# create a basic plot
plt.plot(lon, elev)
plt.show()
# create a data frame, write it to CSV for mapping in QGIS
df = pd.DataFrame({
'lat': lat,
'lon': lon,
'elev': elev
})
df.to_csv('gedi_out.csv', index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment