Skip to content

Commit

Permalink
updating target pipes routes to return related files
Browse files Browse the repository at this point in the history
  • Loading branch information
havok2063 committed Feb 1, 2024
1 parent aa2142d commit f42cf12
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 15 additions & 7 deletions python/valis/routes/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from astroquery.simbad import Simbad

from valis.routes.base import Base
from valis.db.queries import get_target_meta, get_a_spectrum, get_catalog_sources, get_target_cartons, get_boss_target
from valis.db.queries import (get_target_meta, get_a_spectrum, get_catalog_sources,
get_target_cartons, get_boss_target, build_boss_path)
from valis.db.db import get_pw_db
from valis.db.models import CatalogResponse, CartonModel, PipesModel, SDSSModel

Expand Down Expand Up @@ -152,7 +153,8 @@ async def get_coord(self,
return res.to_pandas().to_dict('records')

@router.get('/ids/{sdss_id}', summary='Retrieve pipeline metadata for a target sdss_id',
dependencies=[Depends(get_pw_db)], response_model=Union[SDSSModel, dict],
dependencies=[Depends(get_pw_db)],
response_model=Union[SDSSModel, dict],
response_model_exclude_unset=True, response_model_exclude_none=True)
async def get_target(self, sdss_id: int = Path(title="The sdss_id of the target to get", example=23326)):
""" Return target metadata for a given sdss_id """
Expand All @@ -166,14 +168,16 @@ async def get_spectrum(self, sdss_id: Annotated[int, Path(title="The sdss_id of
return get_a_spectrum(sdss_id, product, self.release)

@router.get('/catalogs/{sdss_id}', summary='Retrieve catalog information for a target sdss_id',
dependencies=[Depends(get_pw_db)], response_model=List[CatalogResponse],
dependencies=[Depends(get_pw_db)],
response_model=List[CatalogResponse],
response_model_exclude_unset=True, response_model_exclude_none=True)
async def get_catalogs(self, sdss_id: int = Path(title="The sdss_id of the target to get", example=23326)):
""" Return catalog information for a given sdss_id """
return get_catalog_sources(sdss_id).dicts().iterator()

@router.get('/cartons/{sdss_id}', summary='Retrieve carton information for a target sdss_id',
dependencies=[Depends(get_pw_db)], response_model=List[CartonModel],
dependencies=[Depends(get_pw_db)],
response_model=List[CartonModel],
response_model_exclude_unset=True, response_model_exclude_none=True)
async def get_cartons(self, sdss_id: int = Path(title="The sdss_id of the target to get", example=23326)):
""" Return carton information for a given sdss_id """
Expand All @@ -188,13 +192,17 @@ async def get_pipeline(self, sdss_id: int = Path(title="The sdss_id of the targe
Query(enum=['all', 'boss', 'apogee', 'astra'],
description='Specify search on specific pipeline',
example='boss')] = 'all'):

boss = get_boss_target(sdss_id, self.release).dicts().first() or {}

if pipe == 'boss':
return {'boss': get_boss_target(sdss_id, self.release).dicts().first()}
return {'boss': boss, 'files': {'boss': build_boss_path(boss, self.release)}}
if pipe == 'apogee':
return {'apogee': {}}
if pipe == 'astra':
return {'astra': {}}

return {'boss': get_boss_target(sdss_id, self.release).dicts().first(),
return {'boss': boss,
'apogee': {},
'astra': {}}
'astra': {},
'files': {'boss': build_boss_path(boss, self.release)}}
4 changes: 4 additions & 0 deletions python/valis/utils/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def build_file_path(values: dict, product: str, release: str, remap: dict = None
ValueError
when not all path template keywords can be found
"""
if not values:
print('No input values dictionary found. Cannot build filepath.')
return ''

path = Path(release=release)

if product not in path.lookup_names():
Expand Down

0 comments on commit f42cf12

Please sign in to comment.