Closed bmaitner closed 2 years ago
Hi @bmaitner you can not combine local-server objects into a map function. More details here https://developers.google.com/earth-engine/guides/client_server
The function below replicates your client-server function.
library(rgee)
ee_Initialize(drive = TRUE)
# However, in building my own function I'm running into problems:
get_integer_date <-function(img) {
# 1. Extract the DayOfYear band
day_values <- img$select("DayOfYear")
# 2. Get the first day of the year and convert to an integer.
start_date <- ee$Date(day_values$get("system:time_start"))
base_date <- ee$Date("1970-01-01")
# 3. Get the day diff betwen start_date and UNIX date
daydiff <- start_date$difference(base_date, "day")
# 4. Mask to only values greater than zero.
mask <- day_values$gt(0)
day_values <- day_values$updateMask(mask)
# #Now, I just need to add the origin to the map
day_values$add(daydiff)
}
modis_ndvi <- ee$ImageCollection("MODIS/006/MOD13A2")
all_days_integer <- modis_ndvi$map(get_integer_date)
gviz <- list(min=10980, max= 11080, palette = c("red", "green"))
Map <- R6Map$new()
Map$addLayer(all_days_integer$first(), gviz)
Map$addLegend(gviz)
Map
Ahhh, I think I see. Thanks so much for pointing me to that resource and for the assistance with the code! Apologies for asking a question that was answered elsewhere
Description
I'm trying to write a function to alter the MODIS NDVI band "DayOfYear" to give the day relative to the start of the UNIX era (1-1-1970). While the code isn't too terribly difficult to get working in general, I'm having trouble figuring out how the function needs to be structured in order to work with $map(). In the NDVI example for rgee, there are a few custom functions made to filter out the bad data using the QA band and these rely on base R functions without any problems. The custom function I wrote relies on other packages beyond base R, so perhaps this is the issue? Any general guidance or resources you can point me to would be much appreciated!
What I Did