Skip to content

Commit

Permalink
adding release filter for queries using the mjd cutoffs (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
havok2063 authored Dec 9, 2024
1 parent 93a500f commit dbf2ad5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
24 changes: 23 additions & 1 deletion python/valis/db/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import astropy.units as u
import deepmerge
import peewee
from peewee import Case
from astropy.coordinates import SkyCoord
from sdssdb.peewee.sdss5db import apogee_drpdb as apo
from sdssdb.peewee.sdss5db import boss_drp as boss
Expand All @@ -28,7 +29,7 @@


def append_pipes(query: peewee.ModelSelect, table: str = 'stacked',
observed: bool = True) -> peewee.ModelSelect:
observed: bool = True, release: str = None) -> peewee.ModelSelect:
""" Joins a query to the SDSSidToPipes table
Joines an existing query to the SDSSidToPipes table and returns
Expand Down Expand Up @@ -77,6 +78,27 @@ def append_pipes(query: peewee.ModelSelect, table: str = 'stacked',
if observed:
qq = qq.where(vizdb.SDSSidToPipes.has_been_observed == observed)

if release:
# get the release
rel = vizdb.Releases.select().where(vizdb.Releases.release==release).first()

# if a release has no cutoff info, then force the cutoff to 0, query will return nothing
# to fix this we want mjd cutoffs by survey for all older releases
if not rel.mjd_cutoff_apo and not rel.mjd_cutoff_lco:
rel.mjd_cutoff_apo = 0
rel.mjd_cutoff_lco = 0

# create the mjd cutoff condition
qq = qq.where(vizdb.SDSSidToPipes.mjd <= Case(
vizdb.SDSSidToPipes.obs,
(
('apo', rel.mjd_cutoff_apo),
('lco', rel.mjd_cutoff_lco)
),
None
)
)

return qq


Expand Down
4 changes: 2 additions & 2 deletions python/valis/routes/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async def main_search(self, body: SearchModel):

# append query to pipes
if query:
query = append_pipes(query, observed=body.observed)
query = append_pipes(query, observed=body.observed, release=self.release)

# query iterator
res = query.dicts().iterator() if query else []
Expand All @@ -133,7 +133,7 @@ async def cone_search(self,
""" Perform a cone search """

res = cone_search(ra, dec, radius, units=units)
r = append_pipes(res, observed=observed)
r = append_pipes(res, observed=observed, release=self.release)
# return sorted by distance
# doing this here due to the append_pipes distinct
return sorted(r.dicts().iterator(), key=lambda x: x['distance'])
Expand Down

0 comments on commit dbf2ad5

Please sign in to comment.