【发布时间】:2022-01-14 15:41:00
【问题描述】:
我是 AWS 服务的新手。 我一直使用下面的代码来计算位于目录中的图像的 NDVI。
path = r'images'
dirContents = os.listdir(path)
for file in dirContents:
if os.path.isdir(file):
subDir = os.listdir(file)
# Assuming only two files in each subdirectory, bands 4 and 8 here
if "B04" in subDir[0]:
band4 = rasterio.open(subDir[0])
band8 = rasterio.open(subDir[1])
else:
band4 = rasterio.open(subDir[1])
band8 = rasterio.open(subDir[0])
red = band4.read(1).astype('float32')
nir = band8.read(1).astype('float32')
#compute the ndvi
ndvi = (NIR.astype(float) - RED.astype(float)) / (NIR+RED)
profile = red.meta
profile.update(driver='GTiff')
profile.update(dtype=rasterio.float32)
with rasterio.open(outfile, 'w', **profile) as dst:
dst.write(ndvi.astype(rasterio.float32))
现在所有必要的图像都在 amazon S3 文件夹中。如何替换下面的行?
path = r'images' dirContents = os.listdir(path)
【问题讨论】:
标签: python amazon-web-services amazon-s3