ee_utils_gif_creator: Create a GIF from an Earth Engine ImageCollection

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/ee_utils.R

Description

Create an GIF (as a magick-image object) from a EE ImageCollection. Note: Animations can only be created when ImageCollections is composed by RGB or RGBA image. This can be done by mapping a visualization function onto an ImageCollection (e.g. ic$map(function(img) img$visualize(...))) or specifying three bands in parameters argument (See examples). ee_utils_gif_creator is a wrapper around ee$ImageCollection$getVideoThumbURL.

Usage

1
ee_utils_gif_creator(ic, parameters, quiet = FALSE, ...)

Arguments

ic

An ee$ImageCollection.

parameters

List of parameters for visualization and animation. See details.

quiet

Logical. Suppress info message.

...

parameter(s) passed on to download.file

Details

The parameters argument is identical to visParams (See rgee::Map$addLayer), plus, optionally:

Value

A magick-image object of the specified ImageCollection.

Author(s)

Jeroen Ooms

See Also

Other GIF functions: ee_utils_gif_annotate(), ee_utils_gif_save()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
## Not run: 
library(rgee)

ee_Initialize()

col <- ee$ImageCollection("JRC/GSW1_1/YearlyHistory")$map(function(img) {
  year <- img$date()$get("year")
  yearImg <- img$gte(2)$multiply(year)
  despeckle <- yearImg$connectedPixelCount(15, TRUE)$eq(15)
  yearImg$updateMask(despeckle)$selfMask()$set("year", year)
})

appendReverse <- function(col) col$merge(col$sort('year', FALSE))

# -----------------------------------
# 1 Basic Animation - Ucayali Peru
# -----------------------------------

bgColor = "FFFFFF" # Assign white to background pixels.
riverColor = "0D0887" # Assign blue to river pixels.

## 1.1 Create the dataset
annualCol = col$map(function(img) {
  img$unmask(0)$
    visualize(min = 0, max = 1, palette = c(bgColor, riverColor))$
    set("year", img$get("year"))
})
basicAnimation <- appendReverse(annualCol)


## 1.2 Set video arguments
aoi <- ee$Geometry$Rectangle(-74.327, -10.087, -73.931, -9.327)
videoArgs = list(
  dimensions = 600, # Max dimension (pixels), min dimension is proportionally scaled.
  region = aoi,
  framesPerSecond = 10
)

## 1.2 Download, display and save the GIF!
animation <- ee_utils_gif_creator(basicAnimation, videoArgs, mode = "wb")
get_years <- basicAnimation$aggregate_array("year")$getInfo()
animation %>%
  ee_utils_gif_annotate("Ucayali, Peru") %>%
  ee_utils_gif_annotate(get_years, size = 15, location = "+90+40",
                        boxcolor = "#FFFFFF") %>%
  ee_utils_gif_annotate("created using {magick} + {rgee}",
                        size = 15, font = "sans",location = "+70+20") ->
  animation_wtxt
gc(reset = TRUE)
ee_utils_gif_save(animation_wtxt, path = paste0(tempfile(), ".gif"))

## End(Not run)

csaybar/rgee documentation built on March 11, 2021, 5:48 a.m.