Skip to content

Commit

Permalink
Added condition to read json data
Browse files Browse the repository at this point in the history
  • Loading branch information
arshdoda committed Jun 28, 2024
1 parent aeb0626 commit da8757e
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions city_metrix/__init__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
from .metrics import *
import os
import ee
import warnings

import ee

from .metrics import *

# initialize ee
if "GOOGLE_APPLICATION_CREDENTIALS" in os.environ and "GOOGLE_APPLICATION_USER" in os.environ:
if (
"GOOGLE_APPLICATION_CREDENTIALS" in os.environ
and "GOOGLE_APPLICATION_USER" in os.environ
):
print("Authenticating to GEE with configured credentials file.")
CREDENTIAL_FILE = os.environ["GOOGLE_APPLICATION_CREDENTIALS"]
GEE_SERVICE_ACCOUNT = os.environ["GOOGLE_APPLICATION_USER"]
auth = ee.ServiceAccountCredentials(GEE_SERVICE_ACCOUNT, CREDENTIAL_FILE)
ee.Initialize(auth, opt_url='https://earthengine-highvolume.googleapis.com')
if CREDENTIAL_FILE.endswith(".json"):
auth = ee.ServiceAccountCredentials(
GEE_SERVICE_ACCOUNT, key_file=CREDENTIAL_FILE
)
else:
auth = ee.ServiceAccountCredentials(
GEE_SERVICE_ACCOUNT, key_data=CREDENTIAL_FILE
)
ee.Initialize(auth, opt_url="https://earthengine-highvolume.googleapis.com")
else:
print("Could not find GEE credentials file, so prompting authentication.")
ee.Authenticate()
ee.Initialize(opt_url='https://earthengine-highvolume.googleapis.com')
ee.Initialize(opt_url="https://earthengine-highvolume.googleapis.com")


# set for AWS requests
os.environ["AWS_REQUEST_PAYER"] = "requester"

# disable warning messages
warnings.filterwarnings('ignore', module='xee')
warnings.filterwarnings('ignore', module='dask')
warnings.filterwarnings('ignore', module='xarray')

warnings.filterwarnings("ignore", module="xee")
warnings.filterwarnings("ignore", module="dask")
warnings.filterwarnings("ignore", module="xarray")

0 comments on commit da8757e

Please sign in to comment.