You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to select Sentinel-2 images using CLOUD_SCORE_PLUS for cloud/shadow quality, not QA60. For this, I try for a maximum 20% of shadow:
# 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.5
# 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, list(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
# Function for the last 6 characters
substrRight <- function(x, n){
substr(x, nchar(x)-n+1, nchar(x))
}
# Download the results
s2_ic_local <- ee_imagecollection_to_local(
ic = s2_roi_add_area,
scale = 10,
region = roi,
via = "drive",
add_metadata = FALSE,
dsn = paste0("stringr::str_extract(gsub("COPERNICUS/S2_SR/","",ic_date$id),
"20\\d{2}\\d{2}\\d{2}"),"_",substrRight(ic_date$id,6))
But there is some trouble because the number of images is always the same despite the changes in the CLEAR_THRESHOLD <- 0.2 parameter values.
Please, could someone help me?
The text was updated successfully, but these errors were encountered:
Leprechault
changed the title
Selection of Sentinel-2 images using CLOUD_SCORE_PLUS
Selection of Sentinel-2 images using CLOUD_SCORE_PLUS collection
May 3, 2024
I want to select Sentinel-2 images using
CLOUD_SCORE_PLUS
for cloud/shadow quality, notQA60
. For this, I try for a maximum 20% of shadow:But there is some trouble because the number of images is always the same despite the changes in the
CLEAR_THRESHOLD <- 0.2
parameter values.Please, could someone help me?
The text was updated successfully, but these errors were encountered: