Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Find Planned Observations for JWST Using astroquery\n",
"<p><i>By Susan Mullally ([email protected])</i></p>\n",
"Below we go through a few examples for how to use the MAST API to find observations planned for JWST (the GTO and ERS programs). We are going to do this by using [astroquery](https://astroquery.readthedocs.io/en/latest/mast/mast.html) on the MAST CAOM database. To avoid unintentional duplications, JWST proposers are required to check their proposed observations against those already approved. These tools may be useful in that process, and to find out more about what counts as a duplicate observations, see the [JWST documentation](https://jwst-docs.stsci.edu/display/JPP/JWST+Duplication+Checking).\n",
"\n",
"We begin by writing a couple of functions to query the MAST. The first function does a cone search on the database of JWST observations that have calibration level equal to -1 (proposed observations). You need only provide the RA, Dec and radius of your search. The second function does a name look-up using the Mast.Name.Lookup service to determine RA and Dec.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import astropy\n",
"from astroquery.mast import Mast\n",
"\n",
"def filteredConeSearch(ra,dec,radius,service=\"\",myfilters=None, returnNum=False):\n",
" \"\"\"\n",
" This function performs a cone search on the MAST CAOM database\n",
" and returns whether any observations overlap with the cone search\n",
" and other filters provided. This only searches planned observations.\n",
" \n",
" Args:\n",
" ra: right ascension in degrees\n",
" dec: declination in degrees\n",
" radius: radius of cone search in arc seconds\n",
" myfilters: Dictionary of what you want to filter on, \n",
" if None, it searhes mission=JWST and calib_level=-1\n",
" service: For testing you can change the MAST service to the testbed here.\n",
" returnNum: False. Set to True if you only want the number of observations returned.\n",
" \n",
" Returns:\n",
" results dictionary unless there are more than 1000 observations or less than 1.\n",
" \n",
" \"\"\"\n",
" \n",
" \n",
" if service==\"\":\n",
" service=\"Mast.Caom.Filtered.Position\"\n",
" \n",
" if myfilters!=None:\n",
" filters=myfilters\n",
" else:\n",
" filters = [\n",
" {\"paramName\":\"calib_level\",\n",
" \"values\":[\"-1\"],},\n",
" {\"paramName\":\"obs_collection\",\"values\":[\"JWST\"]}\n",
" ]\n",
" cone_search=\"%f, %f, %f\" % (ra,dec,radius/3600)\n",
" \n",
" #First see how many observations there are using COUNT_BIG(*)\n",
" params = { \"columns\":\"COUNT_BIG(*)\",\n",
" \"filters\":filters,\n",
" \"position\":cone_search\n",
" }\n",
" \n",
" result=Mast.service_request(service,params)\n",
" numbObs=int(result[0][0])\n",
" if (numbObs > 1000) | (numbObs == 0) | (returnNum):\n",
" return result\n",
" else:\n",
" print(\"Found: %u\" % numbObs)\n",
" \n",
" params = { \"columns\":\"*\",\n",
" \"filters\":filters,\n",
" \"position\":cone_search\n",
" }\n",
" \n",
" result=Mast.service_request(service,params)\n",
" \n",
" return result\n",
"\n",
"\n",
"def getMASTCoords(name):\n",
" \"\"\"\n",
" Use Mast.Name.Lookup to get the ra/dec of your target.\n",
" \"\"\"\n",
" service = 'Mast.Name.Lookup'\n",
" params ={'input':name,\n",
" 'format':'json'}\n",
" response = Mast.service_request_async(service,params)\n",
" result = response[0].json()\n",
" coord=result['resolvedCoordinate']\n",
" ra = coord[0]['ra']\n",
" dec = coord[0]['decl']\n",
" \n",
" return(ra,dec)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Example 1. Look-up TRAPPIST-1 and return all JWST observations on that target."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"target_name=\"Trappist-1\"\n",
"\n",
"(ra,dec) = getMASTCoords(target_name)\n",
"print(\"RA: %f, Dec: %f\" % (ra,dec))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Find planned JWST observations with the function we wrote above. \n",
"Print out the columns that may be of interest. Notice, it is still up to you to determine if these observations count as a duplicate with those you were planning. For instance, it does not provide the timing information necessary to determine which TRAPPIST-1 planet they are targetting. In some cases, the target_name or proposal title (obs_title) contains this information."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"service=\"Mast.Caom.Filtered.Position\"\n",
"radius = 10 #in arc seconds.\n",
"result=filteredConeSearch(ra,dec,radius,service=service)\n",
"print(result['target_name','proposal_pi','instrument_name','filters','t_exptime','proposal_id'])\n",
"print(\"\\nObservation Titles\")\n",
"print(result['obs_title'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Example 1 cont. -- Find HST observations for Trappist-1 using the same function.\n",
"We need to build our own filters dictionary to send into the function. \n",
"In this case we want HST observations taken with the WFC3/IR instrument and the F139M filter. Note, limiting your search by the database \"filters\" column can be tricky for JWST because there is frequently more than one filter listed in the filters field. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"filters = [{\"paramName\":\"obs_collection\",\n",
" \"values\":[\"HST\"]},\n",
" { \"paramName\":\"instrument_name\",\n",
" \"values\":[\"WFC3/IR\"]},\n",
" {\"paramName\" : \"filters\",\n",
" \"values\" : [\"F139M\"]}]\n",
"\n",
"service=\"Mast.Caom.Filtered.Position\"\n",
"\n",
"result=filteredConeSearch(ra,dec,radius,service=service,myfilters=filters)\n",
"\n",
"print(result['target_name','proposal_pi','instrument_name','filters','t_exptime'])\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Example 2. Search for JWST planned observations around a list of stars with known planetary disks.\n",
"We will only ask for data taken with NIRCam. And we will ask our function to only return the number of observations."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pdlist = [\"Vega\", \"Deneb\",\"Fomalhaut\",\"HL Tauri\",\"Eta Corvi\",\"HD 15115\"]\n",
"\n",
"filters= [ {\"paramName\": \"calib_level\",\n",
" \"values\" :[\"-1\"],\n",
" \"paramName\": \"instrument_name\",\n",
" \"values\":[\"NIRCam\"]} \n",
"]\n",
"\n",
"service=\"Mast.Caom.Filtered.Position\"\n",
"\n",
"radius = 100 #arcseconds for cone search\n",
"numlist=[]\n",
"for pd in pdlist:\n",
" (ra,dec) = getMASTCoords(pd)\n",
" result=filteredConeSearch(ra,dec,radius,service=service,myfilters=filters,returnNum=True)\n",
" numbObs=int(result[0][0])\n",
" numlist.append(numbObs)\n",
"\n",
"print(pdlist)\n",
"print(numlist)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Check Details\n",
"Now I list the details of the observations for Fomalhaut."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"(ra,dec) = getMASTCoords('Fomalhaut')\n",
"result = filteredConeSearch(ra,dec,radius,service=service,myfilters=filters)\n",
"print(result['target_name','proposal_pi','instrument_name','filters','t_exptime'])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading