Refactor: Production-grade SatVision backend modularization, structured logging, boot safety validations, and workspace cleanup
7db73fd Download src/database/gee.py from SatVision/App: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/SatVision/App/resolve/main/src/database/gee.py
- Command line
-
hf download hf://spaces/SatVision/App/src/database/gee.py
-
curl -L -o gee.py https://huggingface.co/spaces/SatVision/App/resolve/main/src/database/gee.py
1.19 kB
| """ | |
| Google Earth Engine initialization and authentication. | |
| """ | |
| import json | |
| import ee | |
| from src import config | |
| def initialize_earth_engine(): | |
| """ | |
| Initialize Earth Engine with service account credentials or local auth. | |
| """ | |
| config.logger.info("π Initializing Earth Engine...") | |
| try: | |
| if config.EE_CREDENTIALS_JSON: | |
| # Use service account credentials from environment | |
| key_dict = json.loads(config.EE_CREDENTIALS_JSON) | |
| from google.oauth2 import service_account | |
| credentials = service_account.Credentials.from_service_account_info( | |
| key_dict, | |
| scopes=['https://www.googleapis.com/auth/earthengine'] | |
| ) | |
| ee.Initialize(credentials, project=config.EE_PROJECT_ID) | |
| config.logger.info("β Earth Engine Linked via Service Account.") | |
| else: | |
| # Use local authentication (cached credentials) | |
| ee.Initialize(project=config.EE_PROJECT_ID) | |
| config.logger.info("β Earth Engine Linked via Local Auth.") | |
| except Exception as e: | |
| config.logger.error(f"β Earth Engine Init Failed: {e}") | |
| raise |