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

Adds new endpoint for getting target metadata and spectrum #8

Merged
merged 13 commits into from
Dec 14, 2023
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
Change Log
==========

0.1.1 (unreleased)
------------------
* Adds endpoint for getting a BHM spectrum (POC)
* Adds endpoint for getting target pipeline metadata for sdss_id
* Adds endpoints for target search by sdss_id and catalogid
* Adds endpoints for listing cartons and programs
* Adds endpoints for target search by carton and program

0.1.0 (10-24-2023)
------------------
* Initial tag of software
Expand Down
3,186 changes: 1,867 additions & 1,319 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ uvicorn = "^0.22.0"
gunicorn = "^20.1.0"
astropy = "^5.2.0"
aiofiles = "^0.5.0"
orjson = "^3.6.7"
orjson = "^3.9.0"
fastapi-restful = {extras = ["all"], version = "^0.5.0"}
python-multipart = "^0.0.5"
httpx = "^0.24.0"
Expand Down
99 changes: 76 additions & 23 deletions python/valis/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@

# all resuable Pydantic models of the ORMs go here

import peewee
from typing import Any, Optional
import datetime
from typing import Optional
from pydantic import ConfigDict, BaseModel, Field
#from pydantic.utils import GetterDict


# class PeeweeGetterDict(GetterDict):
# """ Class to convert peewee.ModelSelect into a list """
# def get(self, key: Any, default: Any = None):
# res = getattr(self._obj, key, default)
# if isinstance(res, peewee.ModelSelect):
# return list(res)
# return res
# for how to specify required, optional, default, etc, see
# https://docs.pydantic.dev/latest/migration/#required-optional-and-nullable-fields


class OrmBase(BaseModel):
Expand All @@ -26,13 +20,11 @@ class OrmBase(BaseModel):

class PeeweeBase(OrmBase):
""" Base pydantic model for peewee ORMs """
# TODO[pydantic]: The following keys were removed: `getter_dict`.
# Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information.
model_config = ConfigDict(from_attributes=True) #, getter_dict=PeeweeGetterDict)
model_config = ConfigDict(from_attributes=True)


# class SDSSidStackedBaseA(OrmBase):
# """ Pydantic model for the SQLA vizdb.SDSSidStacked ORM """
# """ Pydantic response model for the SQLA vizdb.SDSSidStacked ORM """

# sdss_id: int = Field(..., description='the SDSS identifier')
# ra_sdss_id: float = Field(..., description='Right Ascension of the most recent cross-match catalogid')
Expand All @@ -43,34 +35,95 @@ class PeeweeBase(OrmBase):


class SDSSidStackedBase(PeeweeBase):
""" Pydantic model for the Peewee vizdb.SDSSidStacked ORM """
""" Pydantic response model for the Peewee vizdb.SDSSidStacked ORM """

sdss_id: int = Field(..., description='the SDSS identifier')
ra_sdss_id: float = Field(..., description='Right Ascension of the most recent cross-match catalogid')
dec_sdss_id: float = Field(..., description='Declination of the most recent cross-match catalogid')
sdss_id: Optional[int] = Field(..., description='the SDSS identifier')
ra_sdss_id: Optional[float] = Field(..., description='Right Ascension of the most recent cross-match catalogid')
dec_sdss_id: Optional[float] = Field(..., description='Declination of the most recent cross-match catalogid')
catalogid21: Optional[int] = Field(None, description='the version 21 catalog id')
catalogid25: Optional[int] = Field(None, description='the version 25 catalog id')
catalogid31: Optional[int] = Field(None, description='the version 31 catalog id')


class SDSSidFlatBase(PeeweeBase):
""" Pydantic model for the Peewee vizdb.SDSSidFlat ORM """
""" Pydantic response model for the Peewee vizdb.SDSSidFlat ORM """

sdss_id: int = Field(..., description='the SDSS identifier')
ra_sdss_id: float = Field(..., description='Right Ascension of the most recent cross-match catalogid')
dec_sdss_id: float = Field(..., description='Declination of the most recent cross-match catalogid')
catalogid: int = Field(..., description='the catalogid associated with the given sdss_id')
version_id: int = Field(..., description='the version of the catalog for a given catalogid')
version_id: Optional[int] = Field(None, description='the version of the catalog for a given catalogid')
n_associated: int = Field(..., description='The total number of sdss_ids associated with that catalogid.')
ra_cat: float = Field(..., description='Right Ascension, in degrees, specific to the catalogid')
dec_cat: float = Field(..., description='Declination, in degrees, specific to the catalogid')
ra_catalogid: Optional[float] = Field(None, description='Right Ascension, in degrees, specific to the catalogid')
dec_catalogid: Optional[float] = Field(None, description='Declination, in degrees, specific to the catalogid')


class SDSSidPipesBase(PeeweeBase):
""" Pydantic model for the Peewee vizdb.SDSSidToPipes ORM """
""" Pydantic response model for the Peewee vizdb.SDSSidToPipes ORM """

sdss_id: int = Field(..., description='the SDSS identifier')
in_boss: bool = Field(..., description='Flag if target is in the BHM reductions', examples=[False])
in_apogee: bool = Field(..., description='Flag if target is in the MWM reductions', examples=[False])
in_astra: bool = Field(..., description='Flag if the target is in the Astra reductions', examples=[False])


class SDSSModel(SDSSidStackedBase, SDSSidPipesBase):
""" Main Pydantic response for SDSS id plus Pipes flags """
pass


class BossSpectrum(PeeweeBase):
""" Pydantic response model for the BHM pipeline metadata """
sdss_id: int = None
field: int = None
mjd: int = None
catalogid: int = None
nexp: int = None
exptime: float = None
survey: str = None
firstcarton: str = None
objtype: str = None
specobjid: int = None


class CatalogModel(PeeweeBase):
""" Pydantic model for source catalog information """
catalogid: int
version: int
lead: str
ra: float
dec: float
pmra: Optional[float] = None
pmdec: Optional[float] = None
parallax: Optional[float] = None


class CatalogResponse(CatalogModel, SDSSidFlatBase):
""" Response model for source catalog and sdss_id information """
pass


class CartonModel(PeeweeBase):
""" Response model for target and carton information """
catalogid: int
version: int
ra: float
dec: float
pmra: Optional[float] = None
pmdec: Optional[float] = None
parallax: Optional[float] = None
epoch: float
program: str
carton: str
category: int
run_on: Optional[datetime.datetime] = None


class PipesModel(PeeweeBase):
""" Pydantic model for pipeline metadata """
boss: Optional[BossSpectrum] = None
apogee: Optional[dict] = None
astra: Optional[dict] = None



Loading
Loading