r-spatial / rgee

Google Earth Engine for R
https://r-spatial.github.io/rgee/
Other
668 stars 146 forks source link

Issue by downloading Sentinel 2 #344

Open agronomofiorentini opened 1 year ago

agronomofiorentini commented 1 year ago

Before to start thanks for the effort to build this amazing package.

I am using the rgee-docker image (https://github.com/csaybar/rgee-docker), which i have set up.

At submit an issue, please attached the following information of your rgee session:

library(rgee)

# Initialize the Earth Engine module.
ee_Initialize()

# Print metadata for a DEM dataset.
print(ee$Image('USGS/SRTMGL1_003')$getInfo())

Attach your Python (reticulate) configuration:

library(reticulate)
py_config()

Description

I am trying to download sentinel 2 images by using the follow code

      roi <- sf_object%>%
                st_bbox() %>%
                st_as_sfc() %>%
                sf_as_ee()

        s2 <- ee$ImageCollection("COPERNICUS/S2_SR")

        getQABits <- function(image, qa) {
          # Convert decimal (character) to decimal (little endian)
          qa <- sum(2^(which(rev(unlist(strsplit(as.character(qa), "")) == 1))-1))
          # Return a single band image of the extracted QA bits, giving the qa value
          image$bitwiseAnd(qa)$lt(1)
        }

        sentinel_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
          ndvi_qa <- img$select("QA60")

          # Select pixels to mask
          quality_mask <- getQABits(ndvi_qa, "110000000000")

          # Mask pixels with value zero.
          img_band_selected$updateMask(quality_mask)
        }

        s2_ocona <- s2$
          filterBounds(roi)$
          filter(ee$Filter$lte("CLOUDY_PIXEL_PERCENTAGE", 30))$
          filter(ee$Filter$date(paste(Sys.Date()-180),paste(Sys.Date())))$
          map(sentinel_clean)

        s2_ic_local <- ee_imagecollection_to_local(ic = s2_ocona,
                                                   scale = 10,
                                                   region = roi,
                                                   via = 'drive')

but it happened to me that some times the downalod process stops due to abnormal downloading.

I report below the tiff files where the weirdness is reported

Screenshot_github_issue

could you suggest me a different code to prevent it from downalod?

Thanks

milesalanmoore commented 11 months ago

I would take a look at your Task Manager: https://code.earthengine.google.com/tasks. Often this is helpful information noted here when tasks time out. If some of them downloaded, it is most likely an issue with your Tasks on GEE's server side than with rgee itself? Just my thoughts!