def create_mask_from_bitmask(geoimg, filename=''):
""" Mask geoimg with a series of provided bitmasks """
# medium and high confidence clouds
nodata = int('0000000000000001', 2)
clouds = int('1000000000000000', 2)
cirrus = int('0011000000000000', 2)
# calculate mask
arr = geoimg.read().astype('int16')
# it is a good data mask
mask = (np.bitwise_and(arr, nodata) != nodata) & \
(np.bitwise_and(arr, clouds) < clouds) & \
(np.bitwise_and(arr, cirrus) < cirrus)
# create mask file
logger.info('Saving to file %s' % filename, action='Save file', actee=filename, actor=__name__)
maskimg = GeoImage.create_from(geoimg, filename=filename, dtype='uint8')
maskimg.set_nodata(0)
maskimg[0].write(mask.astype('uint8'))
return maskimg
评论列表
文章目录