Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding release filter for queries using the mjd cutoffs #72

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion python/valis/db/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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 @@ -26,7 +27,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 @@ -72,6 +73,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
6 changes: 3 additions & 3 deletions python/valis/routes/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async def main_search(self, body: SearchModel):
query=query)
# 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 @@ -125,7 +125,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 Expand Up @@ -208,7 +208,7 @@ async def carton_program(self,
with database.atomic():
database.execute_sql('SET LOCAL enable_seqscan=false;')
query = carton_program_search(name, name_type)
query = append_pipes(query, observed=observed)
query = append_pipes(query, observed=observed, release=self.release)
return query.dicts().iterator()

@router.get('/obs', summary='Return targets with spectrum at observatory',
Expand Down
Loading