rgee - calculate maximum composite of monthly NDVI

54 Views Asked by At

The problem is that when I calculate the maximum value, the resolution deprecate, while I need to maintain the original resolution (10 m).

Does anyone know how to calculate the pixel-wise max value while maintaing the original resolution (10m)?

The code:

    # Create a monthly composite
years <- 2018:2023
months <- 1:12

for (y in years){
  for (m in months) {
    
    t <- as.Date(paste0(y,'-',m,'-01'), format="%Y-%m-%d") 
    tt <- ceiling_date(ymd(t), 'month') - days(1)
    if(nchar(month(t))==1){mm <- paste0("0",month(t))} else {mm <- as.character(month(t))}
    if(nchar(day(t))==1){dd <- paste0("0",day(t))} else {dd <- as.character(day(t))}
    iniz <- paste0(year(t),"-",mm,"-",dd)
    fine <- paste0(year(t),"-",mm,"-",day(tt))
    
    ndvi_composite <- dataset$
      filterDate(iniz,fine)$ #'2019-01-01', '2019-12-31'
      filter(ee$Filter$calendarRange(1, field = "month"))$
      map(S2_clean)$
      max()   ### here if I compute the maximum the resolution is degradated
    
    # Download raster
    ee_raster <- ee_as_raster(
      image = ndvi_max,
      region = aoi_gee$geometry(),
      dsn = paste0("E:/GEE/NDVI_MAX_",mm,"_",y,".tif"),
      #scale = 2000,
      via = "drive")
    # Clean a Google Drive folder
    ee_clean_container(name = "rgee_backup", type = "drive")
    
  }
}

without max():

> ee_print(ndvi_composite)
──────────────────────────────────────────────────────────────────────── Earth Engine ImageCollection ──
ImageCollection Metadata:
 - Class                      : ee$ImageCollection
 - Number of Images           : 114
 - Number of Properties       : 23
 - Number of Pixels*          : 13746389154
 - Approximate size*          : 40.97 GB
Image Metadata (img_index = 0):
 - ID                         : no_id
 - system:time_start          : 2019-01-02 10:28:48
 - Number of Bands            : 1
 - Bands names                : nd
 - Number of Properties       : 3
 - Number of Pixels*          : 120582361
 - Approximate size*          : 367.99 MB
Band Metadata (img_band = 'nd'):
 - EPSG (SRID)                : WGS 84 / UTM zone 32N (EPSG:32632)
 - proj4string                : +proj=utm +zone=32 +datum=WGS84 +units=m +no_defs
 - Geotransform               : 10 0 300000 0 -10 4900020
 - Nominal scale (meters)     : 10
 - Dimensions                 : 10981 10981
 - Number of Pixels           : 120582361
 - Data type                  : FLOAT
 - Approximate size           : 367.99 MB
 ────────────────────────────────────────────────────────────────────────────────────────────────────────
 NOTE: (*) Properties calculated considering a constant  geotransform and data type.

With max(), the crs and the resolution change:

ee_print(ndvi_composite)
────────────────────────────────────────────────────────────────────────────────── Earth Engine Image ──
Image Metadata:
 - Class                      : ee$Image
 - ID                         : no_id
 - Number of Bands            : 1
 - Bands names                : nd
 - Number of Properties       : 0
 - Number of Pixels*          : 64800
 - Approximate size*          : 202.50 KB
Band Metadata (img_band = nd):
 - EPSG (SRID)                : WGS 84 (EPSG:4326)
 - proj4string                : +proj=longlat +datum=WGS84 +no_defs
 - Geotransform               : 1 0 0 0 1 0
 - Nominal scale (meters)     : 111319.5
 - Dimensions                 : 360 180
 - Number of Pixels           : 64800
 - Data type                  : FLOAT
 - Approximate size           : 202.50 KB
 ────────────────────────────────────────────────────────────────────────────────────────────────────────
 NOTE: (*) Properties calculated considering a constant geotransform and data type.
0

There are 0 best solutions below