Skip to content

Commit

Permalink
Fix bug in phase 2 of cross-match code when dealing with addendum runs
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Nov 14, 2024
1 parent 528f032 commit 0bb623e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

## Next version


### 🔧 Fixed

* Fixed a bug in the cross-match code that would cross-match the input table against all versions in ``catalog`` for addendum runs.


## 1.3.15 - August 13 2024

### 🚀 New
Expand All @@ -15,7 +19,6 @@


## 1.3.14 - August 12 2024


### 🚀 New

Expand Down
18 changes: 15 additions & 3 deletions python/target_selection/xmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,11 @@ def _run_phase_2(self, model, source=TempCatalog):
else:
q3c_dist = fn.q3c_dist(model_ra, model_dec, source.ra, source.dec)
q3c_join = fn.q3c_join(
model_ra, model_dec, source.ra, source.dec, query_radius / 3600.0
model_ra,
model_dec,
source.ra,
source.dec,
query_radius / 3600.0,
)

# Get the cross-matched catalogid and model target pk (target_id),
Expand All @@ -1710,7 +1714,8 @@ def _run_phase_2(self, model, source=TempCatalog):
xmatched = xmatched.where(self._get_ls8_where(model))
if table_name == "legacy_survey_dr10":
xmatched = xmatched.where(
model.survey_primary >> True, fn.coalesce(model.ref_cat, "") != "T2"
model.survey_primary >> True,
fn.coalesce(model.ref_cat, "") != "T2",
)

# This may break the use of the index but I think it's needed if
Expand All @@ -1723,7 +1728,8 @@ def _run_phase_2(self, model, source=TempCatalog):
# We'll partition over each group of targets that match the same
# catalogid and mark the one with the smallest distance to it as best.
partition = fn.first_value(xmatched.c.target_id).over(
partition_by=[xmatched.c.catalogid], order_by=[xmatched.c.distance.asc()]
partition_by=[xmatched.c.catalogid],
order_by=[xmatched.c.distance.asc()],
)
best = peewee.Value(partition == xmatched.c.target_id)

Expand Down Expand Up @@ -1772,6 +1778,12 @@ def _run_phase_2(self, model, source=TempCatalog):
)
)

# Make sure we are only spatially cross-matching against targets from the same
# cross-match. This only matters for addendum runs because in those we are also
# cross-matching against the existing catalogdb.catalog table which contains multiple
# versions.
in_query = in_query.where(xmatched.c.version_id == self.version_id)

with Timer() as timer:
with self.database.atomic():
# 1. Tweak database configuration for this transaction to
Expand Down

0 comments on commit 0bb623e

Please sign in to comment.