def apply_mask_cloud(image_coll, collection_name, cloudy_pix_flag):
    """
    Different input_collections need different steps to be taken to handle
    cloudy image. The first step is to reject images that more than X%
    cloudy pixels (here X=5). The next step is to mask cloudy pixels. This
    will hopefully mean that when we take the median of the ImageCollection,
    we ignore cloudy pixels.

    Parameters
    ----------
    image_coll : ee.ImageCollection
        The ImageCollection of images from which we want to remove cloud.
    collection_name : str
        Name of the collection so that we can apply collection specific
        masking.
    cloud_pix_flag : str
        Name of the flag which details the fraction of cloudy pixels in each
        image.

    Returns
    ----------
    image_coll
        Image collection with very cloudy images removed, and masked images
        containing a tolerable amount of cloud.
    """

    # construct cloud mask if availible
    if collection_name == 'COPERNICUS/S2':
        mask_func = cloud_mask.sentinel2()
    elif collection_name == 'LANDSAT/LC08/C01/T1_SR':
        mask_func = cloud_mask.landsat8SRPixelQA()
    elif (collection_name == 'LANDSAT/LE07/C01/T1_SR'
          or collection_name == 'LANDSAT/LT05/C01/T1_SR'
          or collection_name == 'LANDSAT/LT04/C01/T1_SR'):
        mask_func = cloud_mask.landsat457SRPixelQA()
    else:
        print("No cloud mask logic defined for input collection {}"\
              .format(collection_name))
        return image_coll

    # images with more than this percent of cloud pixels are removed
    cloud_pix_frac = 50

    # remove images that have more than `cloud_pix_frac`% cloudy pixels
    if cloudy_pix_flag != 'None':
        image_coll = image_coll.filter(
            ee.Filter.lt(cloudy_pix_flag, cloud_pix_frac))

    # apply per pixel cloud mask
    image_coll = image_coll.map(mask_func)

    return image_coll
Ejemplo n.º 2
0
def test_snow():
    masked = cloud_mask.landsat8SRPixelQA(['snow'])(image)
    vals = getValue(masked, p_snow, 30)

    assert vals.get("B1").getInfo() == None