Skip to content

Allspec: code for /allspec_apred_vers_apstar_id_file_spec - #97

Open
astronomygupta wants to merge 5 commits into
mainfrom
allspec
Open

Allspec: code for /allspec_apred_vers_apstar_id_file_spec#97
astronomygupta wants to merge 5 commits into
mainfrom
allspec

Conversation

@astronomygupta

Copy link
Copy Markdown
Contributor

No description provided.

@havok2063 havok2063 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start, but I think we want to make this a bit easier and more useful for users, and do some performance/timing benchmarks. I've made some comments and requested some changes.

return max(res, key=lambda i: i["created"]) if res else None


def get_targets_allspec_apred_vers_apstar_id_file_spec(apred_vers: str, apstar_id: str, file_spec: str) -> peewee.ModelSelect:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is a bit too long and uninformative. I think we could rename this to something like query_allspec_table.


return vizdb.AllSpec.select().where(vizdb.AllSpec.apred_vers == apred_vers,
vizdb.AllSpec.apstar_id == apstar_id,
vizdb.AllSpec.file_spec == file_spec)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The allspec table contains data from different releases. I think we want to support querying on a specific release. You can join on the vizdb.Releases model using the allspec.releases_pk.

Comment on lines +1469 to +1471

"""Perform a search for SDSS targets on vizdb.allspace based on apred_vers, apstar_id, file_spec values.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now this function has 3 required arguments, but users might not always want to query on these parameters, so I think they should be optional. These 3 columns are only for apogee/mwm targets. I think we want to expose other columns from the allspec table that users may want to query on.

I think we should enable queries on the following columns:
allspec_id, release, sdss_phase, observatory, instrument, sdss_id, catalogid, fiberid, ifudsgn, plate, fps_field, plate_or_fps_field, mjd, programname, survey, ra, dec, apogee_id

I don't think we want to necessarily AND all these together. Some would be ORs. Most columns will be strict equals. I think allspec_id we also want to support a LIKE query.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For RA, Dec columns, we might want to support cone searches with some radius. Users are less likely to specify an exact RA,Dec match.

Comment on lines +35 to +45
# Note for using catalogdb peewee models from sdssdb.
#
# Use the below syntax.
#
# from sdssdb.peewee.sdss5db import catalogdb
# catalogdb.Gaia_DR3.ra
#
# Do not use the below syntax.
#
# from sdssdb.peewee.sdss5db.catalogdb import Gaia_DR3
# Gaia_DR3.ra

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this comment block.

return list(targets)

@router.get(
"/allspec_apred_vers_apstar_id_file_spec",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This endpoint name is too long and convoluted. The name should be simple and easy for a user. I'd suggest allspec. The valis API would then be valis/query/allspec` and a user can easily tell this endpoint is for "querying the allspec table".

dependencies=[Depends(get_pw_db), Depends(set_auth)],
)
@valis_cache(namespace="valis-query")
async def get_targets_allspec_apred_vers_apstar_id_file_spec_search(self,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function name is too long and complicated. I'd simplify it.


@router.get(
"/allspec_apred_vers_apstar_id_file_spec",
summary="Perform a search for an allspec target based on the apred_vers, apstar_id, file_spec",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
summary="Perform a search for an allspec target based on the apred_vers, apstar_id, file_spec",
summary="Perform a target search on the SDSS allspec table",


# throw exception when it's invalid apred_vers, apstar_id, file_spec
if not targets:
raise HTTPException(status_code=400, detail=f"Invalid apred_vers {apred_vers}, apstar_id {apstar_id}, file_spec {file_spec}.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise HTTPException(status_code=400, detail=f"Invalid apred_vers {apred_vers}, apstar_id {apstar_id}, file_spec {file_spec}.")
raise HTTPException(status_code=400, detail="No targets found in the allspec for given search inputs. Try adjusting your query.")

# into a dictionary.
# The function list() converts the dictionary into a list.
# The list can then be serialized.
targets = list(get_targets_allspec_apred_vers_apstar_id_file_spec(apred_vers, apstar_id, file_spec).dicts())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The allspec query may return lots of results. We may want to make this an iterator() and use a StreamingResponse instead. Have you done some performance benchmarks to see how this endpoint performs for large queries? If not, I think we'll want to do some tests comparing this implementation vs iterator/StreamingResponse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants