Skip to content

Commit

Permalink
Add cloud project to EE initialization.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 716378472
  • Loading branch information
jzxu authored and copybara-github committed Jan 17, 2025
1 parent 433d9b2 commit dfbca2e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/skai/earth_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,17 @@ def get_open_buildings(regions: list[ShapelyGeometry],
)


def initialize(service_account: str, private_key: str | None) -> bool:
def initialize(
cloud_project: str, service_account: str, private_key: str | None
) -> bool:
"""Initializes EE server connection.
When not using a service account, this function assumes that the user has
already authenticated with EE using the shell command
"earthengine authenticate".
Args:
cloud_project: Google Cloud project id.
service_account: If not empty, the service account to use. Otherwise
defaults to caller's personal account.
private_key: Private key for service account.
Expand All @@ -174,9 +177,9 @@ def initialize(service_account: str, private_key: str | None) -> bool:
try:
if service_account:
credentials = ee.ServiceAccountCredentials(service_account, private_key)
ee.Initialize(credentials)
ee.Initialize(credentials=credentials, project=cloud_project)
else:
ee.Initialize()
ee.Initialize(project=cloud_project)
except ee.EEException as e:
logging.error('Error initializing Earth Engine: %s', e)
return False
Expand Down
4 changes: 3 additions & 1 deletion src/skai/generate_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ def download_building_footprints(
)
elif config.buildings_method == 'open_buildings':
if not earth_engine.initialize(
config.earth_engine_service_account, config.earth_engine_private_key
config.cloud_project,
config.earth_engine_service_account,
config.earth_engine_private_key,
):
raise NotInitializedEarthEngineError()
logging.info('Querying Open Buildings centroids. This may take a while.')
Expand Down

0 comments on commit dfbca2e

Please sign in to comment.