def cloud_mask_ls8(image):
    """
    Function to mask clouds based on the pixel_qa band of Landsat 8 SR data

    :param {ee.Image} image input Landsat 8 SR image
    :return {ee.Image} cloudmasked Landsat 8 image
    """

    # Bits 3 and 5 are cloud shadow and cloud, respectively.
    cloudShadowBitMask = (1 << 3)
    cloudsBitMask = (1 << 5)
    # Get the pixel QA band.
    qa = image.select('pixel_qa')
    # Both flags should be set to zero, indicating clear conditions.
    mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0).And(qa.bitwiseAnd(cloudsBitMask).eq(0))

    return image.updateMask(mask)