Leprechault
Leprechault

Reputation: 1823

CLOUD_SCORE_PLUS collection for filter Sentinel-2 images doesn't work in R

I want to select Sentinel-2 images using CLOUD_SCORE_PLUS for cloud/shadow quality, not QA60. For this, I try for a maximum 10% of cloud:


# Packages
library(tidyverse)
library(rgee)
library(sf)
ee_Initialize(drive=TRUE)

# Define a Region of interest
roi <-ee$Geometry$Point(-52.19032,-30.25413)$buffer(500)

# Sentinel-2 MSI dataset into the Earth Engine’s public data archive ------------              
s2 <- ee$ImageCollection('COPERNICUS/S2_HARMONIZED')
csPlus <- ee$ImageCollection('GOOGLE/CLOUD_SCORE_PLUS/V1/S2_HARMONIZED')

# Define the QA band and clear threshold
QA_BAND <- 'cs'
CLEAR_THRESHOLD <- 0.1


# Function for remove cloud and shadows ------------------------------------------
s2_clean <- function(img) {

  # Select only band of interest, for instance, B2,B3,B4,B8
  img_band_selected <- img$select("B[2-4|8]")
  # quality band
  img$updateMask(img$select(QA_BAND)$gte(CLEAR_THRESHOLD))
}


# Select S2 images ---------------------------------------------------------------
s2_roi  <- s2$
  filterBounds(roi)$
  linkCollection(csPlus, [QA_BAND])$
  filter(ee$Filter$date(as.character(as.Date("2024-01-01")), as.character(as.Date(as.Date(Sys.Date())))))$
  map(s2_clean)

s2_roi_add_area <- s2_roi$map(
  function(img) {
    img$set("area", img$clip(roi)$geometry()$area())
  }
)

# Get the dates and IDs of the selected images ------------------------------------
area <- floor(ee_utils_py_to_r(roi$area(maxError=1)$getInfo()))
ic_date_gt_area <- s2_roi_add_area$filterMetadata("area", "greater_than", area)

nimages <- ic_date_gt_area$size()$getInfo()
nimages 

But there is some trouble because the number of images is always the same despite the changes in the CLEAR_THRESHOLD <- 0.1 or CLEAR_THRESHOLD <- 0.9 parameter values. Please, could someone help me?

Upvotes: 0

Views: 124

Answers (0)

Related Questions