Giter Club home page Giter Club logo

rgeeextra's Introduction


rgeeExtra: An Extension for rgee

Simplifies the interaction with the GEE API making it more R-like. Popular third-party GEE algorithms are made available to R users

Open in Colab Project Status: Active – The project has reached a stable, usable state and is being actively developed. License lifecycle status CRAN status DOI

InstallationHow does it work?ExampleCode of conductContributingCitationCredits

Why rgeeExtra is needed? 🤔

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.

Python (ee) R (rgee) R (rgee + rgeeExtra)
import ee
ee.Initialize()
db = 'CGIAR/SRTM90_V4'
image = ee.Image(db)
image.bandNames().getInfo()
#> [u'elevation']
library(rgee)
ee_Initialize()
db <- 'CGIAR/SRTM90_V4'
image <- ee$Image(db)
image$bandNames()$getInfo()
#> [1] "elevation"
library(rgee)
library(rgeeExtra)

ee_Initialize()
extra_Initialize()

image <- ee$Image$Dataset$CGIAR_SRTM90_V4
names(image)
#> [1] "elevation"

Installation 🚀

You can install rgeeExtra from GitHub with:

remotes::install_github("r-earthengine/rgeeExtra")

For additional details on connecting GEE and R, refer to the documentation provided here. To set up an account, click here.

How does it work?️ 🛠

The rgeeExtra extends the following Earth Engine classes:

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.

Example 💡

Look at this simple example to estimate the NDVI from a Landsat-8 Surface Reflectance image.

With rgee:

# Load 'rgee' and initialize GEE
library(rgee)
ee_Initialize()

# Compute squared NDVI from Landsat 8 image
img <- ee$Image("LANDSAT/LC08/C02/T1_L2/LC08_007067_20140822")$
  normalizedDifference(c("SR_B5", "SR_B4"))$
  pow(2)

# Visualize squared NDVI on map
Map$centerObject(img)
Map$addLayer(
  eeObject = img, 
  visParams = list(
    min = 0, 
    max = 0.2, 
    palette = c("brown", "yellow", "green")
    ),
  name = "Squared NDVI")

With rgeeExtra:

# Load 'rgee' and initialize GEE
library(rgee)
library(rgeeExtra)

ee_Initialize()
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) <- "NDVI"

# Visualize squared NDVI on map
Map$centerObject(ndvi)
Map$addLayer(
  eeObject = ndvi, 
  visParams = list(
    min = 0, 
    max = 0.2, 
    palette = c("brown", "yellow", "green")
    ),
  name = "Squared NDVI"
  )

Code of Conduct 📜

Please note that the rgeeExtra project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Contributing Guide 🤝

👍 Thanks for taking the time to contribute! 🎉👍 Please review our Contributing Guide.

Share the love ❤️

Think rgeeExtra is useful? Let others discover it, by telling them in person via Twitter or a blog post.

Using rgeeExtra for a paper you are writing? Consider citing it

citation("rgeeExtra")
To cite rgee in publications use:
  
  C Aybar, Q Wu, L Bautista, R Yali and A Barja (2020) rgee: An R
  package for interacting with Google Earth Engine Journal of Open
  Source Software URL https://github.com/r-spatial/rgee/.

A BibTeX entry for LaTeX users is

@Article{,
  title = {rgee: An R package for interacting with Google Earth Engine},
  author = {Cesar Aybar and Quisheng Wu and Lesly Bautista and Roy Yali and Antony Barja},
  journal = {Journal of Open Source Software},
  year = {2020},
}

Credits 👏

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

rgeeextra's People

Contributors

csaybar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rgeeextra's Issues

Issue with py module ee_extra

Hi,
I'm trying to use the rgeeExtra::module function to import a .js module. Here's my code:

library(rgee)
library(rgeeExtra)
ee_Initialize("gtyreegee")
x <- "users/gtyreegee/MODIS_006_MCD19A2:Modules/RAP_LC_Bins_Module.js"
getRAPstrata <- module(x)

When I run the code, I get the error: "Python module ee_extra was not found." However, I checked my py conda environment and ee_extra is installed as:
ee_extra; 0.0.12; pyhd8ed1ab_0; conda-forge

Has this issue come up before, and if so, how was it solved?

I'm using rgee version 1.1.2, rgeeExtra version 0.0.1 in RStudio 1.4.1717.

problem rgeeExtra

with rgee Initialized:

library(rgee)
ee_Initialize( drive =T)

── rgee 1.1.5 ──────────────────────────────────────────────────── earthengine-api 0.1.323 ──
✔ user: not_defined
✔ Google Drive credentials: FOUND
✔ Initializing Google Earth Engine: DONE!
✔ Earth Engine account: users/xxxxxxx
────────────────────────────────────────────────────────────────────────────────
I installed remotes::install_github("r-earthengine/rgeeExtra")

everything worked fine.

but no function could be find:

>library(rgeeExtra)
> ee_ImageCollection_scaleAndOffset()
Error in ee_ImageCollection_scaleAndOffset() : 
could not find function "ee_ImageCollection_scaleAndOffset"

