我目前想用像素 QA 波段掩盖堆叠的 Landsat 8 GeoTIFF 文件,以去除云层和云层阴影。到目前为止,我已经成功地遵循了这里的教程,并使用 EarthPy 和 Rasterio 的组合正确绘制了蒙版场景。生成的蒙版场景是一个 NumPy 蒙版数组。
但是,当我尝试将干净数组导出为 GeoTIFF 文件 (clean.tif) 时,生成的文件包含原始场景而不是蒙版场景文件。以下是我拥有的代码:
from rasterio.plot import plotting_extent
import rasterio as rio
import earthpy.plot as ep
import earthpy.mask as em
# Open mask file
with rio.open("mask.tif") as mask_src:
mask = mask_src.read()
mask_meta = mask_src.profile
# Open scene file
with rio.open("scene.tif") as scene_src:
scene = scene_src.read()
scene_ext = plotting_extent(scene_src)
scene_trf = scene_src.transform
scene_meta = scene_src.profile
# Perform masking
clean = em.mask_pixels(scene, mask)
# Print metadata for mask and scene files
print("masked scene shape => " + str(clean.shape))
print("mask meta => " + str(mask_meta))
print("scene meta => " + str(scene_meta))
# Open and write destination tif file
with rio.open("clean.tif", 'w', **scene_meta) as clean_dst:
clean_dst.write(clean)
# Open destination tif file
with rio.open("clean.tif") as final_dst:
final = final_dst.read()
final_ext = plotting_extent(scene_src)
# Plot mask file
ep.plot_bands(mask)
# Plot scene file
ep.plot_rgb(scene, rgb=[4, 3, 2], extent=scene_ext, stretch=True)
# Plot masked scene
ep.plot_rgb(clean, rgb=[4, 3, 2], extent=scene_ext)
# Plot destination tif file
ep.plot_rgb(final, rgb=[4, 3, 2], extent=final_ext, stretch=True)
这里是文件的情节:
这是文件和脚本的 Dropbox 链接。对此我真的摸不着头脑,我很感激关于发生了什么以及如何解决它的任何指示。谢谢你们:)