Skip to content

Commit e0f140b

Browse files
committed
Added cusom ADQL and TAP+ functionality to ESASky module
1 parent 0de7f0e commit e0f140b

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

astroquery/esasky/core.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from requests import ConnectionError
1818

1919
from ..query import BaseQuery
20+
from ..utils.tap.core import TapPlus
2021
from ..utils import commons
2122
from ..utils import async_to_sync
2223
from . import conf
@@ -75,6 +76,115 @@ class ESASkyClass(BaseQuery):
7576
_SPECTRA_DOWNLOAD_DIR = "Spectra"
7677
_isTest = ""
7778

79+
def __init__(self, tap_handler=None):
80+
super(ESASkyClass, self).__init__()
81+
82+
if tap_handler is None:
83+
self._tap = TapPlus(url="https://sky.esa.int/esasky-tap/tap/")
84+
else:
85+
self._tap = tap_handler
86+
87+
def query(self, query, *, output_file=None,
88+
output_format="votable", verbose=False):
89+
"""Launches a synchronous job to query the ESASky TAP
90+
91+
Parameters
92+
----------
93+
query : str, mandatory
94+
query (adql) to be executed
95+
output_file : str, optional, default None
96+
file name where the results are saved if dumpToFile is True.
97+
If this parameter is not provided, the jobid is used instead
98+
output_format : str, optional, default 'votable'
99+
possible values 'votable' or 'csv'
100+
verbose : bool, optional, default 'False'
101+
flag to display information about the process
102+
103+
Returns
104+
-------
105+
A table object
106+
"""
107+
job = self._tap.launch_job(query=query, output_file=output_file,
108+
output_format=output_format,
109+
verbose=verbose,
110+
dump_to_file=output_file is not None)
111+
return job.get_results()
112+
113+
def get_tables(self, *, only_names=True, verbose=False):
114+
"""
115+
Get the available table in ESASky TAP service
116+
117+
Parameters
118+
----------
119+
only_names : bool, optional, default 'True'
120+
True to load table names only
121+
verbose : bool, optional, default 'False'
122+
flag to display information about the process
123+
124+
Returns
125+
-------
126+
A list of tables
127+
"""
128+
129+
tables = self._tap.load_tables(only_names=only_names,
130+
include_shared_tables=False,
131+
verbose=verbose)
132+
if only_names:
133+
return [t.name for t in tables]
134+
else:
135+
return tables
136+
137+
def get_columns(self, table_name, *, only_names=True, verbose=False):
138+
"""
139+
Get the available columns for a table in ESASky TAP service
140+
141+
Parameters
142+
----------
143+
table_name : string, mandatory, default None
144+
table name of which, columns will be returned
145+
only_names : bool, optional, default 'True'
146+
True to load table names only
147+
verbose : bool, optional, default 'False'
148+
flag to display information about the process
149+
150+
Returns
151+
-------
152+
A list of columns
153+
"""
154+
155+
tables = self._tap.load_tables(only_names=False,
156+
include_shared_tables=False,
157+
verbose=verbose)
158+
columns = None
159+
for table in tables:
160+
if str(table.name) == str(table_name):
161+
columns = table.columns
162+
break
163+
164+
if columns is None:
165+
raise ValueError("table name specified is not found in "
166+
"ESASky TAP service")
167+
168+
if only_names:
169+
return [c.name for c in columns]
170+
else:
171+
return columns
172+
173+
def get_tap(self):
174+
"""
175+
Get a TAP+ instance for the ESASky servers, which supports
176+
all common TAP+ operations (synchronous & asynchronous queries,
177+
uploading of tables, table sharing and more)
178+
Full documentation and examples available here:
179+
https://astroquery.readthedocs.io/en/latest/utils/tap.html
180+
181+
Returns
182+
-------
183+
tap : `~astroquery.utils.tap.core.TapPlus`
184+
"""
185+
186+
return self._tap
187+
78188
def list_maps(self):
79189
"""
80190
Get a list of the mission names of the available observations in ESASky

0 commit comments

Comments
 (0)