> ee_ImageCollection_spectralIndex()
Error in ee_ImageCollection_spectralIndex() : 
  could not find function "ee_ImageCollection_spectralIndex"

version
platform x86_64-w64-mingw32
arch x86_64
os mingw32
crt ucrt
system x86_64, mingw32
status
major 4
minor 2.2
year 2022
month 10
day 31
svn rev 83211
language R
version.string R version 4.2.2 (2022-10-31 ucrt)
nickname Innocent and Trusting

Failing to get spectral indexes

Hello,

I am trying to get spectral indexes using the function ee$Image$spectralIndex() without success.

# Load libraries
library(rgee)
library(rgeeExtra)

# Initialize Earth Engine
ee_Initialize()
extra_Initialize()

## Attempt 1: copied from rgee book ----

ds <- 'LANDSAT/LC08/C01/T1_SR'

ee$ImageCollection(ds) %>% 
  ee_ImageCollection_scaleAndOffset() %>% 
  ee_ImageCollection_spectralIndex(c('NDVI', 'GNDVI', 'NDSI'))

# Error in ee_ImageCollection_spectralIndex(., c("NDVI", "GNDVI", "NDSI")) : 
#   could not find function "ee_ImageCollection_spectralIndex"

## Attempt 2: copied from function reference ----

s2_indices <- ee$ImageCollection("COPERNICUS/S2_SR") %>%
  ee$ImageCollection$first() %>%
  ee$Image$preprocess()%>%
  ee$Image$spectralIndex(c("NDVI", "SAVI"))

# Error in EEextra_PYTHON_PACKAGE$QA : 
#   RuntimeError: $ operator is invalid for atomic vectors

## Attempt 3 ----

## Get an image (works)
s2_img <- ee$ImageCollection("COPERNICUS/S2_SR") %>% 
  ee$ImageCollection$first()

## Preprocess (no not work)
ee$Image$preprocess(s2_img)

#Error in EEextra_PYTHON_PACKAGE$Spectral : 
#  RuntimeError: $ operator is invalid for atomic vectors

## Get spectral indexes (do not work)
ee$Image$spectralIndex(s2_img)

#Error in EEextra_PYTHON_PACKAGE$Spectral : 
#  RuntimeError: $ operator is invalid for atomic vectors

I am working with R 4.3.1, RStudio 2023.06.1, rgee version 1.1.7 and rgeeExtra development version.

Issue with REGEX

Hi!
Amazing features. RgeeExtra is exactly what I have searching for.

But I am facing something similar to gltyree into other issue description.
When i run the example:

library(rgee)
library(rgeeExtra)
library(reticulate)
ee_Initialize()
x <- "users/sofiaermida/landsat_smw_lst:modules/Landsat_LST.js"
LandsatLST <- module(x)

I get:

LandsatLST <- module(x)
Installing Js module in: C:/Users/marib/Documents/R/win-library/4.1/rgeeExtra/ee_extra/ee_extra/ee-sources
Error in py_call_impl(callable, dots$args, dots$keywords) :
ImportError: "regex" is not installed. Please install "regex" -> "pip install regex"

