ICESat2学习笔记9 :python读取ATL08数据

利用jupyter notebook编写python脚本,利用h5py包读取ATL08数据,将6个波束数据分别存储到6个h5文件和csv文件,可通过ArcGIS展点展示数据。

代码:

import icepyx as ipx
import numpy as np
import xarray as xr
import pandas as pd
import h5py
import os,json
from pprint import pprint
import dask.dataframe as dd

# put the full filepath to a data file here. You can get this in JupyterHub by navigating to the file,
# right clicking, and selecting copy path. Then you can paste the path in the quotes below.
fname = r'G:\2.Data\ATL08_20200806112404_06430806_003_01.h5'
def read_atl08(fname, bbox=None):
    """ 
    Read 1 ATL08 file and output 6 reduced files. 
    
    Extract variables of interest and separate the ATL08 file 
    into each beam (ground track) and ascending/descending orbits.
    """

    # Each beam is a group
    group = ['/gt1l', '/gt1r', '/gt2l', '/gt2r', '/gt3l', '/gt3r']

    # Loop trough beams
    for k,g in enumerate(group):
    
        #-----------------------------------#
        # 1) Read in data for a single beam #
        #-----------------------------------#
    
        # Load variables into memory (more can be added!)
        with h5py.File(fname, 'r') as fi:
            lat = fi[g+'/land_segments/latitude'][:]
            lon = fi[g+'/land_segments/longitude'][:]
            canopy_h_metrics = fi[g+'/land_segments/canopy/canopy_h_metrics'][:]
            canopy_openness = fi[g+'/land_segments/canopy/canopy_openness'][:]
            h_canopy_quad = fi[g+'/land_segments/canopy/h_canopy_quad'][:]


        #---------------------------------------------#
        # 2) Filter data according region and quality #
        #---------------------------------------------#
        
        # Select a region of interest
        if bbox:
            lonmin, lonmax, latmin, latmax = bbox
            bbox_mask = (lon >= lonmin) & (lon <= lonmax) & \
                        (lat >= latmin) & (lat <= latmax)
        else:
            bbox_mask = np.ones_like(lat, dtype=bool)  # get all
            

        # Test for no data
        if len(canopy_h_metrics) == 0: continue
        
        
        #-----------------------#
        # 4) Save selected data #
        #-----------------------#
        
        # Define output file name
        ofile = fname.replace('.h5', '_'+g[1:]+'.h5')
                
        # Save variables
        with h5py.File(ofile, 'w') as f:
            f['lon'] = lon
            f['lat'] = lat
            f['canopy_h_metrics'] = canopy_h_metrics
            f['canopy_openness'] = canopy_openness
            f['h_canopy_quad'] = h_canopy_quad
            print('out ->', ofile)
        # save as csv
        ofilecsv = fname.replace('.h5', '_'+g[1:]+'.csv')
        result = pd.DataFrame()
        result['lon'] = lon
        result['lat'] = lat
        result['canopy_h_metrics_0'] = canopy_h_metrics[:,0]
        result['canopy_h_metrics_1'] = canopy_h_metrics[:,1]
        result['canopy_h_metrics_2'] = canopy_h_metrics[:,2]
        result['canopy_h_metrics_3'] = canopy_h_metrics[:,3]
        result['canopy_h_metrics_4'] = canopy_h_metrics[:,4]
        result['canopy_h_metrics_5'] = canopy_h_metrics[:,5]
        result['canopy_h_metrics_6'] = canopy_h_metrics[:,6]
        result['canopy_h_metrics_7'] = canopy_h_metrics[:,7]
        result['canopy_h_metrics_8'] = canopy_h_metrics[:,8]
        result['canopy_openness'] = canopy_openness
        result['h_canopy_quad'] = h_canopy_quad
 
        print('out ->', ofilecsv)
        result.to_csv(ofilecsv,index=None)
            
read_atl08(fname, None)

运行结果:

ArcGIS展点:

  • 16
    点赞
  • 66
    收藏
    觉得还不错? 一键收藏
  • 41
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 41
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值