Skip to content

Commit

Permalink
Tweak logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaraphael committed Oct 27, 2023
1 parent 274ccec commit f392dd1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
8 changes: 8 additions & 0 deletions cerulean_cloud/cloud_function_ais_analysis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""

import asyncio
import logging
import os
from json import loads

Expand Down Expand Up @@ -54,27 +55,34 @@ async def handle_aaa_request(request):
request_json = request.get_json()
if not request_json.get("dry_run"):
scene_id = request_json.get("scene_id")
logging.info(f"Running AAA on scene_id: {scene_id}")
db_engine = get_engine(db_url=os.getenv("DB_URL"))
async with DatabaseClient(db_engine) as db_client:
async with db_client.session.begin():
s1 = await db_client.get_scene_from_id(scene_id)
slicks_without_sources = (
await db_client.get_slicks_without_sources_from_scene_id(scene_id)
)
logging.info(f"# Slicks found: {len(slicks_without_sources)}")
if len(slicks_without_sources) > 0:
ais_constructor = AISConstructor(s1)
ais_constructor.retrieve_ais()
# ais_constructor.add_infra()
logging.info("AIS retrieved")
if (
ais_constructor.ais_gdf is not None
and not ais_constructor.ais_gdf.empty
):
logging.info("AIS is not empty")
ais_constructor.build_trajectories()
ais_constructor.buffer_trajectories()
for slick in slicks_without_sources:
ais_associations = automatic_ais_analysis(
ais_constructor, slick
)
logging.info(
f"{len(ais_associations)} found for Slick ID: {slick.id}"
)
if len(ais_associations) > 0:
# XXX What to do if len(ais_associations)==0 and no sources are associated?
# Then it will trigger another round of this process later! (unnecessary computation)
Expand Down
34 changes: 11 additions & 23 deletions cerulean_cloud/cloud_run_orchestrator/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ def flatten_feature_list(
async def _orchestrate(
payload, tiler, titiler_client, roda_sentinelhub_client, db_engine
):
logging.basicConfig(level=logging.INFO)

# Orchestrate inference
start_time = datetime.now()
logging.info(f"Orchestrating for sceneid {payload.sceneid}")
Expand All @@ -246,11 +244,11 @@ async def _orchestrate(
logging.info(f"scale: {scale}")

if model.zoom_level != zoom:
logging.info(
logging.warning(
f"WARNING: Model was trained on zoom level {model.zoom_level} but is being run on {zoom}"
)
if model.tile_width_px != scale * 256:
logging.info(
logging.warning(
f"WARNING: Model was trained on image tile of resolution {model.tile_width_px} but is being run on {scale*256}"
)

Expand Down Expand Up @@ -430,22 +428,23 @@ async def _orchestrate(
features=flatten_feature_list(offset_tiles_inference)
)
except AttributeError as e:
logging.info(f"YYY error details: {e}")
logging.info(f"YYY base_tiles_inference: {base_tiles_inference}")
logging.info(
logging.debug(f"YYY error details: {e}")
logging.debug(f"YYY base_tiles_inference: {base_tiles_inference}")
logging.debug(
f"YYY offset_tiles_inference: {offset_tiles_inference}"
)
logging.info(
logging.debug(
f"YYY [r for r in base_tiles_inference]: {[r for r in base_tiles_inference]}"
)
logging.info(
logging.debug(
f"YYY [r for r in offset_tiles_inference]: {[r for r in offset_tiles_inference]}"
)
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."
# Example: S1A_IW_GRDH_1SDV_20230727T185101_20230727T185126_049613_05F744_1E56
logging.info(f"XXXDEBUG out_fc: {out_fc}")
logging.info(f"XXXDEBUG out_fc_offset: {out_fc_offset}")
logging.debug(f"out_fc: {out_fc}")
logging.debug(f"out_fc_offset: {out_fc_offset}")
merged_inferences = merge_inferences(
out_fc,
out_fc_offset,
Expand All @@ -456,17 +455,6 @@ async def _orchestrate(
)

for feat in merged_inferences.get("features"):
try:
logging.info(f"XXX CHRISTIAN type(feat): {type(feat)}")
logging.info(
f"XXX CHRISTIAN type(feat['geometry']): {type(feat['geometry'])}"
)
logging.info(f"XXX CHRISTIAN feat['geometry']: {feat['geometry']}")
logging.info(
f"XXX CHRISTIAN geojson.dumps(feat['geometry']): {geojson.dumps(feat['geometry'])}"
)
except: # noqa
pass
async with db_client.session.begin():
# mini_gdf = gpd.GeoDataframe(feat)
# if mini_gdf.intersects(land):
Expand Down Expand Up @@ -499,7 +487,7 @@ async def _orchestrate(
noffsettiles=noffsettiles,
)
else:
logging.info("DRY RUN!!")
logging.warning("WARNING: Operating as a DRY RUN!!")
orchestrator_result = OrchestratorResult(
classification_base=geojson.FeatureCollection(features=[]),
classification_offset=geojson.FeatureCollection(features=[]),
Expand Down
2 changes: 1 addition & 1 deletion stack/cloud_function_ais_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
source_archive_object=source_archive_object.name,
trigger_http=True,
service_account_email=cloud_function_service_account.email,
available_memory_mb=1024,
available_memory_mb=2048,
timeout=540,
secret_environment_variables=[gfw_credentials],
)
Expand Down

0 comments on commit f392dd1

Please sign in to comment.