Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cloud project to EE initialization. #326

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading