Skip to content

Instantly share code, notes, and snippets.

@smoh
Created June 28, 2019 13:53
Show Gist options
  • Save smoh/b57567e0d52ec787afbdd3d6ec6fd781 to your computer and use it in GitHub Desktop.
Save smoh/b57567e0d52ec787afbdd3d6ec6fd781 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# A possible solution to astroqeury issue.\n",
"\n",
"https://github.com/astropy/astroquery/issues/1490"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from astropy.table import Table\n",
"import pyvo"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"simbad_tap_baseurl = 'http://simbad.u-strasbg.fr/simbad/sim-tap/'\n",
"simbad = pyvo.dal.TAPService(simbad_tap_baseurl)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# just testing out to make sure everything's consistent\n",
"r = simbad.run_sync(\"\"\"\n",
"SELECT nbobject\n",
"FROM ref\n",
"WHERE bibcode='2019A&A...625A..80K';\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Table masked=True length=1>\n",
"nbobject\n",
" int32 \n",
"--------\n",
" 5"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"r"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use synchronous ADQL with an uploaded table to query for a number of queries\n",
"\n",
"I think 3000 bibcodes should be fine with synchronous. Below just try three."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"from io import BytesIO"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<i>Table length=3</i>\n",
"<table id=\"table4809893424\" class=\"table-striped table-bordered table-condensed\">\n",
"<thead><tr><th>bibcode</th></tr></thead>\n",
"<thead><tr><th>str19</th></tr></thead>\n",
"<tr><td>2019A&amp;A...625A..80K</td></tr>\n",
"<tr><td>2019A&amp;A...625A..80K</td></tr>\n",
"<tr><td>2019A&amp;A...625A..80K</td></tr>\n",
"</table>"
],
"text/plain": [
"<Table length=3>\n",
" bibcode \n",
" str19 \n",
"-------------------\n",
"2019A&A...625A..80K\n",
"2019A&A...625A..80K\n",
"2019A&A...625A..80K"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t = Table({'bibcode':['2019A&A...625A..80K', '2019A&A...625A..80K', '2019A&A...625A..80K']})\n",
"t"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# prepare file-like object without writing to disk.\n",
"f = BytesIO()\n",
"t.write(f, format='votable')\n",
"f.seek(0)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"r1 = simbad.run_sync(\"\"\"\n",
"select ref.nbobject\n",
"from tmp\n",
"left join ref on tmp.bibcode = ref.bibcode;\"\"\", uploads={'tmp':f})"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Table masked=True length=3>\n",
"nbobject\n",
" int32 \n",
"--------\n",
" 5\n",
" 5\n",
" 5"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"r1"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\u001b[0;31mSignature:\u001b[0m\n",
"\u001b[0msimbad\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun_sync\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mquery\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mlanguage\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'ADQL'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mmaxrec\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0muploads\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkeywords\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mSource:\u001b[0m \n",
" \u001b[0;32mdef\u001b[0m \u001b[0mrun_sync\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mquery\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlanguage\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"ADQL\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmaxrec\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0muploads\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkeywords\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0;34m\"\"\"\u001b[0m\n",
"\u001b[0;34m runs sync query and returns its result\u001b[0m\n",
"\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m Parameters\u001b[0m\n",
"\u001b[0;34m ----------\u001b[0m\n",
"\u001b[0;34m query : str\u001b[0m\n",
"\u001b[0;34m The query\u001b[0m\n",
"\u001b[0;34m language : str\u001b[0m\n",
"\u001b[0;34m specifies the query language, default ADQL.\u001b[0m\n",
"\u001b[0;34m useful for services which allow to use the backend query language.\u001b[0m\n",
"\u001b[0;34m maxrec : int\u001b[0m\n",
"\u001b[0;34m the maximum records to return. defaults to the service default\u001b[0m\n",
"\u001b[0;34m uploads : dict\u001b[0m\n",
"\u001b[0;34m a mapping from table names to objects containing a votable\u001b[0m\n",
"\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m Returns\u001b[0m\n",
"\u001b[0;34m -------\u001b[0m\n",
"\u001b[0;34m TAPResults\u001b[0m\n",
"\u001b[0;34m the query result\u001b[0m\n",
"\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m See Also\u001b[0m\n",
"\u001b[0;34m --------\u001b[0m\n",
"\u001b[0;34m TAPResults\u001b[0m\n",
"\u001b[0;34m \"\"\"\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate_query\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mquery\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlanguage\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlanguage\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmaxrec\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmaxrec\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0muploads\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0muploads\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkeywords\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mFile:\u001b[0m ~/miniconda3/lib/python3.7/site-packages/pyvo/dal/tap.py\n",
"\u001b[0;31mType:\u001b[0m method\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"simbad.run_sync??"
]
}
],
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment