forked from agy-why/rave-tap-pyvo-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rave-tutorial-submit-30m.py
61 lines (48 loc) · 1.42 KB
/
rave-tutorial-submit-30m.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from pkg_resources import parse_version
import requests
import pyvo as vo
import pandas as pd
from pyvo.dal import TAPService
#
# Verify the version of pyvo
#
if parse_version(vo.__version__) < parse_version('1.0'):
raise ImportError('pyvo version must larger than 1.0')
print('\npyvo version {version} \n'.format(version=vo.__version__))
#
# Setup tap_service
#
service_name = 'rave-survey.org'
url = "https://www.rave-survey.org/tap"
token = 'Token <your-token>'
print('TAP service {} \n'.format(service_name))
# Setup authorization
tap_session = requests.Session()
tap_session.headers['Authorization'] = token
tap_service = TAPService(url, session=tap_session)
#
# Submit the query as an async job
#
query_name = "multi_dr3"
lang = 'PostgreSQL'
query = '''
-- Multiple observations in DR3
SELECT F.raveid, F.radeg, F.dedeg, T.N
FROM
( SELECT raveid, count(*) AS N
FROM ravedr3.rave_dr3a
GROUP BY raveid
HAVING count(*) > 1
ORDER BY N DESC ) T JOIN ravedr3.rave_dr3a F
ON F.raveid = T.raveid
'''
job = tap_service.submit_job(query, language=lang, runid=query_name, queue="30m")
job.run()
print('JOB {name}: SUBMITTED'.format(name=job.job.runid))
print('JOB {name}: {status}'.format(name=job.job.runid , status=job.phase))
#
# Save the job's url in a file to later retrieve results.
#
print('URL: {}'.format(job.url))
with open('job_url.txt', 'w') as fd:
fd.write(job.url)