Skip to content

Commit

Permalink
rgeeExtra v.0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
csaybar committed Nov 23, 2023
1 parent 3ca1ad4 commit a31019b
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 126 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rgeeExtra
Title: Extensions for 'rgee'
Version: 0.0.2
Version: 0.1.0
Authors@R:
c(person(given = "Cesar",
family = "Aybar",
Expand Down Expand Up @@ -55,3 +55,4 @@ VignetteBuilder: knitr
Language: en-US
BugReports: https://github.com/r-earthengine/rgeeExtra/issues
URL: https://github.com/r-earthengine/rgeeExtra
Config/testthat/edition: 3
56 changes: 28 additions & 28 deletions R/ee_Image.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
#'
#' ee_Initialize()
#' extra_Initialize()
#'
#'
#' # Retrieve citation for the first image in NASA's IMERG V06 collection
#' citation <- ee$ImageCollection("NASA/GPM_L3/IMERG_V06")[[1]] %>%
#' citation <- ee$ImageCollection("NASA/GPM_L3/IMERG_V06")[[1]] %>%
#' ee$Image$Extra_getCitation()
#'
#'
#' # Display the citation
#' citation
#'
#'
#' # Fetching NASA/GPM_L3/IMERG_V06 image collection and retrieving its citation.
#' citation_ <- ee$ImageCollection("NASA/GPM_L3/IMERG_V06") %>%
#' ee$ImageCollection$Extra_getCitation()
#'
#'
#' # Display the citation
#' citation_
#' }
Expand Down Expand Up @@ -53,17 +53,17 @@ ee_image_getCitation <- function(x) {
#'
#' ee_Initialize()
#' extra_Initialize()
#'
#'
#' # Fetch DOI for first image in NASA IMERG V06 collection
#' doi <- ee$ImageCollection("NASA/GPM_L3/IMERG_V06")[[1]] %>%
#' doi <- ee$ImageCollection("NASA/GPM_L3/IMERG_V06")[[1]] %>%
#' ee$Image$Extra_getDOI()
#'
#' doi
#'
#' doi
#'
#' # Retrieve and print the DOI for the NASA/GPM_L3/IMERG_V06 image collection.
#' doi_ <- ee$ImageCollection("NASA/GPM_L3/IMERG_V06") %>%
#' ee$ImageCollection$Extra_getDOI()
#'
#'
#' doi_
#' }
ee_image_getDOI <- function(x) {
Expand Down Expand Up @@ -95,14 +95,14 @@ ee_image_getDOI <- function(x) {
#' # Retrieve offset parameters from the first image in NASA IMERG V06 collection
#' offset_params <- ee$ImageCollection("NASA/GPM_L3/IMERG_V06")[[1]] %>%
#' ee$Image$Extra_getOffsetParams()
#'
#'
#' # Display offset parameters for each band.
#' offset_params
#'
#' # Get offset parameters from NASA IMERG V06 image collection.
#' offset_params_ <- ee$ImageCollection("NASA/GPM_L3/IMERG_V06") %>%
#' ee$ImageCollection$Extra_getOffsetParams()
#'
#'
#' # Display offset parameters for each band.
#' offset_params_
#' }
Expand Down Expand Up @@ -130,18 +130,18 @@ ee_Image_getOffsetParams <- function(x) {
#'
#' ee_Initialize()
#' extra_Initialize()
#'
#'
#' # Retrieve scale parameters from the first image in NASA IMERG V06 collection
#' scale_params <- ee$ImageCollection("NASA/GPM_L3/IMERG_V06")[[1]] %>%
#' ee$Image$Extra_getScaleParams()
#'
#'
#' # Display scale parameters for each band in the image.
#' scale_params
#'
#'
#' # Retrieve scale parameters for the NASA IMERG V06 collection.
#' scale_params_ <- ee$ImageCollection("NASA/GPM_L3/IMERG_V06") %>%
#' ee$Image$Extra_getScaleParams()
#'
#'
#' # Display scale parameters for each band in the image.
#' scale_params_
#' }
Expand Down Expand Up @@ -170,13 +170,13 @@ ee_Image_getScaleParams <- function(x) {
#' # Retrieve STAC metadata for the first image in NASA's GPM L3 IMERG V06 collection
#' stac_metadata <- ee$ImageCollection("NASA/GPM_L3/IMERG_V06")[[1]] %>%
#' ee$Image$Extra_getSTAC()
#'
#'
#' stac_metadata
#'
#'
#' # Retrieve STAC metadata from NASA's IMERG V06 image collection.
#' stac_metadata_ <- ee$ImageCollection("NASA/GPM_L3/IMERG_V06") %>%
#' ee$ImageCollection$Extra_getSTAC()
#'
#'
#' stac_metadata_
#' }
ee_Image_getSTAC <- function(x) {
Expand Down Expand Up @@ -261,7 +261,7 @@ ee_Image_matchHistogram <- function(image, target, bands, geometry=NULL, maxBuck
#' # Load a Sentinel-2 image and apply automated preprocessing.
#' img <- ee$Image("COPERNICUS/S2_SR/20170328T083601_20170328T084228_T35SQA") %>%
#' ee$Image$Extra_preprocess()
#'
#'
#' # Load and preprocess Sentinel-2 SR image collection.
#' ic <- ee$ImageCollection$Dataset$COPERNICUS_S2_SR %>%
#' ee$ImageCollection$Extra_preprocess()
Expand Down Expand Up @@ -319,7 +319,7 @@ ee_Image_preprocess <- function(x, ...) {
#'
#' s2_indices <- ee$ImageCollection("COPERNICUS/S2_SR") %>%
#' ee$ImageCollection$first() %>%
#' ee$Image$preprocess() %>%
#' ee$Image$Extra_preprocess() %>%
#' ee$Image$Extra_spectralIndex(c("NDVI", "SAVI"))
#'
#' names(s2_indices)
Expand Down Expand Up @@ -365,21 +365,21 @@ ee_Image_spectralIndex <- function(
#' as properties of the sharpened Image.
#'
#' @param x An ee$Image object, the image to sharpen.
#' @param ... Additional arguments including sharpening method, quality
#' assessments, and parameters for `ee.Image.reduceRegion()`.
#' @param ... Additional arguments including sharpening method, quality
#' assessments, and parameters for `ee.Image.reduceRegion()`.
#' See details for more information.
#'
#' @details
#' The `...` argument can include the following:
#' \itemize{
#' \item{method}{Character. The sharpening algorithm to apply. Options include “SFIM”,
#' \item{method}{Character. The sharpening algorithm to apply. Options include “SFIM”,
#' “HPFA”, “PCS”, and “SM”. Default is “SFIM”.}
#' \item{qa}{Character. One or more quality assessment names to apply after sharpening,
#' \item{qa}{Character. One or more quality assessment names to apply after sharpening,
#' such as “MSE”, “RASE”, “UIQI”, etc.}
#' \item{geometry, maxPixels, bestEffort, etc.}{Arguments passed to `ee.Image.reduceRegion()`
#' \item{geometry, maxPixels, bestEffort, etc.}{Arguments passed to `ee.Image.reduceRegion()`
#' during PCS sharpening and quality assessments.}
#' }
#' For the PCS method, additional parameters for `ee.Image.reduceRegion()` can be specified,
#' For the PCS method, additional parameters for `ee.Image.reduceRegion()` can be specified,
#' such as `geometry`, `maxPixels`, `bestEffort`, etc.
#'
#' @return The Image with all sharpenable bands sharpened to the
Expand Down Expand Up @@ -578,7 +578,7 @@ ee_Image_tasseledCap <- function(x) {
#' # Adjust first image in NASA IMERG V06 for scale and offset.
#' adjusted_image <- ee$ImageCollection("NASA/GPM_L3/IMERG_V06")[[1]] %>%
#' ee$Image$Extra_scaleAndOffset()
#'
#'
#' # Adjust Sentinel-2 SR images for scale and offset.
#' adjusted_images <- ee$ImageCollection("COPERNICUS/S2_SR") %>%
#' ee$ImageCollection$Extra_scaleAndOffset()
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@

## **Why rgeeExtra is needed?** 🤔

The aim of rgeeExtra is to enhance the ease-of-use ⚡ of Google Earth Engine (GEE) 🌐 for R enthusiasts by streamlining its syntax and enriching the R user experience. While GEE's primary language is JavaScript, which diverges from R's structure, rgeeExtra serves as a bridge 🌉, offering R users a suite of tools and functions to navigate GEE's complexity with ease. This extension elevates R interaction with GEE through high-level 📈 abstractions and tailored functions, all adapted from the JavaScript API.

The goal of rgeeExtra is to enhance the user experience ⚡ of Google Earth Engine (GEE) 🌐 for R enthusiasts by simplifying its syntax. While GEE's primary language is JavaScript, which diverges from R's structure, rgeeExtra serves as a bridge 🌉, offering R users a suite of tools and functions to navigate GEE's complexity with ease. This extension elevates R interaction with GEE through high-level 📈 abstractions and tailored functions, all adapted from the JavaScript API.

<table>
<tr>
Expand Down Expand Up @@ -115,6 +114,8 @@ You can install rgeeExtra from [GitHub](https://github.com/r-earthengine/rgeeExt
remotes::install_github("r-earthengine/rgeeExtra")
```

For additional details on connecting GEE and R, refer to the documentation provided [here](https://github.com/r-spatial/rgee#installation). To set up an account, click [here](https://earthengine.google.com/signup/).

## **How does it work?️** 🛠

The rgeeExtra extends the following Earth Engine classes:
Expand All @@ -125,7 +126,7 @@ The rgeeExtra extends the following Earth Engine classes:
- [ee\$Image](https://developers.google.com/earth-engine/guides/image_overview)
- [ee\$ImageCollection](https://developers.google.com/earth-engine/guides/ic_creating)

rgeeExtra develops and maintains new methods and constructors that extend the most popular GEE classes (e.g., `ee$Feature$Extra\_...`). All third-party methods implemented by rgeeExtra start with `Extra\_.` To learn more about all the functionalities that rgeeExtra offers, please refer to the article [Features] for additional information.
rgeeExtra develops and maintains new methods and constructors that extend the most popular GEE classes (e.g., `ee$Feature$Extra\_...`). All third-party methods implemented by rgeeExtra start with `Extra\_.` To learn more about all the functionalities that rgeeExtra offers, please refer to the article [Features](https://r-earthengine.com/rgeeExtra/articles/) for additional information.

## **Example** 💡

Expand Down Expand Up @@ -168,7 +169,7 @@ extra_Initialize()
# Compute squared NDVI from Landsat 8 image
img <- ee$Image("LANDSAT/LC08/C02/T1_L2/LC08_007067_20140822")
ndvi <- ((img[["SR_B5"]] - img[["SR_B4"]]) / (img[["SR_B5"]] + img[["SR_B4"]])) ** 2
names(ndvi) <- "Squared NDVI"
names(ndvi) <- "NDVI"

# Visualize squared NDVI on map
Map$centerObject(ndvi)
Expand All @@ -183,7 +184,7 @@ Map$addLayer(
)
```

<center><img src="man/figures/ndvi_example.png" width="80%"/></center>
<center><img src="inst/ndvi_example.png" width="80%"/></center>

## **Code of Conduct** 📜

Expand Down Expand Up @@ -221,4 +222,4 @@ A BibTeX entry for LaTeX users is

We would like to mention the following third-party R/Python packages for contributing indirectly to the improvement of rgeeExtra:

- [**eemont - David Montero Loaiza**](https://github.com/davemlz/eemont)
- [**eemont - David Montero Loaiza**](https://github.com/davemlz/eemont)
Binary file added inst/ndvi_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion man/ee-citation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/ee-getdoi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ee_Image_spectralIndex.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(rgee)
library(rgeeExtra)
library(stars)
library(sf)

if (identical(Sys.getenv("NOT_CRAN"), "true")) {
test_check("rgeeExtra")
}


test_check("rgeeExtra")
19 changes: 8 additions & 11 deletions tests/testthat/test-eeImageCollection.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("rgee: ImageCollection simple test")
# -------------------------------------------------------------------------
library(rgee)
library(rgeeExtra)

Expand All @@ -11,50 +9,49 @@ test_that("ee$ImageCollection$Extra_closest", {
ee$ImageCollection$Dataset$MODIS_006_MCD12Q1 %>%
ee$ImageCollection$Extra_closest("2020-10-15", 2, "year") %>%
ee$ImageCollection$first() -> ee_img
expect_is(ee_img, "ee.image.Image")
expect_s3_class(ee_img, "ee.image.Image")
})


test_that("ee$ImageCollection$Extra_getCitation", {
ee$ImageCollection("NASA/GPM_L3/IMERG_V06") %>%
ee$ImageCollection$Extra_getCitation() -> eestr
expect_is(eestr, "character")
expect_type(eestr, "character")
})

test_that("ee$ImageCollection$Extra_getDOI", {
ee$ImageCollection("NASA/GPM_L3/IMERG_V06") %>%
ee$ImageCollection$Extra_getDOI() -> eestr
expect_is(eestr, "character")
expect_type(eestr, "character")
})

test_that("ee$ImageCollection$Extra_getOffsetParams", {
ee$ImageCollection("NASA/GPM_L3/IMERG_V06") %>%
ee$ImageCollection$Extra_getOffsetParams() -> eelist
expect_is(eelist, "list")
expect_type(eelist, "list")
})

test_that("ee$ImageCollection$Extra_getScaleParams", {
ee$ImageCollection("NASA/GPM_L3/IMERG_V06") %>%
ee$ImageCollection$Extra_getScaleParams() -> eelist
expect_is(eelist, "list")
expect_type(eelist, "list")
})

test_that("ee$ImageCollection$Extra_getSTAC", {
ee$ImageCollection("NASA/GPM_L3/IMERG_V06") %>%
ee$ImageCollection$Extra_getSTAC() -> eelist
expect_is(eelist, "list")
expect_type(eelist, "list")
})

test_that("ee$ImageCollection$Extra_preprocess", {
ee$ImageCollection("COPERNICUS/S2_SR") %>%
ee$ImageCollection$Extra_preprocess() -> eeic
expect_is(eeic, "ee.imagecollection.ImageCollection")
expect_s3_class(eeic, "ee.imagecollection.ImageCollection")
})

test_that("ee$ImageCollection$Extra_scaleAndOffset", {
ee$ImageCollection("COPERNICUS/S2_SR") %>%
ee$ImageCollection$Extra_preprocess()%>%
ee$ImageCollection$Extra_scaleAndOffset() -> eeic
expect_is(eeic, "ee.imagecollection.ImageCollection")
expect_s3_class(eeic, "ee.imagecollection.ImageCollection")
})

6 changes: 1 addition & 5 deletions tests/testthat/test-ee_gif.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
context("rgee: ee_gif simple test")
# -------------------------------------------------------------------------


library(rgee)
library(rgeeExtra)

Expand Down Expand Up @@ -54,5 +50,5 @@ test_that("ee_utils_gif_creator", {
animation_wtxt
gc(reset = TRUE)
ee_utils_gif_save(animation_wtxt, path = paste0(tempfile(), ".gif"))
expect_is(animation_wtxt, "magick-image")
expect_s3_class(animation_wtxt, "magick-image")
})
Loading

0 comments on commit a31019b

Please sign in to comment.