Example #1
0
    def pix():
        mask = image.select('pixel_qa')
        cloud_mask = tools.compute_bits(mask, 5, 5, 'cloud')
        shadow_mask = tools.compute_bits(mask, 3, 3, 'shadow')
        snow_mask = tools.compute_bits(mask, 4, 4, 'snow')

        good_pix = cloud_mask.eq(0).And(shadow_mask.eq(0)).And(snow_mask.eq(0))
        return good_pix
Example #2
0
    def sr():
        mask = image.select('sr_cloud_qa')
        cloud_mask = tools.compute_bits(mask, 1, 1, 'cloud')
        shadow_mask = tools.compute_bits(mask, 2, 2, 'shadow')
        adjacent_mask = tools.compute_bits(mask, 3, 3, 'adjacent')
        snow_mask = tools.compute_bits(mask, 4, 4, 'snow')

        good_pix = cloud_mask.eq(0).And(shadow_mask.eq(0)).And(
            snow_mask.eq(0)).And(adjacent_mask.eq(0))
        return good_pix
Example #3
0
def sentinel2(image):
    """ Function to use in SENTINEL2 Collection

    Use:

    `masked = collection.map(cloud_mask.sentinel2)`
    """
    nubes = image.select("QA60")
    opaque = tools.compute_bits(nubes, 10, 10, "opaque")
    cirrus = tools.compute_bits(nubes, 11, 11, "cirrus")
    mask = opaque.Or(cirrus)
    result = image.updateMask(mask.Not())
    return result
Example #4
0
def modis(img):
    """ Function to use in MODIS Collection

    Use:

    `masked = collection.map(cloud_mask.modis)`
    """
    cmask = img.select("state_1km")
    cloud = tools.compute_bits(cmask, 1, 1, "cloud")
    mix = tools.compute_bits(cmask, 0, 0, "mix")
    shadow = tools.compute_bits(cmask, 2, 2, "shadow")
    cloud2 = tools.compute_bits(cmask, 10, 10, "cloud2")
    snow = tools.compute_bits(cmask, 11, 11, "snow")

    mask = cloud.Or(mix).Or(shadow).Or(cloud2).Or(snow)

    return img.updateMask(mask.Not())
Example #5
0
def ledaps(image):
    """ Function to use in Surface Reflectance Collections computed by
    LEDAPS

    Use:

    `masked = collection.map(cloud_mask.ledaps)`
    """
    cmask = image.select('QA')

    valid_data_mask = tools.compute_bits(cmask, 1, 1, 'valid_data')
    cloud_mask = tools.compute_bits(cmask, 2, 2, 'cloud')
    snow_mask = tools.compute_bits(cmask, 4, 4, 'snow')

    good_pix = cloud_mask.eq(0).And(valid_data_mask.eq(0)).And(snow_mask.eq(0))
    result = image.updateMask(good_pix)

    return result
Example #6
0
    def wrap(img):
        # mask = img.select('pixel_qa')
        mask = img.select('BQA')
        cloud_mask = tools.compute_bits(mask, 4, 4, 'cloud')
        shadow_mask = tools.compute_bits(mask, 8, 8, 'shadow')
        snow_mask = tools.compute_bits(mask, 10, 10, 'snow')

        relation = ee.Dictionary({
            'cloud': cloud_mask,
            'shadow': shadow_mask,
            'snow': snow_mask
        })

        masks_list = tools.get_from_dict(options,
                                         relation)  # make a list of masks
        good_pix = apply_masks(masks_list)

        return img.updateMask(good_pix)
Example #7
0
    def for_iterate(option, ini):
        i = ee.Image(ini)  # cast ini

        # bits relation dict contains the option?
        cond = bits_dict.contains(option)

        # get the mask for the option
        mask = tools.compute_bits(bits_dict.get(option), bits_dict.get(option),
                                  option)(image)
        return ee.Image(ee.Algorithms.If(cond, i.Or(mask), i))
Example #8
0
def modis(img):
    """ Function to use in MODIS Collection

    Use:

    `masked = collection.map(cloud_mask.modis)`
    """
    cmask = img.select("state_1km")
    cloud = tools.compute_bits(cmask, 0, 0, "cloud")
    mix = tools.compute_bits(cmask, 1, 1, "mix")
    shadow = tools.compute_bits(cmask, 2, 2, "shadow")
    cloud2 = tools.compute_bits(cmask, 10, 10, "cloud2")
    snow = tools.compute_bits(cmask, 12, 12, "snow")

    mask = (
        cloud.Or(mix)
        # .Or(shadow)  # Cloud shadow seems to be miscomputed (MODIS/MYD09GA/MYD09GA_005_2015_09_18)
        .Or(cloud2).Or(snow))

    return img.updateMask(mask.Not())