NDVI animation - Generate a time series animation of NDVI for Peru’s Arequipa Region

library(rgee)
library(sf)
library(magick)

ee_Initialize()

mask <- system.file("shp/arequipa.shp", package = "rgee") %>%
st_read(quiet = TRUE) %>%
sf_as_ee()

region <- mask$geometry()$bounds()

col <- ee$ImageCollection("MODIS/006/MOD13A2")$select("NDVI")
col <- col$map(function(img) {
doy <- ee$Date(img$get("system:time_start"))$getRelative("day", "year")
img$set("doy", doy)
})

distinctDOY <- col$filterDate("2013-01-01", "2014-01-01")
filter <- ee$Filter$equals(leftField = "doy", rightField = "doy")
join <- ee$Join$saveAll("doy_matches")
joinCol <- ee$ImageCollection(join$apply(distinctDOY, col, filter))

comp <- joinCol$map(function(img) {
doyCol = ee$ImageCollection$fromImages(img$get("doy_matches"))
doyCol$reduce(ee$Reducer$median())$set("date", img$date()$format("MMM"))
})

dates <- comp$aggregate_array("date")$getInfo()

visParams <- list(
min = 0.0,
max = 9000.0,
bands = "NDVI_median",
palette = c("FFFFFF", "CE7E45", "DF923D", "F1B555", "FCD163", "99B718",
"74A901", "66A000", "529400", "3E8601", "207401", "056201",
"004C00", "023B01", "012E01", "011D01", "011301")
)

rgbVis <- comp$map(function(img) {
do.call(img$visualize, visParams) %>%
ee$Image$clip(mask)
})

gifParams <- list(
region = region,
dimensions = 600,
crs = "EPSG:3857",
framesPerSecond = 2
)

animation <- ee_utils_gif_creator(rgbVis, gifParams, mode = "wb")
animation %>%
ee_utils_gif_annotate(
text = "NDVI: MODIS/006/MOD13A2",
size = 15,
color = "white",
location = "+10+10"
) %>%
ee_utils_gif_annotate(
text = dates,
size = 30,
location = "+290+350",
color = "white",
font = "arial",
boxcolor = "#000000"
)
Note: Running Google Earth Engine from RStudio Cloud | by Justin Braaten | Medium
Error:
Captura

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.