#traceback
7. stop(structure(list(message = "ImportError: "regex" is not installed. Please install "regex" -> "pip install regex"\n",
call = py_call_impl(callable, dots$args, dots$keywords),
cppstack = NULL), class = c("Rcpp::exception", "C++Error",
"error", "condition")))
6. EEextra_PYTHON_PACKAGE$require(x)
5. value[3L]
4. tryCatchOne(expr, names, parentenv, handlers[[1L]])
3. tryCatchList(expr, classes, parentenv, handlers)
2. tryCatch(expr = EEextra_PYTHON_PACKAGE$require(x), error = function(e) {
EEextra_PYTHON_PACKAGE$install(x = x, update = upgrade, quiet = TRUE)
if (!quiet) {message(sprintf("Installing Js module in: %s", ee_install$"_get_ee_sources_path"())) ...

  1. module(x)

But I have installed Regex:
#Anaconda prompt

(base) C:\Users\marib>pip install regex
Requirement already satisfied: regex in c:\users\marib\appdata\local\r-miniconda\lib\site-packages (2022.6.2)

I'm a using rgee 1.1.3, rgeeExtra 0.0.1, reticulate 1.25, R version 4.1.3, RStudio 2022.02.0+443, Windows 10.
Do you know how to fix it? I think this is something to do with the folder where REGEX is installed but I don't know how to deal with it.

Thanks a lot.

rgeeExtra::module() returns 404 error

Hey there! Having initialized GEE successfully, I cannot seem to load js modules using rgeeExtra::module(). My problem is similar to the one described in issue 6, but since that has remained unchanged for about a year, I opened this new issue. Here's a reprex:

library(rgee)
library(rgeeExtra)
library(reticulate)

ee_Initialize() # initialize gee
#> ── rgee 1.1.5 ─────────────────────────────────────── earthengine-api 0.1.323 ── 
#>  ✔ user: not_defined
#>  ✔ Initializing Google Earth Engine: ✔ Initializing Google Earth Engine:  DONE!
#>  ✔ Earth Engine account: users/MathiasWeidinger 
#> ────────────────────────────────────────────────────────────────────────────────

reticulate::py_install(packages=c("regex", "ee_extra", "jsbeautifier")) # install necessary python packages
#> Using virtual environment '/home/madmat/.virtualenvs/rgee' ...
#> + '/home/madmat/.virtualenvs/rgee/bin/python' -m pip install --upgrade --no-user 'regex' 'ee_extra' 'jsbeautifier'

x <- "users/andreim/geeMonitor:monitor.js"

engine <- rgeeExtra::module(x)
#> HTTP Error 404: Not Found

I tried loading in other modules with the same result. Still, from my side everything seems to be up to date and otherwise rgee is working as expected. Any ideas what might be going wrong?

Cheers!

readme

Hey @csaybar great work as always! I noticed a few things when I started working with the package in regards to the Readme and thought I'd give a shout. Just a few things with the example. So nice to be able to index now and use the operators! Take care.

library(rgee)

ee_Initialize()

img <- ee$Image("LANDSAT/LC08/C01/T1_SR/LC08_038029_20180810")
ndvi <- (img[["B5"]] - img[["B4"]])/(img[["B5"]] + img[["B4"]])**2
names(ndvi) <- "pow_ndvi"

Map$centerObject(img,zoom=12)
Map$addLayer(img)

potential edits

library(rgee)
library(rgeeExtra) #add library call

ee_Initialize()

img <- ee$Image("LANDSAT/LC08/C01/T1_SR/LC08_038029_20180810")
ndvi <- (img[["B5"]] - img[["B4"]])/(img[["B5"]] + img[["B4"]])**2
names(ndvi) <- "pow_ndvi"

# here just add ndvi instead of image and also some visParams for the image with power.
Map$centerObject(ndvi,zoom=12)
Map$addLayer(ndvi, visParams = list(min = -0.001, max = 0.001)

translate fail in image overview - I

CASE:

var loadedImage = ee.Image('JAXA/ALOS/AW3D30/V2_2');
var first = ee.ImageCollection('COPERNICUS/S2_SR')
                .filterBounds(ee.Geometry.Point(-70.48, 43.3631))
                .filterDate('2019-01-01', '2019-12-31')
                .sort('CLOUDY_PIXEL_PERCENTAGE')
                .first();
var uri = 'gs://gcp-public-data-landsat/LC08/01/001/002/' +
    'LC08_L1GT_001002_20160817_20170322_01_T2/' +
    'LC08_L1GT_001002_20160817_20170322_01_T2_B5.TIF';
var cloudImage = ee.Image.loadGeoTIFF(uri);

GOT:

 Error in py_call_impl(callable, dots$args, dots$keywords) : 
 InvalidInput: Cannot parse: 17:54: uri = 'gs:#gcp-public-data-landsat/LC08/01/001/002/' + 

Trouble with rgeeExtra install

Hi, I want to use rgeeExtra to import Javascript modules from GEE, as described in r-spatial/rgee issue #155 (r-spatial/rgee#155). I have successfully downloaded the required version of reticulate (1.22.9000) but I am having difficulty downloading the rgeeExtra package. Below is my code and the output.

remotes::install_github("r-earthengine/rgeeExtra")

Downloading GitHub repo r-earthengine/rgeeExtra@HEAD
Error: Failed to install 'rgeeExtra' from GitHub:
Git does not seem to be installed on your system.
In addition: Warning message:
In readLines(file) :
incomplete final line found on 'C:\Users\Gtyree\AppData\Local\Temp\RtmpSSb4xZ\remotesd228626324ba/r-earthengine-rgeeExtra-a14ee7c/.gitmodules'

I attempted to solve the issue by installing Git, but after I did that I began to experience the issue described in r-spatial/rgee issue #91 (r-spatial/rgee#91). It's possible that the problem was unrelated to Git, but was only solved after I both uninstalled Git and ran this code:

library(rgee)
library(reticulate)
earthengine_python <- Sys.getenv("EARTHENGINE_PYTHON", unset = NA)
Sys.setenv(RETICULATE_PYTHON = earthengine_python)
reticulate::py_config()

Is there a way to install rgeeExtra that doesn't require Git? I have also tried devtools::install_github("r-earthengine/rgeeExtra") but received the same error message.

I am using RStudio v. 1.4.1717 on a Windows 10 computer.

rgeeExtra - "has no attribute" error

Hi csaybar,

I can not make it to work, every time I tried I get this kind of error. rgee works great.

Error in py_get_attr_impl(x, name, silent) :
AttributeError: type object 'Image' has no attribute 'getDOI'
Run reticulate::py_last_error() for details.

I's like so with other like "spectralIndex" e.g
Are there any python dependencies for rgeeExtra to work?. Do you have any idea of what is the problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.