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])]