r-spatial / rgee

Google Earth Engine for R
https://r-spatial.github.io/rgee/
Other
677 stars 146 forks source link

Running in a non-interactive framework #317

Open bmaitner opened 1 year ago

bmaitner commented 1 year ago

At submit an issue, please attached the following information of your rgee session:

library(rgee)

# Initialize the Earth Engine module.
ee_Initialize()

# Print metadata for a DEM dataset.
print(ee$Image('USGS/SRTMGL1_003')$getInfo())

Attach your Python (reticulate) configuration:

library(reticulate)
py_config()

python:         /usr/bin/python3
libpython:      /usr/lib/python3.10/config-3.10-x86_64-linux-gnu/libpython3.10.so
pythonhome:     //usr://usr
version:        3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0]
numpy:          /usr/lib/python3/dist-packages/numpy
numpy_version:  1.21.5
ee:             /usr/local/lib/python3.10/dist-packages/ee

Description

Describe what you were trying to get done. Tell us what happened, what went wrong, and what you expected to happen.

First of all, thanks for this outstanding package!

I'm trying to run rgee via Github actions. Until recently, I was able to achieve this by: 1) Encrypting my earth engine and drive credential via gpg 2) Saving the encrypted credentials in by Github repo 3) decrypting the credentials as part of a Github action workflow using secrets 4) calling rgee as usual

However, due to recent changes to googledrive (and maybe rgee?) , this approach no longer works. However, I think a few minor changes to rgee could make it easier to use in a non-interactive framework:

1) Add the option to use a JSON token for googledrive (per https://gargle.r-lib.org/articles/non-interactive-auth.html ) 2) Allow manual specification of the locations of credentials, for example via something like:


  create_rgee_creds_manual <- function(email = "ndef",
                                       user = NA,
                                       drive_cre = NA,
                                       gcs_cre = NA){

    ee_path <- rgee:::ee_utils_py_to_r(utils_py$ee_path())

    data.frame(email,user,drive_cre,gcs_cre) %>%
      write.table(
        file = sprintf("%s/rgee_sessioninfo.txt", ee_path),
        append = FALSE,
        row.names = FALSE

      )

I'm happy to help on this if it would be useful, and if it is outside the scope of what you planned for the package, I can always fork the repo and make the changes myself, but I thought I'd ask you first (in case this is something you had planned doing). Just let me know either way! :)

What I Did

 Happy to share code if it would be helpful, but this would amount to an entire targets workflow, including shell code that decrypts credentials and the rgee code itself (or I can point you to the Github repo in question).
csaybar commented 1 year ago

Hi, @bmaitner thank you for pointing it out.

I think this feature has a lot of sense. rgee is not very friendly in non-interactively environments. Please, feel free to send us a PR! I will happy to help if some parts of the code are not clear to you.