(im_QA, satname, cloud_mask_issue)
return cloud_mask
Creates a cloud mask using the information contained in the QA band.

    KV WRL 2018

    Arguments:
    -----------
    im_QA: np.array
        Image containing the QA band
    satname: string
        short name for the satellite: ```'L5', 'L7', 'L8' or 'S2'```
    cloud_mask_issue: boolean
        True if there is an issue with the cloud mask and sand pixels are being
        erroneously masked on the images

    Returns:
    -----------
    cloud_mask : np.array
        boolean array with True if a pixel is cloudy and False otherwise
Creates a cloud mask using the information contained in the QA band.
Creates a cloud mask using the information contained in the QA band .
def create_cloud_mask(im_QA, satname, cloud_mask_issue):
    """
    Creates a cloud mask using the information contained in the QA band.

    KV WRL 2018

    Arguments:
    -----------
    im_QA: np.array
        Image containing the QA band
    satname: string
        short name for the satellite: ```'L5', 'L7', 'L8' or 'S2'```
    cloud_mask_issue: boolean
        True if there is an issue with the cloud mask and sand pixels are being
        erroneously masked on the images

    Returns:
    -----------
    cloud_mask : np.array
        boolean array with True if a pixel is cloudy and False otherwise
        
    """

    # convert QA bits (the bits allocated to cloud cover vary depending on the satellite mission)
    if satname == 'L8':
        cloud_values = [2800, 2804, 2808, 2812, 6896, 6900, 6904, 6908]
    elif satname == 'L7' or satname == 'L5' or satname == 'L4':
        cloud_values = [752, 756, 760, 764]
    elif satname == 'S2':
        cloud_values = [1024, 2048] # 1024 = dense cloud, 2048 = cirrus clouds

    # find which pixels have bits corresponding to cloud values
    cloud_mask = np.isin(im_QA, cloud_values)

    # remove cloud pixels that form very thin features. These are beach or swash pixels that are
    # erroneously identified as clouds by the CFMASK algorithm applied to the images by the USGS.
    if sum(sum(cloud_mask)) > 0 and sum(sum(~cloud_mask)) > 0:
        morphology.remove_small_objects(cloud_mask, min_size=10, connectivity=1, in_place=True)

        if cloud_mask_issue:
            elem = morphology.square(3) # use a square of width 3 pixels
            cloud_mask = morphology.binary_opening(cloud_mask,elem) # perform image opening
            # remove objects with less than 25 connected pixels
            morphology.remove_small_objects(cloud_mask, min_size=25, connectivity=1, in_place=True)

    return cloud_mask
def create_cloud_mask ( im_QA , satname , cloud_mask_issue ) : # convert QA bits (the bits allocated to cloud cover vary depending on the satellite mission) if satname == 'L8' : cloud_values = [ 2800 , 2804 , 2808 , 2812 , 6896 , 6900 , 6904 , 6908 ] elif satname == 'L7' or satname == 'L5' or satname == 'L4' : cloud_values = [ 752 , 756 , 760 , 764 ] elif satname == 'S2' : cloud_values = [ 1024 , 2048 ] # 1024 = dense cloud, 2048 = cirrus clouds # find which pixels have bits corresponding to cloud values cloud_mask = np . isin ( im_QA , cloud_values ) # remove cloud pixels that form very thin features. These are beach or swash pixels that are # erroneously identified as clouds by the CFMASK algorithm applied to the images by the USGS. if sum ( sum ( cloud_mask ) ) > 0 and sum ( sum ( ~ cloud_mask ) ) > 0 : morphology . remove_small_objects ( cloud_mask , min_size = 10 , connectivity = 1 , in_place = True ) if cloud_mask_issue : elem = morphology . square ( 3 ) # use a square of width 3 pixels cloud_mask = morphology . binary_opening ( cloud_mask , elem ) # perform image opening # remove objects with less than 25 connected pixels morphology . remove_small_objects ( cloud_mask , min_size = 25 , connectivity = 1 , in_place = True ) return cloud_mask