From dca830a4619bab0c442b9971895cc9acb330487b Mon Sep 17 00:00:00 2001 From: csaybar Date: Wed, 11 Aug 2021 23:13:09 +0200 Subject: [PATCH 1/4] ee_extra sync --- NAMESPACE | 2 + R/Deprecated.R | 1016 ----------------------------------- R/ee_Initialize.R | 4 +- R/ee_module.R | 52 ++ R/zzz.R | 4 + man/dot-__Extra__.Rd | 33 ++ man/dot-__Extra_module__.Rd | 33 ++ 7 files changed, 126 insertions(+), 1018 deletions(-) create mode 100644 man/dot-__Extra__.Rd create mode 100644 man/dot-__Extra_module__.Rd diff --git a/NAMESPACE b/NAMESPACE index 93d94af6..9974a655 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,6 +9,8 @@ S3method(ee_print,ee.image.Image) S3method(ee_print,ee.imagecollection.ImageCollection) S3method(print,ee.computedobject.ComputedObject) export("%>%") +export(.__Extra__) +export(.__Extra_module__) export(Map) export(R6Map) export(ee) diff --git a/R/Deprecated.R b/R/Deprecated.R index f2fb6253..e69de29b 100755 --- a/R/Deprecated.R +++ b/R/Deprecated.R @@ -1,1016 +0,0 @@ -#' Earth Engine arithmetic, logic and compare generic functions -#' -#' Arithmetic, logic and compare operators for computation with \code{ee$Image} -#' objects and numeric values. -#' -#' \itemize{ -#' \item \strong{Arith}: +, -, *, /, ^, %%, %/%, %>>% and %>>%. -#' \item \strong{Logic}: !, &, |. -#' \item \strong{Comparison}: ==, !=, >, <, <=, >= -#' } -#' -#' @param e1 Numeric or ee$Image. -#' @param e2 Numeric or ee$Image. -#' -#' @examples -#' \dontrun{ -#' library(rgee) -#' ee_Initialize() -#' -#' # Sum Operator -#' ee1 <- ee$Image(1) -#' ee2 <- ee$Image(2) -#' ee3 <- ee1 + ee2 -#' ee_extract(ee3, ee$Geometry$Point(0, 0)) -#' -#' v1 <- 1 -#' v2 <- 2 -#' v3 <- v1 + v2 -#' v3 -#' -#' # Multiple Operators -#' ee4 <- ee1 / 10 -#' ee5 <- ee4 * (ee2 - 1 + ee1^2 / ee2) -#' ee_extract(ee5, ee$Geometry$Point(0, 0)) -#' -#' v4 <- v1 / 10 -#' v5 <- v4 * (v2 - 1 + v1^2 / v2) -#' v5 -#' -#' # multi-layer object mutiplication, no recycling -#' ee6 <- ee1 + c(1, 5, 10) -#' ee_extract(ee6, ee$Geometry$Point(0, 0)) -#' -#' v6 <- v1 + c(1, 5, 10) -#' v6 -#' } -#' @name Ops-methods -#' @export -Ops.ee.image.Image <- function(e1, e2) { - .Deprecated( - msg = sprintf("%s %s. %s", - "Ops.ee.image.Image will be deprecated in rgee v.1.1.0.", - "Please install rgeeExtra (https://github.com/r-earthengine/rgeeExtra)", - "Deeply sorry for the inconveniences." - ) - ) - # Convert logical values to numeric. - if (!missing(e2)) { - if (is.logical(e2)) { - e2 <- as.numeric(e2) - } - } - if (is.logical(e1)) { - e1 <- as.numeric(e1) - } - - if (.Generic == "+") { - if (missing(e2)) { - e1 - } else { - ee$Image(e1)$add(ee$Image(e2)) - } - } else if(.Generic == "-") { - if (missing(e2)) { - e1$multiply(-1L) - } else { - ee$Image(e1)$subtract(ee$Image(e2)) - } - } else if(.Generic == "*") { - ee$Image(e1)$multiply(ee$Image(e2)) - } else if(.Generic == "^") { - ee$Image(e1)$pow(ee$Image(e2)) - } else if(.Generic == "%%") { - ee$Image(e1)$mod(ee$Image(e2)) - } else if(.Generic == "%/%") { - ee$Image(e1)$divide(ee$Image(e2))$toInt64() - } else if(.Generic == "/") { - ee$Image(e1)$divide(ee$Image(e2)) - } else if (.Generic == "!") { - if (missing(e2)) { - ee$Image(e1)$Not() - } else { - stop("Unexpected use of !") - } - } else if(.Generic == "&") { - ee$Image(e1)$And(ee$Image(e2)) - } else if(.Generic == "|") { - ee$Image(e1)$Or(ee$Image(e2)) - } else if(.Generic == "==") { - ee$Image(e1)$eq(ee$Image(e2)) - } else if(.Generic == "!=") { - ee$Image(e1)$neq(ee$Image(e2)) - } else if(.Generic == "<") { - ee$Image(e1)$lt(ee$Image(e2)) - } else if(.Generic == "<=") { - ee$Image(e1)$lte(ee$Image(e2)) - } else if(.Generic == ">") { - ee$Image(e1)$gt(ee$Image(e2)) - } else if(.Generic == ">=") { - ee$Image(e1)$gte(ee$Image(e2)) - } -} - - -#' Mathematical functions -#' -#' @param x ee$Image -#' @param ... Ignored -#' -#' Generic mathematical functions that can be used with an \code{ee$Image} -#' object as argument: \code{abs}, \code{sign}, \code{sqrt}, \code{ceiling}, -#' \code{cumprod}, \code{cumsum}, \code{log}, \code{log10}, \code{log1p}, -#' \code{log2}, \code{acos}, \code{floor}, \code{asin}, \code{atan}, \code{exp}, -#' \code{expm1}, \code{cos}, \code{cosh}, \code{sin}, \code{sinh}, -#' \code{tan}, and \code{tanh}. -#' -#' @name Math-methods -#' @export -Math.ee.image.Image <- function(x, ...) { - .Deprecated( - msg = sprintf("%s %s. %s", - "Math.ee.image.Image will be deprecated in rgee v.1.1.0.", - "Please install rgeeExtra (https://github.com/r-earthengine/rgeeExtra)", - "Deeply sorry for the inconveniences." - ) - ) - if (.Generic == "abs") { - ee$Image$abs(x) - } else if(.Generic == "sign") { - ee$Image$signum(x$float()) - } else if(.Generic == "sqrt") { - ee$Image$sqrt(x) - } else if(.Generic == "floor") { - ee$Image$floor(x) - } else if(.Generic == "ceiling") { - ee$Image$ceil(x) - } else if(.Generic == "round") { - ee$Image$round(x) - } else if(.Generic == "log") { - args <- list(...) - if (length(args) == 0) { - ee$Image$log(x) / ee$Image$log(ee$Image$exp(1)) - } else { - if (is.null(args$base)) { - stop("Unused argument.") - } - ee$Image$log(x) / ee$Image$log(ee$Image(args$base)) - } - } else if(.Generic == "log10") { - ee$Image$log10(x) - } else if(.Generic == "log2") { - ee$Image$log(x) / ee$Image$log(2) - } else if(.Generic == "log1p") { - ee$Image$log(x + 1) - } else if(.Generic == "exp") { - ee$Image$exp(x) - } else if(.Generic == "expm1") { - ee$Image$exp(x) - 1 - } else if(.Generic == "sin") { - ee$Image$sin(x) - } else if(.Generic == "cos") { - ee$Image$cos(x) - } else if(.Generic == "tan") { - ee$Image$tan(x) - } else if(.Generic == "asin") { - ee$Image$asin(x) - } else if(.Generic == "acos") { - ee$Image$acos(x) - } else if(.Generic == "atan") { - ee$Image$atan(x) - } else if(.Generic == "cosh") { - ee$Image$cosh(x) - } else if(.Generic == "sinh") { - ee$Image$sinh(x) - } else if(.Generic == "tanh") { - ee$Image$tanh(x) - } else if(.Generic == "cumsum") { - total <- 0 - x_list <- list() # List to save. - x_bandnames <- x$bandNames()$getInfo() #band names. - for (index in seq_along(x_bandnames)) { - total <- total + x[[x_bandnames[[index]]]] - x_list[[index]] <- total - } - ee$ImageCollection(x_list)$toBands() - } else if(.Generic == "cumprod") { - total <- 1 - x_list <- list() # List to save. - x_bandnames <- x$bandNames()$getInfo() #band names. - for (index in seq_along(x_bandnames)) { - total <- total * x[[x_bandnames[[index]]]] - x_list[[index]] <- total - } - ee$ImageCollection(x_list)$toBands() - } else { - stop(sprintf("rgee does not support %s yet.", .Generic)) - } -} - -#' Summary Methods -#' -#' @param ... ee$Image. -#' @param na.rm Ignore. -#' @name Summary-methods -#' @export -Summary.ee.image.Image <- function(..., na.rm = TRUE) { - .Deprecated( - msg = sprintf("%s %s. %s", - "Summary.ee.image.Image will be deprecated in rgee v.1.1.0.", - "Please install rgeeExtra (https://github.com/r-earthengine/rgeeExtra)", - "Deeply sorry for the inconveniences." - ) - ) - - img <- ee$ImageCollection(list(...))$toBands() - - if (.Generic == "max") { - img$reduce(ee$Reducer$max()) - } else if (.Generic == "min") { - img$reduce(ee$Reducer$min()) - } else if (.Generic == "range") { - img$reduce(ee$Reducer$minMax()) - } else if (.Generic == "sum") { - img$reduce(ee$Reducer$sum()) - } else if (.Generic == "prod") { - img$reduce(ee$Reducer$product()) - } else { - stop(sprintf("rgee does not support %s yet.", .Generic)) - } -} - -#' @name Summary-methods -#' @export -mean.ee.image.Image <- function(..., na.rm = TRUE) { - .Deprecated( - msg = sprintf("%s %s. %s", - "mean.ee.image.Image will be deprecated in rgee v.1.1.0.", - "Please install rgeeExtra (https://github.com/r-earthengine/rgeeExtra)", - "Deeply sorry for the inconveniences." - ) - ) - - img <- ee$ImageCollection(list(...))$toBands() - img$reduce(ee$Reducer$mean()) -} - - -#' Return the element at a specified position in an Earth Engine Image or ImageCollection -#' -#' @param ee_c ImageCollection or FeatureCollection. -#' @param index Numeric. Specified position. -#' @return Depending of \code{ee_c} can return either an \code{ee$FeatureCollection} -#' or \code{ee$ImageCollection}. -#' @examples -#' \dontrun{ -#' library(rgee) -#' library(sf) -#' -#' ee_Initialize() -#' -#' nc <- st_read(system.file("shape/nc.shp", package = "sf")) %>% -#' st_transform(4326) %>% -#' sf_as_ee() -#' -#' ee_s2 <- ee$ImageCollection("COPERNICUS/S2")$ -#' filterDate("2016-01-01", "2016-01-31")$ -#' filterBounds(nc) -#' -#' ee_s2$size()$getInfo() # 126 -#' -#' # Get the first 5 elements -#' ee_get(ee_s2, index = 0:4)$size()$getInfo() # 5 -#' } -#' @export -ee_get <- function(ee_c, index = 0) { - .Deprecated( - msg = sprintf("%s %s. %s", - "ee_get will be deprecated in rgee v.1.1.0.", - "Please install rgeeExtra (https://github.com/r-earthengine/rgeeExtra)", - "Deeply sorry for the inconveniences." - ) - ) - is_consecutive <- all(diff(index) == 1) - if (any(index < 0)) { - stop("index must be a positive value") - } - if (any(class(ee_c) %in% c("ee.imagecollection.ImageCollection"))) { - # Index is a single value? - if (length(index) == 1) { - ee_c %>% - ee$ImageCollection$toList(count = 1, offset = index) %>% - ee$ImageCollection() - } else { - # Index is a n-length vector and consecutive? - if (length(index) > 1 & is_consecutive) { - ee_c %>% - ee$ImageCollection$toList(count = length(index), offset = min(index)) %>% - ee$ImageCollection() - } else { - stop("ee_get only support ascending index order") - } - } - } else if (any(class(ee_c) %in% c("ee.featurecollection.FeatureCollection"))) { - # Index is a single value? - if (length(index) == 1) { - ee_c %>% - ee$FeatureCollection$toList(count = 1, offset = index) %>% - ee$FeatureCollection() - } else { - # Index is a n-length vector and consecutive? - if (length(index) > 1 & is_consecutive) { - ee_c %>% - ee$FeatureCollection$toList(count = length(index), offset = min(index)) %>% - ee$FeatureCollection() - } else { - stop("ee_get only support ascending index order") - } - } - } else { - stop("ee_get only support objects of class FeatureCollection and ImageCollection.", - "\nEnter: ", class(ee_c)[1], - "\nExpected: ee$ImageCollection or ee$FeatureCollection") - } -} - - -#' Extract or replace parts of and ee$ImageCollection -#' @param x ee$ImageCollection or ee$Image. -#' @param index Integer. Index specifying elements to extract or replace. -#' @param value ee$ImageCollection or ee$Image to replace in. -#' @name ee_subsetting -#' @examples -#' \dontrun{ -#' library(rgee) -#' library(sf) -#' -#' ee_Initialize(gcs = TRUE, drive = TRUE) -#' -#' # Define a Image or ImageCollection: Terraclimate -#' terraclimate <- ee$ImageCollection("IDAHO_EPSCOR/TERRACLIMATE") %>% -#' ee$ImageCollection$filterDate("2001-01-01", "2002-01-01") -#' -#' # Define temperature Vis parameters -#' maximumTemperatureVis <- list( -#' min = -300.0, -#' max = 300.0, -#' palette = c( -#' '1a3678', '2955bc', '5699ff', '8dbae9', 'acd1ff', 'caebff', 'e5f9ff', -#' 'fdffb4', 'ffe6a2', 'ffc969', 'ffa12d', 'ff7c1f', 'ca531a', 'ff0000', -#' 'ab0000' -#' ) -#' ) -#' -#' Map$setCenter(71.72, 52.48, 2) -#' m1 <- Map$addLayer(terraclimate[[2]][["tmmx"]], maximumTemperatureVis) -#' -#' terraclimate[[2]] <- terraclimate[[2]]*1.4 -#' m2 <- Map$addLayer(terraclimate[[2]][["tmmx"]], maximumTemperatureVis) -#' m1 | m2 -#' } -#' @export -'[[.ee.imagecollection.ImageCollection' <- function(x, index) { - .Deprecated( - msg = sprintf("%s %s. %s", - "[[.ee.imagecollection.ImageCollection will be deprecated in rgee v.1.1.0.", - "Please install rgeeExtra (https://github.com/r-earthengine/rgeeExtra)", - "Deeply sorry for the inconveniences." - ) - ) - # 1. Deal with negative and zero index - if (index < 1) { - if (index == 0) { - stop( - "rgee respect the one-based index. Therefore if you want to obtain the ", - "first ee$Image you must use 1 rather than 0." - ) - } else { - stop("Negative index are not supported.") - } - } - - if (length(index) > 1) { - x %>% ee_get((index) - 1) - } else { - x %>% ee_get((index) - 1) %>% ee$ImageCollection$first() - } -} - - -#' @name ee_subsetting -#' @export -'[[<-.ee.imagecollection.ImageCollection' <- function(x, index, value) { - .Deprecated( - msg = sprintf("%s %s. %s", - "[[<-.ee.imagecollection.ImageCollection will be deprecated in rgee v.1.1.0.", - "Please install rgeeExtra (https://github.com/r-earthengine/rgeeExtra)", - "Deeply sorry for the inconveniences." - ) - ) - - # 1. Deal with negative and zero index - if (any(index < 1)) { - if (any(index == 0)) { - stop( - "rgee respect the one-based index. Therefore if you want to obtain the ", - "first ee$Image you must use 1 rather than 0." - ) - } else { - stop("Negative index are not supported.") - } - } - - if (length(index) == 2) { - ee_ic_size <- index[2] - index <- index[1] - } else { - # 2. Length of the ImageCollection - ee_ic_size <- x %>% - ee$ImageCollection$size() %>% - ee$Number$getInfo() - } - - # 3. From ImageCollection to list of images - ic_list <- lapply( - (seq_len(ee_ic_size) - 1), - function(index) x %>% ee_get(index) %>% ee$ImageCollection$first() - ) - - # 4. Convert value from ee.Image, ee.ImageCollection or list of ee.Image to - # list of ee.Image. - if (any(class(value) %in% "ee.image.Image")) { - list_value <- list(value) - } else if(any(class(value) %in% "ee.imagecollection.ImageCollection")) { - # 4.1. Length of the ImageCollection - ee_value_size <- value %>% - ee$ImageCollection$size() %>% - ee$Number$getInfo() - - # 4.2. From ImageCollection to list of images - value_list <- lapply( - (seq_len(ee_value_size) - 1), - function(index) x %>% ee_get(index) %>% ee$ImageCollection$first() - ) - list_value <- value_list - } else if(any(class(value) %in% "list")) { - list_value <- value - } else { - stop( - sprintf( - "value should be a ee.Image, ee.ImageCollection of a list of ee.Image not a %s.", - class(value) - ) - ) - } - - # 5. Do the index and value have the same length? - if (length(index) != length(list_value)) { - stop("The value to assign should have the same length that the ee$ImageCollection.") - } - - # 6. Condition: Index is outside of ic - if (!any(seq_len(ee_ic_size) %in% seq_along(list_value))) { - stop("Not a valid subset") - } - - # 7. Condition: Index is outside of ic - counter <- 1 - for (list_value_index in seq_along(list_value)) { - ic_list[[index[counter]]] <- list_value[[list_value_index]] - counter <- counter + 1 - } - ee$ImageCollection(ic_list) -} - - -#' @name ee_subsetting -#' @export -'[[.ee.image.Image' <- function(x, index) { - .Deprecated( - msg = sprintf("%s %s. %s", - "[[.ee.image.Image will be deprecated in rgee v.1.1.0.", - "Please install rgeeExtra (https://github.com/r-earthengine/rgeeExtra)", - "Deeply sorry for the inconveniences." - ) - ) - - # 2. Select just an specific band - if (is.numeric(index)) { - - # 2.1. Deal with negative and zero index - if (any(index < 1)) { - if (any(index == 0)) { - stop( - "rgee respect the one-based index. Therefore if you want to obtain the ", - "first image-band you must use 1 rather than 0." - ) - } else { - stop("Negative index are not supported.") - } - } - - x$select(index - 1) - } else if (is.character(index)) { - x$select(index) - } else { - stop( - sprintf("index must be a numeric or a character not a %s.", class(index)) - ) - } -} - - -#' @name ee_subsetting -#' @export -'[[<-.ee.image.Image' <- function(x, index, value) { - .Deprecated( - msg = sprintf("%s %s. %s", - "[[<-.ee.image.Image will be deprecated in rgee v.1.1.0.", - "Please install rgeeExtra (https://github.com/r-earthengine/rgeeExtra)", - "Deeply sorry for the inconveniences." - ) - ) - - # 1. Get band names - if (!any(class(value) %in% "ee.image.Image")) { - stop(sprintf("value must be a ee.Image not a %s.", class(value))) - } - - # 2. From multiband Image to single-band ImageCollection - x_ic <- x %>% - ee$Image$bandNames() %>% - ee$List$map( - ee_utils_pyfunc( - function(band) x$select(list(band)) - ) - ) %>% ee$ImageCollection() - - - if (is.character(index)) { - # 3. If index is a character obtain band name - bdn <- ee$Image$bandNames(x)$getInfo() - if (any(bdn %in% index)) { - # 3.1. Send to '[['.ImageCollection operator the numerical index and the - # length of the ImageCollection (to avoid estimate it again!) - x_ic[[c(which(bdn %in% index), length(bdn))]] <- value - x_ic$toBands() - } else { - stop("Index does not match with any band in the ee$Image.") - } - } else { - # 3. Replace value - x_ic[[index]] <- value - x_ic$toBands() - } -} - - -#' Names of Earth Engine Images Layers -#' -#' Get or set the names of the layers of an Earth Engine Image object. -#' @param x an EE Image object. -#' @param value a character vector with the same length as x. -#' @name ee_name -#' @export -'names<-.ee.image.Image' <-function(x, value) { - .Deprecated( - msg = sprintf("%s %s. %s", - "names<-.ee.image.Image will be deprecated in rgee v.1.1.0.", - "Please install rgeeExtra (https://github.com/r-earthengine/rgeeExtra)", - "Deeply sorry for the inconveniences." - ) - ) - ee$Image$rename(x, value) -} - - -#' @name ee_name -#' @export -'names.ee.image.Image' <-function(x) { - .Deprecated( - msg = sprintf("%s %s. %s", - "names.ee.image.Image will be deprecated in rgee v.1.1.0.", - "Please install rgeeExtra (https://github.com/r-earthengine/rgeeExtra)", - "Deeply sorry for the inconveniences." - ) - ) - x$bandNames()$getInfo() -} - - - -#' Length of an Earth Engine Image Object -#' -#' Get or set the length of an Earth Engine Image. -#' @param x an EE Image Object. -#' @param value a non-negative integer. -#' @details -#' If a vector is shortened, extra values are discarded and when a vector -#' is lengthened, it is padded out to its new length with ee$Image(0), with -#' band name of zzz_rgee_NA_%02d. -#' @name ee_length -#' @export -'length.ee.image.Image' <-function(x) { - .Deprecated( - msg = sprintf("%s %s. %s", - "length.ee.image.Image will be deprecated in rgee v.1.1.0.", - "Please install rgeeExtra (https://github.com/r-earthengine/rgeeExtra)", - "Deeply sorry for the inconveniences." - ) - ) - length(x$bandNames()$getInfo()) -} - - - -#' @name ee_length -#' @export -'length<-.ee.image.Image' <-function(x, value) { - .Deprecated( - msg = sprintf("%s %s. %s", - "length<-.ee.image.Image will be deprecated in rgee v.1.1.0.", - "Please install rgeeExtra (https://github.com/r-earthengine/rgeeExtra)", - "Deeply sorry for the inconveniences." - ) - ) - - ee_x_length <- length(x) - how_much_add <- value - ee_x_length - if(how_much_add < 0) { - x[[seq_len(value)]] - } else if (how_much_add == 0) { - x - } else if (how_much_add > 0) { - ee_zero_img <- ee$ImageCollection( - lapply(seq_len(how_much_add), function(z) ee$Image(0)) - )$toBands() - names(ee_zero_img) <- sprintf("zzz_rgee_NA_%02d", seq_len(how_much_add)) - x$addBands(ee_zero_img) - } -} - - -#' Length of an Earth Engine ImageCollection Object -#' -#' Set the length of an Earth Engine Image. -#' -#' @param x an EE ImageCollection Object. -#' @name ee_length_ic -#' @export -'length.ee.imagecollection.ImageCollection' <-function(x) { - .Deprecated( - msg = sprintf("%s %s. %s", - "length.ee.imagecollection.ImageCollection will be deprecated in rgee v.1.1.0.", - "Please install rgeeExtra (https://github.com/r-earthengine/rgeeExtra)", - "Deeply sorry for the inconveniences." - ) - ) - x$size()$getInfo() -} - - - -# GIF --------------------------------------------------------------------- - -#' Create a GIF from an Earth Engine ImageCollection -#' -#' 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. \code{ic$map(function(img) img$visualize(...))}) -#' or specifying three bands in parameters argument (See examples). [ee_utils_gif_creator] is a -#' wrapper around \strong{\code{ee$ImageCollection$getVideoThumbURL}}. -#' -#' @author Jeroen Ooms -#' -#' @param ic An ee$ImageCollection. -#' @param parameters List of parameters for visualization and animation. See details. -#' @param quiet Logical. Suppress info message. -#' @param ... parameter(s) passed on to [download.file][utils::download.file] -#' @details -#' The parameters argument is identical to visParams (See \code{rgee::Map$addLayer}), -#' plus, optionally: -#' \itemize{ -#' \item \strong{dimensions}: A number or pair of numbers in format c(WIDTH,HEIGHT). -#' Max dimensions of the thumbnail to render, in pixels. If only one number is -#' passed, it is used as the maximum, and the other dimension is computed by -#' proportional scaling. -#' \item \strong{crs}: A CRS string specifying the projection of the output. -#' \item \strong{crs_transform}: The affine transform to use for the output -#' pixel grid. -#' \item \strong{scale}: A scale to determine the output pixel grid; ignored if -#' both crs and crs_transform are specified. -#' \item \strong{region}: ee$Geometry$Polygon, GeoJSON or c(E,S,W,N). Geospatial -#' region of the result. By default, the whole image. -#' \item \strong{format}: String. The output format (only 'gif' is currently -#' supported). -#' \item \strong{framesPerSecond}: String. Animation speed. -#' } -#' @return A magick-image object of the specified ImageCollection. -#' @examples -#' \dontrun{ -#' 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")) -#' } -#' @family GIF functions -#' @export -ee_utils_gif_creator <- function(ic, parameters, quiet = FALSE, ...) { - .Deprecated( - msg = sprintf("%s %s. %s", - "ee_utils_gif_creator will be deprecated in rgee v.1.1.0.", - "Please install rgeeExtra (https://github.com/r-earthengine/rgeeExtra)", - "Deeply sorry for the inconveniences." - ) - ) - # check packages - ee_check_packages("ee_utils_gif_creator", "magick") - - if (!quiet) { - message("1. Creating gif ... please wait ....") - } - animation_url <- ee$ImageCollection$getVideoThumbURL(ic, parameters) - temp_gif <- tempfile() - if (!quiet) { - message("1. Downloading GIF from: ", animation_url) - } - download.file( - url = animation_url, - destfile = temp_gif, - quiet = quiet, - ...) - magick::image_read(path = temp_gif) -} - - -#' Add text to a GIF -#' -#' Add text to a GIF (magick-image object). This function is a wrapper around -#' [image_annotate][magick::image_annotate]. -#' -#' @author Jeroen Ooms -#' -#' @param image magick image object returned by [magick::image_read()] or [magick::image_graph()] -#' @param text character vector of length equal to 'image' or length 1 -#' @param gravity string with [gravity](https://www.imagemagick.org/Magick++/Enumerations.html#GravityType) -#' value from [gravity_types][magick::gravity_types]. -#' @param location geometry string with location relative to `gravity` -#' @param degrees rotates text around center point -#' @param size font-size in pixels -#' @param font string with font family such as `"sans"`, `"mono"`, `"serif"`, -#' `"Times"`, `"Helvetica"`, `"Trebuchet"`, `"Georgia"`, `"Palatino"` or `"Comic Sans"`. -#' @param style value of [style_types][magick::style_types] for example `"italic"` -#' @param weight thickness of the font, 400 is normal and 700 is bold. -#' @param kerning increases or decreases whitespace between letters -#' @param decoration value of [decoration_types][magick::decoration_types] for example `"underline"` -#' @param color a valid [color string](https://www.imagemagick.org/Magick++/Color.html) such as -#' `"navyblue"` or `"#000080"`. Use `"none"` for transparency. -#' @param strokecolor a [color string](https://www.imagemagick.org/Magick++/Color.html) -#' adds a stroke (border around the text) -#' @param boxcolor a [color string](https://www.imagemagick.org/Magick++/Color.html) -#' for background color that annotation text is rendered on. -#' -#' @return A magick-image object -#' -#' @examples -#' \dontrun{ -#' 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")) -#' } -#' @family GIF functions -#' @export -ee_utils_gif_annotate <- function(image, - text, - gravity = "northwest", - location = "+0+0", - degrees = 0, - size = 20, - font = "sans", - style = "normal", - weight = 400, - kerning = 0, - decoration = NULL, - color = NULL, - strokecolor = NULL, - boxcolor = NULL) { - .Deprecated( - msg = sprintf("%s %s. %s", - "ee_utils_gif_annotate will be deprecated in rgee v.1.1.0.", - "Please install rgeeExtra (https://github.com/r-earthengine/rgeeExtra)", - "Deeply sorry for the inconveniences." - ) - ) - # check packages - ee_check_packages("ee_utils_gif_annotate", "magick") - - if (length(text) == 1) { - image <- magick::image_annotate(image, text, gravity = gravity, - location = location, degrees = degrees, size = size, - font = font, style = style, weight = weight, - kerning = kerning, decoration = decoration, - color = color, strokecolor = strokecolor, - boxcolor = boxcolor) - } else if(length(text) == length(image)) { - image <- magick::image_annotate(image, text, gravity = gravity, - location = location, degrees = degrees, size = size, - font = font, style = style, weight = weight, - kerning = kerning, decoration = decoration, - color = color, strokecolor = strokecolor, - boxcolor = boxcolor) - } else { - stop( - "The text argument has not the same length as the magick-image object", - "\nActual:",length(text), - "\nExpected:", length(image) - ) - } - image -} - - -#' Write a GIF -#' -#' Write a magick-image object as a GIF file using the \code{magick} package. This -#' function is a wrapper around [image_write][magick::image_write]. -#' -#' @author Jeroen Ooms -#' -#' @param image magick image object returned by [image_read][magick::image_read]. -#' @param path path a file, url, or raster object or bitmap array. -#' @param format output format such as `"png"`, `"jpeg"`, `"gif"`, `"rgb"` or `"rgba"`. -#' @param quality number between 0 and 100 for jpeg quality. Defaults to 75. -#' @param depth color depth (either 8 or 16). -#' @param density resolution to render pdf or svg. -#' @param comment text string added to the image metadata for supported formats. -#' @param flatten should the image be flattened before writing? This also replaces -#' transparency with a background color. -#' @examples -#' \dontrun{ -#' 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")) -#' } -#' @family GIF functions -#' @return No return value, called to write a GIF file. -#' @export -ee_utils_gif_save <- function(image, - path = NULL, - format = NULL, - quality = NULL, - depth = NULL, - density = NULL, - comment = NULL, - flatten = FALSE) { - .Deprecated( - msg = sprintf("%s %s. %s", - "ee_utils_gif_save will be deprecated in rgee v.1.1.0.", - "Please install rgeeExtra (https://github.com/r-earthengine/rgeeExtra)", - "Deeply sorry for the inconveniences." - ) - ) - - # check packages - ee_check_packages("ee_utils_gif_save", "magick") - magick::image_write(image = image, path = path, format = format, - quality = quality, depth = depth, density = density, - comment = comment, flatten = flatten) -} diff --git a/R/ee_Initialize.R b/R/ee_Initialize.R index b2382778..8c089d66 100755 --- a/R/ee_Initialize.R +++ b/R/ee_Initialize.R @@ -261,8 +261,8 @@ ee_Initialize <- function(user = NULL, # If Extra module exist add to ee! tryCatch( expr = { - class(Extra) <- c("Extra_EE_module", class(Extra)) - ee$Extra <- Extra + ee$Extra <- .__Extra__ + ee$`__Extra__` <- .__Extra_module__ }, error = function(e) { {ee$Extra <- NULL} diff --git a/R/ee_module.R b/R/ee_module.R index fcea57d9..5a1d7180 100755 --- a/R/ee_module.R +++ b/R/ee_module.R @@ -20,3 +20,55 @@ #' } #' @export ee <- NULL + + +#' Extra Earth Engine dictionary +#' +#' Interface to Extra Earth Engine module. Provides access to the top level +#' classes and functions as well as sub-modules (e.g. \code{ee$Image}, +#' \code{ee$FeatureCollection$first}, etc.). +#' +#' @format Earth Engine module +#' +#' @examples +#' \dontrun{ +#' library(rgee) +#' library(rgeeExtra) +#' +#' # ee_install_extra() +#' ee_Initialize() +#' +#' ee_img1 <- ee$Image(0) +#' ee_img2 <- ee$Image(0) +#' +#' ee_img3 <- ee_img1 * ee_img2 + ee_img2 +#' print(ee_img3) +#' } +#' @export +.__Extra__ <- NULL + + +#' Extra Earth Engine module +#' +#' Interface to Extra Earth Engine module. Provides access to the top level +#' classes and functions as well as sub-modules (e.g. \code{ee$Image}, +#' \code{ee$FeatureCollection$first}, etc.). +#' +#' @format Earth Engine module +#' +#' @examples +#' \dontrun{ +#' library(rgee) +#' library(rgeeExtra) +#' +#' # ee_install_extra() +#' ee_Initialize() +#' +#' ee_img1 <- ee$Image(0) +#' ee_img2 <- ee$Image(0) +#' +#' ee_img3 <- ee_img1 * ee_img2 + ee_img2 +#' print(ee_img3) +#' } +#' @export +.__Extra_module__ <- NULL diff --git a/R/zzz.R b/R/zzz.R index a61df914..8f02a5b1 100755 --- a/R/zzz.R +++ b/R/zzz.R @@ -11,4 +11,8 @@ # delay load earthengine-api #ee <<- reticulate::import("ee", delay_load = TRUE) ee <<- reticulate::import("ee", delay_load = list(priority = 30)) + + # delay load eeExtra + .__Extra_module__ <<- reticulate::import("ee_extra", delay_load = list(priority = 40)) + .__Extra__ <<- .__Extra_module__$Extra } diff --git a/man/dot-__Extra__.Rd b/man/dot-__Extra__.Rd new file mode 100644 index 00000000..4abbf75c --- /dev/null +++ b/man/dot-__Extra__.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ee_module.R +\docType{data} +\name{.__Extra__} +\alias{.__Extra__} +\title{Extra Earth Engine dictionary} +\format{ +Earth Engine module +} +\usage{ +.__Extra__ +} +\description{ +Interface to Extra Earth Engine module. Provides access to the top level +classes and functions as well as sub-modules (e.g. \code{ee$Image}, +\code{ee$FeatureCollection$first}, etc.). +} +\examples{ +\dontrun{ +library(rgee) +library(rgeeExtra) + +# ee_install_extra() +ee_Initialize() + +ee_img1 <- ee$Image(0) +ee_img2 <- ee$Image(0) + +ee_img3 <- ee_img1 * ee_img2 + ee_img2 +print(ee_img3) +} +} +\keyword{datasets} diff --git a/man/dot-__Extra_module__.Rd b/man/dot-__Extra_module__.Rd new file mode 100644 index 00000000..3595548b --- /dev/null +++ b/man/dot-__Extra_module__.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ee_module.R +\docType{data} +\name{.__Extra_module__} +\alias{.__Extra_module__} +\title{Extra Earth Engine module} +\format{ +Earth Engine module +} +\usage{ +.__Extra_module__ +} +\description{ +Interface to Extra Earth Engine module. Provides access to the top level +classes and functions as well as sub-modules (e.g. \code{ee$Image}, +\code{ee$FeatureCollection$first}, etc.). +} +\examples{ +\dontrun{ +library(rgee) +library(rgeeExtra) + +# ee_install_extra() +ee_Initialize() + +ee_img1 <- ee$Image(0) +ee_img2 <- ee$Image(0) + +ee_img3 <- ee_img1 * ee_img2 + ee_img2 +print(ee_img3) +} +} +\keyword{datasets} From 45a65153ae5f9c748b1b519e37d884f55de576a2 Mon Sep 17 00:00:00 2001 From: csaybar Date: Wed, 25 Aug 2021 17:30:15 +0200 Subject: [PATCH 2/4] WIP --- DESCRIPTION | 2 +- R/addins.R | 4 ++-- R/ee_Initialize.R | 22 ++++++++++++++++++++++ R/ee_install.R | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 817dd795..5afa758a 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -112,7 +112,7 @@ Suggests: geojsonio, sf, stars, - googledrive (>= 1.0.0), + googledrive (>= 2.0.0), googleCloudStorageR (>= 0.5.1), rstudioapi (>= 0.7), raster, diff --git a/R/addins.R b/R/addins.R index 64872846..785ebfc3 100755 --- a/R/addins.R +++ b/R/addins.R @@ -1,7 +1,7 @@ #' Return documentation of Earth Engine modules, methods and classes #' @noRd -ee_help_addins <- function(debug=FALSE, content) { - if (!debug) { +ee_help_addins <- function(content = NULL, debug=FALSE) { + if (debug) { selected_content <- content } else { context <- rstudioapi::getSourceEditorContext() diff --git a/R/ee_Initialize.R b/R/ee_Initialize.R index 8c089d66..d3698f4d 100755 --- a/R/ee_Initialize.R +++ b/R/ee_Initialize.R @@ -832,3 +832,25 @@ ee_Dataset_creator <- function(eeDataset) { eedataset_fc <- lapply(eeDataset[["FeatureCollection"]], function(x) ee$FeatureCollection(x)) list(image = eedataset_img, ic = eedataset_ic, fc = eedataset_fc) } + + +#' Exist ee_extra +#' @noRd +eeExtra_exist <- function() { + condition <- reticulate::py_module_available("ee_extra") + if (!condition) { + "Consider installing ee_extra Python package. ee_extra enables" + "the integration between Javascript and rgee. The following functions" + "will not work until you install ee_extra:" + "- rgeeExtra::module()" + "- ee$Extra$*" + "To install ee_extra please try as follow:" + "> ee_install(): To create and set a Python environment with all rgee dependencies." + "> ee_install_upgrade(): Run previously ee_Initialize to set a Python Env." + "> pip3 install ee_extra" + "> conda install ee_xtra" + } + return(condition) +} + + diff --git a/R/ee_install.R b/R/ee_install.R index a66df633..050b5b6d 100755 --- a/R/ee_install.R +++ b/R/ee_install.R @@ -224,7 +224,7 @@ ee_install <- function(py_env = "rgee", ) reticulate::py_install( - packages = c("earthengine-api", "numpy"), + packages = c("earthengine-api", "numpy", "ee_extra"), envname = rgee_path ) From ff67120ba058c0f28dad55d59a1a22936b803a88 Mon Sep 17 00:00:00 2001 From: csaybar Date: Wed, 15 Sep 2021 08:50:18 +0200 Subject: [PATCH 3/4] conflict in merging solved --- R/addins.R | 3 +-- R/ee_Initialize.R | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/R/addins.R b/R/addins.R index 785ebfc3..93d29219 100755 --- a/R/addins.R +++ b/R/addins.R @@ -1,6 +1,6 @@ #' Return documentation of Earth Engine modules, methods and classes #' @noRd -ee_help_addins <- function(content = NULL, debug=FALSE) { +ee_help_addins <- function(content=NULL, debug=FALSE) { if (debug) { selected_content <- content } else { @@ -164,4 +164,3 @@ ee_get_eefunc <- function() { ee_get_funname(text = context$contents[line], cursor = cursor) } } - diff --git a/R/ee_Initialize.R b/R/ee_Initialize.R index d3698f4d..6dbe5545 100755 --- a/R/ee_Initialize.R +++ b/R/ee_Initialize.R @@ -823,7 +823,6 @@ ee_check_packages <- function(fn_name, packages) { } } - #' Dataset Creator #' @noRd ee_Dataset_creator <- function(eeDataset) { @@ -854,3 +853,30 @@ eeExtra_exist <- function() { } +#' Testing 403 error in GD +#' @noRd +test_drive_privileges <-function(user) { + ee_check_packages("ee_Initialize(..., drive=TRUE)", "gargle") + # this will break in GD API v4 ... be careful :) + req <- gargle::request_build( + path = "drive/v3/files/{fileId}", + method = "GET", + params = list(fileId = "soyunparametro", supportsAllDrives = TRUE), + token = googledrive::drive_token() + ) + resp <- gargle::request_make(req) + if (resp$status_code == 403) { + stop( + "Your googledrive token does not have permission\n", + "to view or modify files from Google Drive.\n", + "Did you cross the check box when Google asked for permissions?\n", + "See: https://github.com/r-spatial/rgee/issues/175#issuecomment-905611278\n", + sprintf( + "Run %s to fix.", + crayon::bold( + sprintf("ee_clean_credentials('%s')", user) + ) + ) + ) + } +} From 3af376b3766fdc9626b218d01d380ba4fbfab8bb Mon Sep 17 00:00:00 2001 From: csaybar Date: Thu, 16 Sep 2021 02:37:53 +0200 Subject: [PATCH 4/4] rgee 1.1.2 --- .Rbuildignore | 3 ++- DESCRIPTION | 2 +- NAMESPACE | 2 -- NEWS.md | 6 +++++ R/ee_Initialize.R | 33 ----------------------- R/ee_check.R | 2 +- R/ee_clean.R | 10 +++---- R/ee_install.R | 8 +++--- R/ee_module.R | 52 ------------------------------------- R/zzz.R | 7 ++--- man/dot-__Extra__.Rd | 33 ----------------------- man/dot-__Extra_module__.Rd | 33 ----------------------- 12 files changed, 21 insertions(+), 170 deletions(-) delete mode 100644 man/dot-__Extra__.Rd delete mode 100644 man/dot-__Extra_module__.Rd diff --git a/.Rbuildignore b/.Rbuildignore index 73317302..976f26b4 100755 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -21,4 +21,5 @@ ^test\credentials ^doc$ ^Meta$ -^tester\.R$ \ No newline at end of file +^tester\.R$ +^CITATION\.cff$ \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index 73159b68..281f1d50 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rgee Title: R Bindings for Calling the 'Earth Engine' API -Version: 1.1.1 +Version: 1.1.2 Authors@R: c(person(given = "Cesar", family = "Aybar", diff --git a/NAMESPACE b/NAMESPACE index 9974a655..93d94af6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,8 +9,6 @@ S3method(ee_print,ee.image.Image) S3method(ee_print,ee.imagecollection.ImageCollection) S3method(print,ee.computedobject.ComputedObject) export("%>%") -export(.__Extra__) -export(.__Extra_module__) export(Map) export(R6Map) export(ee) diff --git a/NEWS.md b/NEWS.md index fbc3c14a..3e2a7cd4 100755 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,12 @@ vignette: > %\VignetteIndexEntry{NEWS} %\VignetteEncoding{UTF-8} --- +# rgee 1.1.2 + +- Fix an error in 'ee_check' warning message. +- 'ee_extra' Python package is now a submodule of rgeeExtra. +- 'ee_install' typo fixed. + # rgee 1.1.1 - Deprecated.R file deleted. diff --git a/R/ee_Initialize.R b/R/ee_Initialize.R index a77dd602..f5acafd7 100755 --- a/R/ee_Initialize.R +++ b/R/ee_Initialize.R @@ -259,18 +259,6 @@ ee_Initialize <- function(user = NULL, ee$ImageCollection$Dataset <- eeDataset_b$ic ee$Image$Dataset <- eeDataset_b$image - - # If Extra module exist add to ee! - tryCatch( - expr = { - ee$Extra <- .__Extra__ - ee$`__Extra__` <- .__Extra_module__ - }, - error = function(e) { - {ee$Extra <- NULL} - } - ) - invisible(TRUE) } @@ -834,27 +822,6 @@ ee_Dataset_creator <- function(eeDataset) { list(image = eedataset_img, ic = eedataset_ic, fc = eedataset_fc) } - -#' Exist ee_extra -#' @noRd -eeExtra_exist <- function() { - condition <- reticulate::py_module_available("ee_extra") - if (!condition) { - "Consider installing ee_extra Python package. ee_extra enables" - "the integration between Javascript and rgee. The following functions" - "will not work until you install ee_extra:" - "- rgeeExtra::module()" - "- ee$Extra$*" - "To install ee_extra please try as follow:" - "> ee_install(): To create and set a Python environment with all rgee dependencies." - "> ee_install_upgrade(): Run previously ee_Initialize to set a Python Env." - "> pip3 install ee_extra" - "> conda install ee_xtra" - } - return(condition) -} - - #' Testing 403 error in GD #' @noRd test_drive_privileges <-function(user) { diff --git a/R/ee_check.R b/R/ee_check.R index 7e2964bc..4ed5bada 100755 --- a/R/ee_check.R +++ b/R/ee_check.R @@ -109,7 +109,7 @@ ee_check_python_packages <- function(quiet = FALSE) { sprintf("version used by rgee (%s). You might use:", ee_version()), "* rgee::ee_install_upgrade()", sprintf( - "* reticulate::py_install('earthengine-api==%s')", + "* reticulate::py_install('earthengine-api==%s', envname='PUT_HERE_YOUR_PYENV')", ee_version() ), sprintf( diff --git a/R/ee_clean.R b/R/ee_clean.R index 9df44201..1ae47270 100755 --- a/R/ee_clean.R +++ b/R/ee_clean.R @@ -15,13 +15,13 @@ ee_clean_credentials <- function(user='not_defined', quiet = FALSE) { oauth_func_path <- system.file("python/ee_utils.py", package = "rgee") utils_py <- ee_source_python(oauth_func_path) ee_path <- ee_utils_py_to_r(utils_py$ee_path()) - email_clean <- gsub("@gmail.com", "", user) + user_clean <- gsub("@gmail.com", "", user) - if (email == 'not_defined') { - email_clean <- 'ndef' + if (user == 'not_defined') { + user_clean <- 'ndef' } - path_to_delete <- sprintf("%s/%s", ee_path, email_clean) + path_to_delete <- sprintf("%s/%s", ee_path, user_clean) if (!dir.exists(path_to_delete)) { if (!quiet) { @@ -32,7 +32,7 @@ ee_clean_credentials <- function(user='not_defined', quiet = FALSE) { if (!quiet && dir.exists(path_to_delete)) { cat( sprintf("Credentials in %s has been deleted.\n", - sprintf("%s/%s", ee_path, email_clean))) + sprintf("%s/%s", ee_path, user_clean))) } unlink(x = path_to_delete, recursive = TRUE, force = TRUE) diff --git a/R/ee_install.R b/R/ee_install.R index 050b5b6d..5179b5dc 100755 --- a/R/ee_install.R +++ b/R/ee_install.R @@ -224,7 +224,7 @@ ee_install <- function(py_env = "rgee", ) reticulate::py_install( - packages = c("earthengine-api", "numpy", "ee_extra"), + packages = c("earthengine-api", "numpy"), envname = rgee_path ) @@ -455,8 +455,8 @@ ee_install_upgrade <- function(version = NULL, earthengine_env = Sys.getenv("EARTHENGINE_ENV")) { if (earthengine_env == "") { stop( - "ee_install_upgrade needs that global env EARTHENGINE_ENV", - " is defined to work. Run ee_install_set_pyenv(py_env = \"YOUR_ENV\")", + "ee_install_upgrade needs to define EARTHENGINE_ENV.\n", + "Run ee_install_set_pyenv(py_env = \"YOUR_ENV\")", " to set a Python environment." ) } @@ -465,7 +465,7 @@ ee_install_upgrade <- function(version = NULL, } reticulate::py_install( packages = c(sprintf("earthengine-api==%s", version)), - envname = Sys.getenv("EARTHENGINE_ENV") + envname = earthengine_env ) title <- paste( "", diff --git a/R/ee_module.R b/R/ee_module.R index 5a1d7180..fcea57d9 100755 --- a/R/ee_module.R +++ b/R/ee_module.R @@ -20,55 +20,3 @@ #' } #' @export ee <- NULL - - -#' Extra Earth Engine dictionary -#' -#' Interface to Extra Earth Engine module. Provides access to the top level -#' classes and functions as well as sub-modules (e.g. \code{ee$Image}, -#' \code{ee$FeatureCollection$first}, etc.). -#' -#' @format Earth Engine module -#' -#' @examples -#' \dontrun{ -#' library(rgee) -#' library(rgeeExtra) -#' -#' # ee_install_extra() -#' ee_Initialize() -#' -#' ee_img1 <- ee$Image(0) -#' ee_img2 <- ee$Image(0) -#' -#' ee_img3 <- ee_img1 * ee_img2 + ee_img2 -#' print(ee_img3) -#' } -#' @export -.__Extra__ <- NULL - - -#' Extra Earth Engine module -#' -#' Interface to Extra Earth Engine module. Provides access to the top level -#' classes and functions as well as sub-modules (e.g. \code{ee$Image}, -#' \code{ee$FeatureCollection$first}, etc.). -#' -#' @format Earth Engine module -#' -#' @examples -#' \dontrun{ -#' library(rgee) -#' library(rgeeExtra) -#' -#' # ee_install_extra() -#' ee_Initialize() -#' -#' ee_img1 <- ee$Image(0) -#' ee_img2 <- ee$Image(0) -#' -#' ee_img3 <- ee_img1 * ee_img2 + ee_img2 -#' print(ee_img3) -#' } -#' @export -.__Extra_module__ <- NULL diff --git a/R/zzz.R b/R/zzz.R index 8f02a5b1..e543454e 100755 --- a/R/zzz.R +++ b/R/zzz.R @@ -9,10 +9,7 @@ # Sys.setenv(RETICULATE_PYTHON = earthengine_python) # delay load earthengine-api - #ee <<- reticulate::import("ee", delay_load = TRUE) - ee <<- reticulate::import("ee", delay_load = list(priority = 30)) + ee <<- reticulate::import("ee", delay_load = TRUE) + #ee <<- reticulate::import("ee", delay_load = list(priority = 30)) - # delay load eeExtra - .__Extra_module__ <<- reticulate::import("ee_extra", delay_load = list(priority = 40)) - .__Extra__ <<- .__Extra_module__$Extra } diff --git a/man/dot-__Extra__.Rd b/man/dot-__Extra__.Rd deleted file mode 100644 index 4abbf75c..00000000 --- a/man/dot-__Extra__.Rd +++ /dev/null @@ -1,33 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ee_module.R -\docType{data} -\name{.__Extra__} -\alias{.__Extra__} -\title{Extra Earth Engine dictionary} -\format{ -Earth Engine module -} -\usage{ -.__Extra__ -} -\description{ -Interface to Extra Earth Engine module. Provides access to the top level -classes and functions as well as sub-modules (e.g. \code{ee$Image}, -\code{ee$FeatureCollection$first}, etc.). -} -\examples{ -\dontrun{ -library(rgee) -library(rgeeExtra) - -# ee_install_extra() -ee_Initialize() - -ee_img1 <- ee$Image(0) -ee_img2 <- ee$Image(0) - -ee_img3 <- ee_img1 * ee_img2 + ee_img2 -print(ee_img3) -} -} -\keyword{datasets} diff --git a/man/dot-__Extra_module__.Rd b/man/dot-__Extra_module__.Rd deleted file mode 100644 index 3595548b..00000000 --- a/man/dot-__Extra_module__.Rd +++ /dev/null @@ -1,33 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ee_module.R -\docType{data} -\name{.__Extra_module__} -\alias{.__Extra_module__} -\title{Extra Earth Engine module} -\format{ -Earth Engine module -} -\usage{ -.__Extra_module__ -} -\description{ -Interface to Extra Earth Engine module. Provides access to the top level -classes and functions as well as sub-modules (e.g. \code{ee$Image}, -\code{ee$FeatureCollection$first}, etc.). -} -\examples{ -\dontrun{ -library(rgee) -library(rgeeExtra) - -# ee_install_extra() -ee_Initialize() - -ee_img1 <- ee$Image(0) -ee_img2 <- ee$Image(0) - -ee_img3 <- ee_img1 * ee_img2 + ee_img2 -print(ee_img3) -} -} -\keyword{datasets}