Skip to content

Commit

Permalink
adding coord units to search
Browse files Browse the repository at this point in the history
  • Loading branch information
havok2063 committed Oct 23, 2023
1 parent d1c600d commit 563d6b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
7 changes: 6 additions & 1 deletion python/valis/db/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

# all resuable queries go here

import astropy.units as u
from sdssdb.peewee.sdss5db import vizdb


def cone_search(ra: float, dec: float, radius: float):
def cone_search(ra: float, dec: float, radius: float, units: str = 'degree'):
""" Perform a cone search against the vizdb sdss_id_stacked table
Perform a cone search using the peewee ORM for SDSS targets in the
Expand All @@ -17,6 +18,10 @@ def cone_search(ra: float, dec: float, radius: float):
In the route endpoint itself, remember to return wrap this in a list.
"""

# convert radial units to degrees
radius *= u.Unit(units)
radius = radius.to(u.degree).value

return vizdb.SDSSidStacked.select().\
where(vizdb.SDSSidStacked.cone_search(ra, dec, radius,
ra_col='ra_sdss_id',
Expand Down
17 changes: 13 additions & 4 deletions python/valis/routes/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
#

from enum import Enum
from typing import List
from fastapi import APIRouter, Depends, Query
from fastapi_utils.cbv import cbv
Expand All @@ -12,6 +13,13 @@
from valis.db.queries import cone_search


class SearchCoordUnits(str, Enum):
""" Units of coordinate search radius """
degree: str = "degree"
arcmin: str = "arcmin"
arcsec: str = "arcsec"


router = APIRouter()


Expand All @@ -35,9 +43,10 @@ class QueryRoutes(Base):
@router.get('/cone', summary='Perform a cone search for SDSS targets with sdss_ids',
response_model=List[SDSSidStackedBase], dependencies=[Depends(get_pw_db)])
async def cone_search(self,
ra=Query(..., description='Right Ascension in degrees', example=315.01417),
dec=Query(..., description='Declination in degrees', example=35.299),
radius=Query(..., description='Search radius in degrees', example=0.01)):
ra: float = Query(..., description='Right Ascension in degrees', example=315.01417),
dec: float = Query(..., description='Declination in degrees', example=35.299),
radius: float = Query(..., description='Search radius in specified units', example=0.01),
units: SearchCoordUnits = Query('degree', description='Units of search radius', example='degree')):
""" Perform a cone search """
return list(cone_search(ra, dec, radius))
return list(cone_search(ra, dec, radius, units=units))

0 comments on commit 563d6b1

Please sign in to comment.