def cfmask(mask, mask_values=(1,2,3,4,255), nodata=-9999):
'''
Returns a binary mask according to the CFMask algorithm results for the
image; mask has True for water, cloud, shadow, and snow (if any) and False
everywhere else. More information can be found:
https://landsat.usgs.gov/landsat-surface-reflectance-quality-assessment
Landsat 4-7 Pre-Collection pixel_qa values to be masked:
mask_values = (1, 2, 3, 4)
Landsat 4-7 Collection 1 pixel_qa values to be masked (for "Medium" confidence):
mask_values = (1, 68, 72, 80, 112, 132, 136, 144, 160, 176, 224)
Landsat 8 Collection 1 pixel_qa values to be masked (for "Medium" confidence):
mask_values = (1, 324, 328, 386, 388, 392, 400, 416, 432, 480, 832, 836, 840, 848, 864, 880, 900, 904, 912, 928, 944, 992, 1024)
Arguments:
mask A gdal.Dataset or a NumPy array
mask_path The path to an EOS HDF4 CFMask raster
mask_values The values in the mask that correspond to NoData pixels
nodata The NoData value; defaults to -9999.
'''
if not isinstance(mask, np.ndarray):
maskr = mask.ReadAsArray()
else:
maskr = mask.copy()
# Mask according to bit-packing described here:
# https://landsat.usgs.gov/landsat-surface-reflectance-quality-assessment
maskr = np.in1d(maskr.reshape((maskr.shape[0] * maskr.shape[1])), mask_values)\
.reshape((1, maskr.shape[0], maskr.shape[1])).astype(np.int0)
return maskr
评论列表
文章目录