Skip to content

Commit

Permalink
Added outer join on sdss_id_flat
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Way committed Jul 29, 2024
1 parent 812c3da commit b946ab5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion python/target_selection/sdss_id/append_to_sdss_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ def run_MetaXMatch(self, database):
and catalogidx_to_catalogidy_?_unique tables.
"""
metax = MetaXMatch(config_filename=None, database=database, from_yaml=False,
from_dict=True, config_dict=self.config)
from_dict=True, config_dict=self.config,
outer_join_sdss_id=True)

metax.run()
create_unique_from_region(metax.output_name)
Expand Down
17 changes: 15 additions & 2 deletions python/target_selection/sdss_id/create_catalogidx_to_catalogidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
import numpy as np
import peewee
import yaml
from peewee import fn
from peewee import JOIN, fn
from playhouse.postgres_ext import ArrayField

from sdssdb.peewee.sdss5db.catalogdb import Catalog, database
from sdssdb.peewee.sdss5db.targetdb import Target

from .append_to_sdss_id import SdssIdFlat

import target_selection


Expand Down Expand Up @@ -96,11 +98,14 @@ class MetaXMatch:
log_file, and split_inrest_number.
save_log_output : bool
Save output to a file? Default is False.
outer_join_sdss_id : bool
Only use catalogids not associated with an sdss_id?
"""

def __init__(self, database, config_filename=None, from_yaml=True, from_dict=False,
config_dict=None, save_log_output=False):
config_dict=None, save_log_output=False, outer_join_sdss_id=True):
self.database = database
self.outer_join_sdss_id = outer_join_sdss_id
if from_yaml:
config = yaml.load(open(config_filename, 'r'), Loader=yaml.SafeLoader)
elif from_dict:
Expand Down Expand Up @@ -309,6 +314,14 @@ def match_in_table(self, name, split=False, min_targetid=0, max_targetid=0):
ra_start, ra_stop = self.ra_region
cte_targetids = cte_targetids.where(Target.ra.between(ra_start, ra_stop))

# If outer_join_sdss_id is True, only match in the catalogids that aren't
# already in sdss_id_flat

if self.outer_join_sdss_id:
cte_targetids = (cte_targetids.join(SdssIdFlat, join_type=JOIN.LEFT_OUTER,
on=(rel_table.catalogid == SdssIdFlat.catalogid))
.where(SdssIdFlat.catalogid).is_null())

cte_targetids = cte_targetids.cte('cte_targets')

query = (rel_table
Expand Down

0 comments on commit b946ab5

Please sign in to comment.