diff --git a/cerulean_cloud/cloud_run_orchestrator/clients.py b/cerulean_cloud/cloud_run_orchestrator/clients.py index 3737f895..7749a436 100644 --- a/cerulean_cloud/cloud_run_orchestrator/clients.py +++ b/cerulean_cloud/cloud_run_orchestrator/clients.py @@ -1,6 +1,7 @@ """Clients for other cloud run functions""" import asyncio import json +import logging import os import zipfile from base64 import b64encode @@ -74,28 +75,57 @@ async def get_base_tile_inference( ) -> InferenceResultStack: """fetch inference for base tiles""" async with semaphore: + logging.info("Fetching base tile.") img_array = await self.titiler_client.get_base_tile( sceneid=self.sceneid, tile=tile, scale=self.scale, rescale=rescale ) + + logging.info("Reshaping image array.") img_array = reshape_as_raster(img_array) + + logging.info("Getting tile bounds.") bounds = list(TMS.bounds(tile)) + + logging.info("Reading auxiliary datasets.") with self.aux_datasets.open() as src: window = rasterio.windows.from_bounds(*bounds, transform=src.transform) height, width = img_array.shape[1:] aux_ds = src.read(window=window, out_shape=(height, width)) + logging.info("Concatenating image arrays.") img_array = np.concatenate([img_array[0:1, :, :], aux_ds], axis=0) + logging.info("Encoding image to base64.") encoded = img_array_to_b64_image(img_array) + logging.info("Preparing payload for prediction.") inf_stack = [InferenceInput(image=encoded, bounds=TMS.bounds(tile))] + logging.info("Preparing payload for prediction.") + + # Log the length of inf_stack + logging.info(f"Length of inf_stack: {len(inf_stack)}") + + # Log a sample from inf_stack + logging.info( + f"Sample from inf_stack: {inf_stack[:1]}" + ) # adjust the slice as needed + + # Log inf_parms + logging.info(f"inf_parms: {self.inference_parms}") + + # Create and log the entire payload payload = PredictPayload( inf_stack=inf_stack, inf_parms=self.inference_parms ) + logging.info(f"Complete PredictPayload: {payload.dict()}") + + logging.info(f"Sending request to {self.url + '/predict'}.") res = await self.client.post( self.url + "/predict", json=payload.dict(), timeout=None ) + + logging.info("Processing response.") return InferenceResultStack(**res.json()) async def get_offset_tile_inference( diff --git a/cerulean_cloud/cloud_run_orchestrator/handler.py b/cerulean_cloud/cloud_run_orchestrator/handler.py index e37f18d9..89e784d6 100644 --- a/cerulean_cloud/cloud_run_orchestrator/handler.py +++ b/cerulean_cloud/cloud_run_orchestrator/handler.py @@ -350,7 +350,7 @@ async def _orchestrate( ) for base_tile in base_tiles ], - return_exceptions=True, + return_exceptions=False, ) logging.info("Inference on offset tiles!") @@ -364,7 +364,7 @@ async def _orchestrate( ) for offset_tile_bounds in offset_tiles_bounds ], - return_exceptions=True, + return_exceptions=False, ) if base_tiles_inference[0].stack[0].dict().get("classes"): @@ -431,12 +431,10 @@ async def _orchestrate( print(f"YYY error details: {e}") print(f"YYY base_tiles_inference: {base_tiles_inference}") print(f"YYY offset_tiles_inference: {offset_tiles_inference}") - print( - f"YYY [r for r in base_tiles_inference]: {[r for r in base_tiles_inference]}" - ) - print( - f"YYY [r for r in offset_tiles_inference]: {[r for r in offset_tiles_inference]}" - ) + for r in base_tiles_inference: + print(f"YYY [r for r in base_tiles_inference]: {r}") + for r in offset_tiles_inference: + print(f"YYY [r for r in offset_tiles_inference]: {r}") raise e # XXXBUG ValueError: Cannot determine common CRS for concatenation inputs, got ['WGS 84 / UTM zone 28N', 'WGS 84 / UTM zone 29N']. Use `to_crs()` to transform geometries to the same CRS before merging." @@ -453,6 +451,13 @@ async def _orchestrate( ) for feat in merged_inferences.get("features"): + logging.info( + f"XXX CHRISTIAN feat.get('properties') {feat.get('properties')}" + ) + logging.info(f"XXX CHRISTIAN feat.get('id') {feat.get('id')}") + logging.info( + f"XXX CHRISTIAN feat.get('geometry') {feat.get('geometry')}" + ) async with db_client.session.begin(): # mini_gdf = gpd.GeoDataframe(feat) # if mini_gdf.intersects(land):