Skip to content

Commit

Permalink
Adding option for dynamic GEE key location, defaults to Explore location
Browse files Browse the repository at this point in the history
  • Loading branch information
jordancaraballo committed Mar 7, 2025
1 parent abc961a commit 0c78a92
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions model/CCDCPipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import ee
import geedim
import logging
import rioxarray as rxr
from shapely import box
from pathlib import Path
Expand Down Expand Up @@ -39,10 +40,22 @@ class CCDCPipeline:
Generate a single CCDC image.
run(self): Run the pipeline to process all input scenes.
"""
def __init__(self, input_dir, output_dir):
def __init__(
self,
input_dir: Path,
output_dir: Path,
gee_key: Path = None
):
self.input_dir = input_dir
self.output_dir = output_dir

if gee_key is not None:
self.gee_key = gee_key
else:
self.gee_key = \
'/explore/nobackup/projects/ilab/gee/gee_config.json'
logging.info(f'Defaulting to Explore location: {self.gee_key}')

@staticmethod
def _get_gee_credential(account, key):
try:
Expand All @@ -51,7 +64,7 @@ def _get_gee_credential(account, key):
print(f"Error creating GEE credentials: {str(e)}")
raise

def _get_coords(self, file):
def _get_coords(self, file: Path):
"""
Extract coordinates from a raster file and convert
them to EPSG:4326 projection.
Expand Down Expand Up @@ -101,17 +114,17 @@ def gen_single_image(
):
# TODO: Implement user-specified GEE account authentication.
# Currently using local credentials for testing purposes.
with open("/explore/nobackup/projects/ilab/gee/gee_config.json") as fh:
with open(self.gee_key) as fh:
config = json.load(fh)
gee_account = config.get('gee_account')
gee_key = config.get('gee_key_path')

try:
credentials = self._get_gee_credential(gee_account, gee_key)
ee.Initialize(credentials)
print("GEE initialized successfully")
logging.info("GEE initialized successfully")
except Exception as e:
print(f"Error initializing GEE: {str(e)}")
logging.info(f"Error initializing GEE: {str(e)}")
raise

date_object = dt.strptime(date_str, '%Y-%m-%d').date()
Expand Down

0 comments on commit 0c78a92

Please sign in to comment.