我有一个来自Landsat 5,Landsat 7和Landsat 8的解压缩文件的文件夹。我想导入红色和NIR波段来运行NDVI。但是,这意味着我需要为Landsat 8带来4和5频段,为Landsat 5和7带来3和4频段。我很难编写代码来导入这些频段。我对python是全新的,所以这可能会有所不同,但这就是我所拥有的:
import os
import arcpy
import re
from arcpy import env
from arcpy.sa import *
mydir = r"E:\Thesis\005005-006004\005005\US_Landsat_4-8_ARD"
rasters = r"E:\Thesis\Processing\005005"
P_2Band = []
for root,dirs,files in os.walk(mydir):
for name in files:
if name.startswith("LC08")
if name.endswith("4.tif") or if name.endswith("5.tif"):
mypath = root+"\\"+name
P_2Band.append(mypath)
print(name)
elif name.startswith("LE07") or if name.startswith("LT05")
if name.endswith("3.tif" or "4.tif"):
mypath = root+"\\"+name
P_Metadata.append(mypath)
print(name)
感谢您的帮助!