Skip to content

Commit

Permalink
Merge branch 'feat/sss'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaraphael committed Nov 20, 2024
2 parents 9a158db + 9344dae commit d36dcd4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions alembic/versions/3c4693517ef6_add_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ def upgrade() -> None:
sa.Column("id", sa.BigInteger, primary_key=True),
sa.Column("slick", sa.BigInteger, sa.ForeignKey("slick.id"), nullable=False),
sa.Column("source", sa.BigInteger, sa.ForeignKey("source.id"), nullable=False),
sa.Column("active", sa.Boolean, nullable=False),
sa.Column("coincidence_score", sa.Float),
sa.Column("collated_score", sa.Float),
sa.Column("rank", sa.BigInteger),
Expand Down
4 changes: 4 additions & 0 deletions cerulean_cloud/cloud_function_ais_analysis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ async def handle_asa_request(request):
slicks = await db_client.get_slicks_from_scene_id(
scene_id, with_sources=overwrite_previous
)
if overwrite_previous:
for slick in slicks:
await db_client.deactivate_sources_for_slick(slick.id)

print(f"# Slicks found: {len(slicks)}")
if len(slicks) > 0:
Expand Down Expand Up @@ -124,6 +127,7 @@ async def handle_asa_request(request):
await db_client.insert_slick_to_source(
source=source.id,
slick=slick.id,
active=True,
coincidence_score=source_row["coincidence_score"],
collated_score=source_row["collated_score"],
rank=idx + 1,
Expand Down
9 changes: 9 additions & 0 deletions cerulean_cloud/database_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ async def get_slicks_from_scene_id(
"""
query = (
select(db.Slick)
.distinct()
.outerjoin(db.SlickToSource, db.Slick.id == db.SlickToSource.slick)
.join(db.OrchestratorRun)
.join(db.Sentinel1Grd)
Expand Down Expand Up @@ -348,4 +349,12 @@ async def deactivate_stale_slicks_from_scene_id(self, scene_id):
# Return the number of rows updated
return result.rowcount

async def deactivate_sources_for_slick(self, slick_id):
"""deactivate sources for slick"""
await self.session.execute(
update(db.SlickToSource)
.where(db.SlickToSource.slick == slick_id)
.values(active=False)
)

# EditTheDatabase
1 change: 1 addition & 0 deletions cerulean_cloud/database_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ class SlickToSource(Base): # noqa
)
slick = Column(ForeignKey("slick.id"), nullable=False)
source = Column(ForeignKey("source.id"), nullable=False)
active = Column(Boolean, nullable=False)
coincidence_score = Column(Float(53))
collated_score = Column(Float(53))
rank = Column(BigInteger)
Expand Down
2 changes: 1 addition & 1 deletion notebooks/ASA_test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def plot_coincidence(
for s_type in source_types
}

ranked_sources = pd.DataFrame(columns=["type", "st_name", "coincidence_score"])
ranked_sources = pd.DataFrame(columns=["type", "st_name", "collated_score"])
for s_type, analyzer in analyzers.items():
res = analyzer.compute_coincidence_scores(slick_gdf)
ranked_sources = pd.concat([ranked_sources, res], ignore_index=True)
Expand Down

0 comments on commit d36dcd4

Please sign in to comment.