Closed Leprechault closed 2 years ago
Maybe using the SLC band and COPERNICUS_S2_CLOUD_PROBABILITY can give you better results. You would have to:
1) Convert SLC and COPERNICUS_S2_CLOUD_PROBABILITY to a binary mask (0: clear, 1:mask). 2) Merge both products using AND operator. 3) Create your own "CLOUDY_PIXEL_PERCENTAGE" using ee$Image$reduceRegion. 4) Filtering your ic according to this new metadata. 5) if the results are unsatisfactory, try applying dilation to the merged mask product (step 2).
Thanks very much, @csaybar, but look a little bit complicated. Please, do you have any examples in R? I don't find any examples in R syntax from the web.
Hi @Leprechault use rgeeExtra to have a more R-friendly interface to rgee.
library(rgeeExtra)
library(rgee)
# 1. Define your ROI
ROI <- ee$Geometry$Rectangle(
coords = c(440030, 4568820, 445120, 4573910),
proj = "EPSG:32719",
geodesic = FALSE
)
# 2. load S2 collection
ic <- ee$ImageCollection("COPERNICUS/S2_SR") %>%
ee$ImageCollection$filterBounds(ROI) %>%
ee$ImageCollection$filterDate("2021-09-01", "2022-01-01")
add_new_property <- function(img) {
# 3. Use sen2cor cloud mask
sen2cor_cloudmask <- img[["SCL"]]
bmask01 <- sen2cor_cloudmask == 8 | sen2cor_cloudmask == 9 | sen2cor_cloudmask == 10
# 4. Use sen2cloudless cloud mask
# sen2cloudless recommends 0.4 (as I remenber), but it varies according the ROI.
bmask02 <- img[["MSK_CLDPRB"]] > 0.5
# 5. Merge both cloud masks
bmask <- bmask01 | bmask02
# 6. Estimate the new CLOUDY_PIXEL_PERCENTAGE
newproperty <- ee$Image$reduceRegion(
image = bmask,
geometry = ROI, # PUT HERE YOUR ROI!
reducer = ee$Reducer$mean(),
bestEffort = TRUE
) %>%
# The rgeeExtra results have the band name "layer".
# It works as well the raster R package!
ee$Dictionary$get("layer") %>%
ee$Number()
# 7. Set the property
img$set("newCLOUDY_PIXEL_PERCENTAGE", newproperty)
}
new_ic <- ic$map(add_new_property)
ncloud_coverage <- unlist(new_ic$aggregate_array("newCLOUDY_PIXEL_PERCENTAGE")$getInfo())
nold_coverage <- unlist(new_ic$aggregate_array("CLOUDY_PIXEL_PERCENTAGE")$getInfo())
So nice @csaybar, thanks again!! Problem solved
I'd like to know if there is yet something to do not to download
COPERNICUS/S2_SR
images with cloud or shadows. In my reproducible example:It's clear the clouds in
2019-04-12
and2020-05-02
dates, despite the filtersfilter(ee$Filter$lte("CLOUDY_PIXEL_PERCENTAGE", 1)
andfloor(ee_utils_py_to_r(roi$area(maxError=1)$getInfo()))
applied. Please, any help with it?