Skip to content

Commit

Permalink
use pyvo to get proposal number:category dict
Browse files Browse the repository at this point in the history
  • Loading branch information
bhilbert4 committed Jan 29, 2024
1 parent 70818bd commit a1db37a
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions jwql/website/apps/jwql/data_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,24 +1400,16 @@ def get_proposals_by_category(instrument):
Returns
-------
category_sorted_dict : dict
Dictionary with category as the key and a list of program id's as the value
Dictionary with program number as the key and program category as the value
"""
tap_service = vo.dal.TAPService("https://vao.stsci.edu/caomtap/tapservice.aspx")
tap_results = tap_service.search(f"""select distinct prpID,prpProject from CaomObservation where collection='JWST'
and maxLevel>0 and insName like '{instrument.lower()}%'""")
# Put the results into an astropy Table
prop_table = tap_results.to_table()

service = "Mast.Jwst.Filtered.{}".format(instrument)
params = {"columns": "program, category",
"filters": [{'paramName': 'instrume', 'values': [instrument]}]}
response = Mast.service_request_async(service, params)
results = response[0].json()['data']

if len(results) == MAST_QUERY_LIMIT:
logging.error(f"MAST_QUERY_LIMIT of {MAST_QUERY_LIMIT} reached for {instrument} in get_proposals_by_category")

# Get all unique dictionaries
unique_results = list(map(dict, set(tuple(sorted(sub.items())) for sub in results)))

# Make a dictionary of {program: category} to pull from
proposals_by_category = {d['program']: d['category'] for d in unique_results}

# Convert to a dictionary
proposals_by_category = {int(d['prpID']): d['prpProject'] for d in prop_table}
return proposals_by_category


Expand Down

0 comments on commit a1db37a

Please sign in to comment.