Skip to content

Independent initialization (GEE) #11

Description

@YenCheng1226

The current Google Earth Engine (GEE) initialization logic in src/ingestion.py is tightly coupled with hardcoded project IDs and attempts interactive authentication as a default fallback. This creates dependencies on specific user environments and makes the module difficult to reuse in automated pipelines or remote servers without manual intervention.

Current Limitations

  1. Hardcoded Project ID: The variable my_gee_project is defined directly within
    main(), requiring code changes for different environments.
  2. Interactive Auth Dependency: The try-except block assumes an interactive session for ee.Authenticate(), which fails gracefully in non-interactive builds.
  3. Side Effects: Initialization directly prints to stdout and doesn't provide a way to check status programmatically.

Proposed Solution

Refactor the initialization logic to be independent and configurable:

  1. Extract Initialization: Move initialize_gee to a dedicated utility module (e.g., src/utils/gee_utils.py).
  2. Configuration Injection: Accept the Project ID as an argument or read from an environment variable (e.g., GEE_PROJECT_ID).
  3. Robust Error Handling: Provide clear error messages for missing credentials instead of forcing interactive ee.Authenticate() in non-interactive contexts.

Pseudo Code

FUNCTION initialize_gee (INPUTS: gee_project, gee_key)
TRY:
IF key_path is provided AND file exists:

  1. Create a Service Account Credential using the JSON file.
  2. INITIALIZE Earth Engine using these specific credentials and the gee_project ID.
    ELSE (No key file provided)

CATCH (any errors):

  1. PRINT: "Authentication required."
  2. EXECUTE: ee.Authenticate() to trigger a manual web-browser login flow.
  3. INITIALIZE Earth Engine using the newly generated manual token and the gee_project ID.

Logic Flow Summary

  1. Primary Path: Automated login via Service Account (Best for servers/headless).
  2. Secondary Path: Local environment initialization (Best for personal laptops).
  3. Fallback Path: Manual browser-based authentication (Interactive backup).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions