r-spatial / rgee

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

Radar vegetation index - RVI for `ImageCollection("COPERNICUS/S1_GRD")` #295

Closed Leprechault closed 2 years ago

Leprechault commented 2 years ago

I'd like to create a temporal mean for the Radar vegetation index - RVI in a target roi. In my example:

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-1 dataset into the Earth Engine’s public data archive ------------              
s1 <- ee$ImageCollection("COPERNICUS/S1_GRD")$filter(ee$Filter$listContains("transmitterReceiverPolarisation", "VV"))
$filter(ee$Filter$listContains("transmitterReceiverPolarisation","VH"))$filter(ee$Filter$eq("instrumentMode", "IW"))

# Radar vegetation index - RVI

RVI = function(img){
    img_band_selected <- image$expression(
        expression = '4*vh/(vv+vh)',
        opt_map =  list(
            'vv' = image$select('VV'),
            'vh' = image$select('VH')
        )
    )
        return(img_band_selected)
    }

s1_roi  <- s1$
   filterBounds(roi)$
   filter(ee$Filter$date(as.character(as.Date("2019-12-04")), as.character(as.Date("2020-01-03"))))$
   map(RVI)

#Extract average radar vegetation index (RVI) values 
ee_mean<- ee_extract(
     x = s1_roi,
     y = RVI,
     scale = 10,
     fun = ee$Reducer$mean(),
     via = "drive"
    )
ee_mean

Error in py_call_impl(callable, dots$args, dots$keywords) : 
TypeError: 'ImageCollection' object is not callable

But the output is not OK and almost doesn't have examples with vegetation index for Sentinel-1 band C.

Please any help with it?

csaybar commented 2 years ago

i hope it helps image

Leprechault commented 2 years ago

Thanks @csaybar, now it works!!!

- download parameters (Google Drive)
 Table ID    : rgee_file_70c1bbd7e46 
 Google user : ndef 
 Folder name : rgee_backup 
 Date        : 2022_10_08_09_37_33 
Polling for task <id: NO52LT3A3RRAAGRRLDLLCVYE, time: 0s>.
Polling for task <id: NO52LT3A3RRAAGRRLDLLCVYE, time: 5s>.
Polling for task <id: NO52LT3A3RRAAGRRLDLLCVYE, time: 10s>.
State: COMPLETED

> ee_mean
  S1B_IW_GRDH_1SDV_20191210T084832_20191210T084857_019300_024710_A03C_constant
1                                                                     2.426008
  S1B_IW_GRDH_1SDV_20191222T084832_20191222T084857_019475_024CA1_193D_constant
1                                                                     2.434232

I do:

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-1 dataset into the Earth Engine’s public data archive ------------              
s1 <- ee$ImageCollection("COPERNICUS/S1_GRD")$filter(ee$Filter$listContains("transmitterReceiverPolarisation", "VV"))$filter(ee$Filter$listContains("transmitterReceiverPolarisation","VH"))$filter(ee$Filter$eq("instrumentMode", "IW"))

# Radar vegetation index - RVI

RVI = function(img){
  img_band_selected <- img$expression(
    expression = '4*vh/(vv+vh)',
    opt_map =  list(
      'vv' = img$select('VV'),
      'vh' = img$select('VH')
    )
  )
  return(img_band_selected)
}

s1_roi  <- s1$filterBounds(roi)$filter(ee$Filter$date(as.character("2019-12-04"), as.character("2020-01-03")))$map(RVI)

#Extract average radar vegetation index (RVI) values 
ee_mean<- ee_extract(
  x = s1_roi,
  y = roi,
  scale = 10,
  fun = ee$Reducer$mean(),
  via = "drive"
)
ee_mean