mask.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:beachfront-py 作者: venicegeo 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号