GEDI学习笔记 二:通过Subsetter.py代码对GEDI L1 L2级别光斑数据进行处理:属性筛选、区域裁剪和矢量格式转换(最后附上代码链接)

1. 在Pycharm中打开GEDI_Subsetter.py,修改环境为Subsetter(建议重新建一个环境,根据提示安装所需要的python库,安装顺序不要出错,不然会出现版本不匹配问题)

在这里插入图片描述

2. 在GEDI_Subsetter.py代码中修改相关参数

2.1 代码中已经默认添加了比较重要的属性,可根据实际需求进行相关修改

在这里插入图片描述

2.2 代码运行需要添加一个输入路径,一个裁剪范围(经纬度)

在这里插入图片描述

2.3 参数设置完成之后,运行,会在当前文件夹路径下生成一个output文件夹

在这里插入图片描述

2.4文件输出格式可以选择: .geojson、.shp格式

在这里插入图片描述
在这里插入图片描述

3. 代码链接

3.1 Subsetter官方代码链接如下:

https://git.earthdata.nasa.gov/projects/LPDUR/repos/gedi-subsetter/browse

3.2 修改后的代码如下

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
---------------------------------------------------------------------------------------------------
GEDI Spatial and Band/Layer Subsetting and Export to GeoJSON Script
Author: Cole Krehbiel
Last Updated: 04/13/2021
See README for additional information:
https://git.earthdata.nasa.gov/projects/LPDUR/repos/gedi-subsetter/browse/
---------------------------------------------------------------------------------------------------
"""
# Import necessary libraries
import os
import h5py
import pandas as pd
from shapely.geometry import Polygon
import geopandas as gp
import argparse
import sys
import numpy as np
import warnings
warnings.filterwarnings("ignore")

# --------------------------COMMAND LINE ARGUMENTS AND ERROR HANDLING---------------------------- #
# Set up argument and error handling
parser = argparse.ArgumentParser(description='Performs Spatial/Band Subsetting and Conversion to GeoJSON for GEDI L1-L2 files')
parser.add_argument('--dir', required=True, help='Local directory containing GEDI files to be processed')
parser.add_argument('--beams', required=False, help='Specific beams to be included in the output GeoJSON (default is all beams) \
                    BEAM0000,BEAM0001,BEAM0010,BEAM0011 are Coverage Beams. BEAM0101,BEAM0110,BEAM1000,BEAM1011 are Full Power Beams.')
parser.add_argument('--sds', required=False, help='Specific science datasets (SDS) to include in the output GeoJSON \
                    (see README for a list of available SDS and a list of default SDS returned for each product).')
parser.add_argument('--roi', required=True, help='Region of interest (ROI) to subset the GEDI orbit to in the output GeoJSON. \
                    Valid inputs are a geojson or .shp file or bounding box coordinates: ul_lat,ul_lon,lr_lat,lr_lon')
args = parser.parse_args()

# --------------------------------SET ARGUMENTS TO VARIABLES------------------------------------- #
# Options include a GeoJSON or a list of bbox coordinates
ROI = args.roi  

# Convert to Shapely polygon for geojson, .shp or bbox
if ROI.endswith('json') or ROI.endswith('.shp'):
    try:
        ROI = gp.GeoDataFrame.from_file(ROI)
        ROI.crs = 'EPSG:4326'
        if len(ROI) > 1:
            print('Multi-feature polygon detected. Only the first feature will be used to subset the GEDI data.')
        ROI = ROI.geometry[0]
    except:
        print('error: unable to read input geojson file or the file was not found')
        sys.exit(2)
else:
    ROI = ROI.replace("'", "")
    ROI = ROI.split(',')
    ROI = [float(r) for r in ROI]
    try:
        ROI = Polygon([(ROI[1], ROI[0]), (ROI[3], ROI[0]), (ROI[3], ROI[2]), (ROI[1], ROI[2])]) 
    excep
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值