From b67d6787c8d128c8571df57cbd5fb9a08a80c12a Mon Sep 17 00:00:00 2001 From: Qiusheng Wu Date: Thu, 17 Oct 2024 14:07:39 -0500 Subject: [PATCH 1/4] Fix download_ee_image_tiles_parallel error (#2158) --- geemap/common.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/geemap/common.py b/geemap/common.py index 7a1c8d839e..8d9ea9acbf 100644 --- a/geemap/common.py +++ b/geemap/common.py @@ -12601,6 +12601,7 @@ def download_ee_image_tiles_parallel( column=None, job_args={"n_jobs": -1}, ee_init=True, + project_id=None, **kwargs, ): """Download an Earth Engine Image as small tiles based on ee.FeatureCollection. Images larger than the `Earth Engine size limit are split and downloaded as @@ -12637,6 +12638,7 @@ def download_ee_image_tiles_parallel( column (str, optional): The column name in the feature collection to use as the filename. Defaults to None. job_args (dict, optional): The arguments to pass to joblib.Parallel. Defaults to {"n_jobs": -1}. ee_init (bool, optional): Whether to initialize Earth Engine. Defaults to True. + project_id (str, optional): The Earth Engine project ID. Defaults to None. """ import joblib @@ -12668,7 +12670,10 @@ def download_ee_image_tiles_parallel( def download_data(index): if ee_init: - ee_initialize(opt_url="https://earthengine-highvolume.googleapis.com") + ee_initialize( + opt_url="https://earthengine-highvolume.googleapis.com", + project=project_id, + ) region = ee.Feature(collection.get(index)).geometry() filename = os.path.join( out_dir, "{}{}.tif".format(prefix, names[index].replace("/", "_")) From 41d7d026e6e557696189b333a183d80dc31afcc4 Mon Sep 17 00:00:00 2001 From: Qiusheng Wu Date: Sat, 2 Nov 2024 16:47:55 -0400 Subject: [PATCH 2/4] Simplify ee_initialize function (#2162) * Simplify ee_initialize function * Skip ee_initialize when not needed * Remove ee.data import --- geemap/coreutils.py | 87 +++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 63 deletions(-) diff --git a/geemap/coreutils.py b/geemap/coreutils.py index c5b9117ba6..0b5e8f0163 100644 --- a/geemap/coreutils.py +++ b/geemap/coreutils.py @@ -42,7 +42,6 @@ def get_env_var(key: str) -> Optional[str]: def ee_initialize( token_name: str = "EARTHENGINE_TOKEN", auth_mode: Optional[str] = None, - service_account: bool = False, auth_args: Optional[Dict[str, Any]] = None, user_agent_prefix: str = "geemap", project: Optional[str] = None, @@ -58,8 +57,6 @@ def ee_initialize( notebook, localhost, or gcloud. See https://developers.google.com/earth-engine/guides/auth for more details. Defaults to None. - service_account (bool, optional): If True, use a service account. - Defaults to False. auth_args (dict, optional): Additional authentication parameters for aa.Authenticate(). Defaults to {}. user_agent_prefix (str, optional): If set, the prefix (version-less) @@ -70,17 +67,33 @@ def ee_initialize( For example, opt_url='https://earthengine-highvolume.googleapis.com' to use the Earth Engine High-Volume platform. Defaults to {}. """ - import httplib2 + import google.oauth2.credentials from .__init__ import __version__ - if auth_args is None: - auth_args = {} - user_agent = f"{user_agent_prefix}/{__version__}" ee.data.setUserAgent(user_agent) - if "http_transport" not in kwargs: - kwargs["http_transport"] = httplib2.Http() + if ee.data._credentials is not None: + return + + ee_token = get_env_var(token_name) + if ee_token is not None: + + stored = json.loads(ee_token) + credentials = google.oauth2.credentials.Credentials( + None, + token_uri="https://oauth2.googleapis.com/token", + client_id=stored["client_id"], + client_secret=stored["client_secret"], + refresh_token=stored["refresh_token"], + quota_project_id=stored["project"], + ) + + ee.Initialize(credentials=credentials, **kwargs) + return + + if auth_args is None: + auth_args = {} if project is None: kwargs["project"] = get_env_var("EE_PROJECT_ID") @@ -97,60 +110,8 @@ def ee_initialize( auth_args["auth_mode"] = auth_mode - if ee.data._credentials is None: - ee_token = get_env_var(token_name) - if service_account: - try: - credential_file_path = os.path.expanduser( - "~/.config/earthengine/private-key.json" - ) - - if os.path.exists(credential_file_path): - with open(credential_file_path) as f: - token_dict = json.load(f) - else: - token_name = "EARTHENGINE_TOKEN" - ee_token = os.environ.get(token_name) - token_dict = json.loads(ee_token, strict=False) - service_account = token_dict["client_email"] - private_key = token_dict["private_key"] - - credentials = ee.ServiceAccountCredentials( - service_account, key_data=private_key - ) - ee.Initialize(credentials, **kwargs) - - except Exception as e: - raise Exception(e) - - else: - try: - if ee_token is not None: - credential_file_path = os.path.expanduser( - "~/.config/earthengine/credentials" - ) - if not os.path.exists(credential_file_path): - os.makedirs( - os.path.dirname(credential_file_path), exist_ok=True - ) - if ee_token.startswith("{") and ee_token.endswith( - "}" - ): # deals with token generated by new auth method (earthengine-api>=0.1.304). - token_dict = json.loads(ee_token) - with open(credential_file_path, "w") as f: - f.write(json.dumps(token_dict)) - else: - credential = ( - '{"refresh_token":"%s"}' % ee_token - ) # deals with token generated by old auth method. - with open(credential_file_path, "w") as f: - f.write(credential) - - ee.Initialize(**kwargs) - - except Exception: - ee.Authenticate(**auth_args) - ee.Initialize(**kwargs) + ee.Authenticate(**auth_args) + ee.Initialize(**kwargs) def get_info( From 824e4e5e3aa5d10b5224b9d38a6ce4311be11501 Mon Sep 17 00:00:00 2001 From: Qiusheng Wu Date: Sat, 2 Nov 2024 16:48:19 -0400 Subject: [PATCH 3/4] =?UTF-8?q?Bump=20version:=200.35.0=20=E2=86=92=200.35?= =?UTF-8?q?.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- geemap/__init__.py | 2 +- pyproject.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/geemap/__init__.py b/geemap/__init__.py index 9b5bcf0533..a9cf904b6d 100644 --- a/geemap/__init__.py +++ b/geemap/__init__.py @@ -2,7 +2,7 @@ __author__ = """Qiusheng Wu""" __email__ = "giswqs@gmail.com" -__version__ = "0.35.0" +__version__ = "0.35.1" import os diff --git a/pyproject.toml b/pyproject.toml index 1362ac5b81..f7f21840cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "geemap" -version = "0.35.0" +version = "0.35.1" description = "A Python package for interactive mapping using Google Earth Engine and ipyleaflet" readme = "README.md" requires-python = ">=3.9" @@ -143,7 +143,7 @@ universal = true [tool.bumpversion] -current_version = "0.35.0" +current_version = "0.35.1" commit = true tag = true From f0c19506a29bd6990107dfc7a7f2e72e3e8151a7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 Nov 2024 19:23:39 -0500 Subject: [PATCH 4/4] [pre-commit.ci] pre-commit autoupdate (#2163) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/kynan/nbstripout: 0.7.1 → 0.8.0](https://github.com/kynan/nbstripout/compare/0.7.1...0.8.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d7abc3ed07..dafdeaf6e1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,6 +27,6 @@ repos: ] - repo: https://github.com/kynan/nbstripout - rev: 0.7.1 + rev: 0.8.0 hooks: - id: nbstripout