rgee icon indicating copy to clipboard operation
rgee copied to clipboard

ee_Initialize() failed in rgee but not Python

Open treetexan opened this issue 3 years ago • 1 comments

  • rgee version: rgee_1.1.5
  • R version: R version 4.0.3 (2020-10-10)
  • Operating System: Windows 10

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

  • [ Y] You have the Python API installed (from terminal):
earthengine -h
  • [Y] You can find the credentials file on your system:
library(rgee)
ee_path <- path.expand("~/.config/earthengine/credentials")
file.exists(ee_path)
  • [NO] You can run a simple EE command from R:
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: C:/anaconda/envs/ee/python.exe libpython: C:/anaconda/envs/ee/python38.dll pythonhome: C:/anaconda/envs/ee version: 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 05:59:45) [MSC v.1929 64 bit (AMD64)] Architecture: 64bit numpy: C:/anaconda/envs/ee/Lib/site-packages/numpy numpy_version: 1.23.1 ee: C:\anaconda\envs\ee\lib\site-packages\ee_init_.p

NOTE: Python version was forced by RETICULATE_PYTHON

Description

I am using a university gmail account (ending in .edu) to access Earth Engine. I can't get Rgee to use gcloud (see output below). Python GEE API is working fine, with gcloud installed, and I am able to run GEE code (like ee.Initialize).

I see three potential issues. One, your ee_Initialize() function appears to try to deduce my email by subtracting @gmail.com (why don't you use unlist(strsplit()) on the @ symbol instead, and take the first element?). Two, I think it keeps trying to look for my credential in a subfolder, and making empty subfolders (ndef) when it can't find it. Not sure why. Finally, I had to authenticate via the notebook auth_mode method to create my credential file, which now works fine in Python. However, since I think you ask ee_Initialize() to do earthengine authenticate each time it runs ee_Initialize(), I believe it's possible keeps trying to use the "gcloud" method and failing.

oddly, when I just run rgee::ee$Initialize() it runs without error and I can run the simple rgee code above. This is the same behavior I get in Python. does that mean I can avoid running ee_Initialize() and just run rgee::ee$Initialize(), without error down the line?

Your code in ee_Initialize() for the first two issues: email_clean <- gsub("@gmail.com", "", user) ee_path <- ee_utils_py_to_r(ee_utils$ee_path()) ee_path_user <- sprintf("%s/%s", ee_path, email_clean) dir.create(ee_path_user, showWarnings = FALSE, recursive = TRUE) unlink(list.files(ee_path, "@gmail.com", full.names = TRUE)) unlink(list.files(ee_path, ".json", full.names = TRUE))

What I Did

> library(rgee)
> ee_Initialize()
── rgee 1.1.5 ────────────────────────────────────────────────────────── earthengine-api 0.1.324 ── 
 ✔ user: not_defined
 ✔ Initializing Google Earth Engine:Fetching credentials using gcloud
Error in py_call_impl(callable, dots$args, dots$keywords) : 
  Exception: gcloud failed. Please check for any errors above and install gcloud if needed.
> rgee::ee$Initialize()
> 

treetexan avatar Sep 29 '22 03:09 treetexan

Hi, @treetexan can you share a traceback()?

idk for my regex is more readable, but a PR is always welcome ;)

(why don't you use unlist(strsplit()) on the @ symbol instead, and take the first element?)

I don't think your .edu email is a problem. The code you attached is only for creating a folder.

Your code in ee_Initialize() for the first two issues: email_clean <- gsub("@gmail.com", "", user) ee_path <- ee_utils_py_to_r(ee_utils$ee_path()) ee_path_user <- sprintf("%s/%s", ee_path, email_clean) dir.create(ee_path_user, showWarnings = FALSE, recursive = TRUE) unlink(list.files(ee_path, "@gmail.com", full.names = TRUE)) unlink(list.files(ee_path, ".json", full.names = TRUE))

I can't reproduce the error, if you have any idea how to improve the ee_Initialize syntax please let us know!

csaybar avatar Oct 01 '22 18:10 csaybar