Skip to content

Instantly share code, notes, and snippets.

@pllim
Last active October 20, 2017 01:27
Show Gist options
  • Save pllim/3a746c5483e6efafcf2cb318bbffb1d5 to your computer and use it in GitHub Desktop.
Save pllim/3a746c5483e6efafcf2cb318bbffb1d5 to your computer and use it in GitHub Desktop.
Cone Search Example using AKARI/FIS All-Sky Survey Bright Source Catalogue
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*I wanted to search this SCS resource in the registry:\n",
"http://vao.stsci.edu/directory/getRecord.aspx?id=ivo://irsa.ipac/AKARI/Catalog/FISBSC*\n",
"\n",
"*How would I do that?*\n",
"\n",
"(Solution below adapted from http://astroquery.readthedocs.io/en/latest/vo_conesearch/vo_conesearch.html)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Solution 1: By Querying STScI VAO Registry"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This solution also uses the \"classic\" interface inherited from its days in `astropy.vo` package."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import warnings\n",
"\n",
"from astroquery.vo_conesearch.vos_catalog import VOSDatabase\n",
"from astroquery.vo_conesearch.validator import conf as validator_conf"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Downloading http://vao.stsci.edu/directory/NVORegInt.asmx/VOTCapabilityPredOpt?predicate=1%3D1&capability=conesearch&VOTStyleOption=2 [Done]\n"
]
}
],
"source": [
"# Obtain STScI VAO cone search registry (takes several seconds).\n",
"with warnings.catch_warnings():\n",
" warnings.simplefilter('ignore')\n",
" registry_db = VOSDatabase.from_registry(\n",
" validator_conf.conesearch_master_list, encoding='binary')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['AKARI/FIS All-Sky Survey Bright Source Catalog, Version 1 1',\n",
" 'AKARI/FIS All-Sky Survey Bright Source Catalogue 1']"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Find catalogs that might be AKARI/FIS All-Sky Survey Bright Source.\n",
"registry_db.list_catalogs(pattern='AKARI/FIS All-Sky Survey Bright Source')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"capabilityClass\": \"ConeSearch\",\n",
" \"capabilityStandardID\": \"ivo://ivoa.net/std/ConeSearch\",\n",
" \"capabilityValidationLevel\": \"2\",\n",
" \"contentLevel\": \"#Research#\",\n",
" \"description\": \"The AKARI/FIS Bright Source Catalogue Version 1.0 provides the positions and fluxes of 427,071 point sources in the four far-infrared wavelengths centred at 65, 90, 140, and 160 microns. The sensitivity in the 90 micron band is about 0.55 Jy. The Far-Infrared Surveyor (FIS) instrument scanned 98 percent of the entire sky more than twice during the 16 months of the cryogenic mission phase. The AKARI/FIS Bright Source Catalogue is the primary data product from the AKARI survey. The catalogue is designed to have a uniform detection limit (corresponding to per scan sensitivity) over the entire sky (except for high background regions where a different data acquisition mode was used). Redundant observations are used to increase the reliability of the detection.\",\n",
" \"duplicatesIgnored\": 0,\n",
" \"identifier\": \"ivo://irsa.ipac/AKARI/Catalog/FISBSC#1\",\n",
" \"interfaceClass\": \"ParamHTTP\",\n",
" \"interfaceRole\": \"std?\",\n",
" \"interfaceVersion\": \"\",\n",
" \"maxRadius\": 180.0,\n",
" \"maxRecords\": 2147483647,\n",
" \"publisher\": \"NASA/IPAC Infrared Science Archive\",\n",
" \"publisherID\": \"ivo://irsa.ipac/IRSA\",\n",
" \"referenceURL\": \"https://irsa.ipac.caltech.edu/data/AKARI/gator_docs/akari_fis_colDescriptions.html\",\n",
" \"regionOfRegard\": NaN,\n",
" \"resourceID\": \"ivo://irsa.ipac/AKARI/Catalog/FISBSC\",\n",
" \"shortName\": \"AKARI/FIS [1]\",\n",
" \"subject\": \"#all sky survey#\",\n",
" \"tags\": \"Catalog\",\n",
" \"title\": \"AKARI/FIS All-Sky Survey Bright Source Catalogue\",\n",
" \"type\": \"#Catalog#\",\n",
" \"updated\": \"2017-07-25T00:13:41Z\",\n",
" \"url\": \"https://irsa.ipac.caltech.edu/SCS?table=akari_fis&\",\n",
" \"version\": \"\",\n",
" \"waveband\": \"#Infrared#Millimeter#\"\n",
"}\n"
]
}
],
"source": [
"# Select the one you want and inspect its metadata.\n",
"akari_cat = registry_db.get_catalog('AKARI/FIS All-Sky Survey Bright Source Catalogue 1')\n",
"print(akari_cat.dumps())"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from astropy import units as u\n",
"from astropy.coordinates import SkyCoord\n",
"from astroquery.vo_conesearch import conesearch"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Define your search object.\n",
"# See http://astropy.readthedocs.io/en/stable/coordinates/index.html\n",
"c = SkyCoord(0, 0, frame='icrs', unit='deg')\n",
"\n",
"# Define your search radius.\n",
"# See http://astropy.readthedocs.io/en/stable/units/index.html\n",
"sr = 0.1 * u.degree"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Unfortunately, due to a bug with this particular service, we need to sanitize the service URL a little below. See https://github.com/astropy/astroquery/issues/992 for more details."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"https://irsa.ipac.caltech.edu/SCS?table=akari_fis\n"
]
}
],
"source": [
"url = akari_cat['url'][:-1] # Remove [:-1] for astroquery>=0.3.7\n",
"print(url)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Trying https://irsa.ipac.caltech.edu/SCS?table=akari_fis\n"
]
}
],
"source": [
"result = conesearch.conesearch(c, sr, catalog_db=url)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'astropy.io.votable.tree.Table'>\n",
" objid objname ra ... spt_ind cntr \n",
" deg ... \n",
"------- -------------- ------------------- ... --------- ------\n",
"3119859 2359487-000418 359.952740 ... 132000000 119859\n"
]
}
],
"source": [
"# This is a VO Table object.\n",
"print(result.__class__)\n",
"print(result)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'astropy.table.table.Table'>\n",
" objid objname ra ... spt_ind cntr \n",
" deg ... \n",
"------- -------------- ------------------- ... --------- ------\n",
"3119859 2359487-000418 359.952740 ... 132000000 119859\n"
]
}
],
"source": [
"# Convert it to a more user-friendly Astropy Table object.\n",
"# See http://astropy.readthedocs.io/en/latest/table/index.html\n",
"tab = result.to_table()\n",
"print(tab.__class__)\n",
"print(tab)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Solution 2: If You Already Know the Service URL"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This solution also uses the \"new-style\" interface as recommended in AstroQuery."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from astropy import units as u\n",
"from astropy.coordinates import SkyCoord\n",
"from astroquery.vo_conesearch import ConeSearch"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"c = SkyCoord(0, 0, frame='icrs', unit='deg')\n",
"sr = 0.1 * u.degree"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"ConeSearch.URL = 'https://irsa.ipac.caltech.edu/SCS?table=akari_fis'\n",
"result = ConeSearch.query_region(c, sr)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" objid objname ra ... spt_ind cntr \n",
" deg ... \n",
"------- -------------- ------------------- ... --------- ------\n",
"3119859 2359487-000418 359.952740 ... 132000000 119859\n"
]
}
],
"source": [
"tab = result.to_table()\n",
"print(tab)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
" objid objname ra dec poserrmj poserrmi \\\n",
"0 3119859.0 b'2359487-000418' 359.95274 -0.07168 6.0 6.0 \n",
"\n",
" posserrpa flux65 flux90 flux140 ... mconf65 mconf90 mconf140 \\\n",
"0 0.0 0.1588 0.6644 1.092 ... 0.0 1.0 0.0 \n",
"\n",
" mconf160 ndens x y z spt_ind cntr \n",
"0 0.0 0.0 0.999999 -0.000825 -0.001251 132000000.0 119859.0 \n",
"\n",
"[1 rows x 41 columns]\n"
]
}
],
"source": [
"# And if you prefer pandas DataFrame\n",
"pantab = tab.to_pandas()\n",
"print(pantab.__class__)\n",
"print(pantab)"
]
}
],
"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.5.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment