Skip to content

Commit d606686

Browse files
authored
Merge pull request #2158 from jd-au/CASDA-6719-stage-data
Allow non image data to be retrieved
2 parents 9a2864c + 2dd51b4 commit d606686

File tree

6 files changed

+74
-11
lines changed

6 files changed

+74
-11
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ New Tools and Services
1010
Service fixes and enhancements
1111
------------------------------
1212

13+
casda
14+
^^^^^^
15+
16+
- Add ability to stage and download non image data which have been found
17+
through the CASDA obscore table. [#2158]
18+
1319
vizier
1420
^^^^^^
1521

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ The following modules have been completed using a common API:
109109
* `Besancon <http://astroquery.readthedocs.io/en/latest/besancon/besancon.html>`_: Model of stellar population synthesis in the Galaxy.
110110
* `CDS MOC Service <https://astroquery.readthedocs.io/en/latest/cds/cds.html>`_: A collection of all-sky survey coverage maps.
111111
* `CADC <https://astroquery.readthedocs.io/en/latest/cadc/cadc.html>`_: Canadian Astronomy Data Centre.
112+
* `CASDA <https://astroquery.readthedocs.io/en/latest/casda/casda.html>`_: CSIRO ASKAP Science Data Archive.
112113
* `ESASky <http://astroquery.readthedocs.io/en/latest/esasky/esasky.html>`_: ESASky is a science driven discovery portal providing easy visualizations and full access to the entire sky as observed with ESA Space astronomy missions.
113114
* `ESO Archive <http://astroquery.readthedocs.io/en/latest/eso/eso.html>`_
114115
* `FIRST <http://astroquery.readthedocs.io/en/latest/image_cutouts/first/first.html>`_: Faint Images of the Radio Sky at Twenty-cm. 20-cm radio images of the extragalactic sky from the VLA.

astroquery/casda/core.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,21 @@ def stage_data(self, table, verbose=False):
184184

185185
# Use datalink to get authenticated access for each file
186186
tokens = []
187+
soda_url = None
187188
for row in table:
188189
access_url = row['access_url']
189-
response = self._request('GET', access_url, auth=self._auth,
190-
timeout=self.TIMEOUT, cache=False)
191-
response.raise_for_status()
192-
soda_url, id_token = self._parse_datalink_for_service_and_id(response, 'cutout_service')
193-
tokens.append(id_token)
190+
if access_url:
191+
response = self._request('GET', access_url, auth=self._auth,
192+
timeout=self.TIMEOUT, cache=False)
193+
response.raise_for_status()
194+
service_url, id_token = self._parse_datalink_for_service_and_id(response, 'async_service')
195+
if id_token:
196+
tokens.append(id_token)
197+
soda_url = service_url
198+
199+
# Trap a request with no allowed data
200+
if not soda_url:
201+
raise ValueError('You do not have access to any of the requested data files.')
194202

195203
# Create job to stage all files
196204
job_url = self._create_soda_job(tokens, soda_url=soda_url)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?xml-stylesheet href='https://data.csiro.au/casda_vo_proxy/vo/votable.xsl' type='text/xsl' ?>
2+
3+
<VOTABLE xmlns="http://www.ivoa.net/xml/VOTable/v1.3" version="1.3">
4+
<RESOURCE name="CASDA Datalink Result" type="results">
5+
<TABLE>
6+
<FIELD datatype="char" name="ID" ucd="meta.id;meta.main" arraysize="*"/>
7+
<FIELD datatype="char" name="access_url" ucd="meta.ref.url" arraysize="*"/>
8+
<FIELD datatype="char" name="service_def" ucd="meta.ref" arraysize="*"/>
9+
<FIELD datatype="char" name="error_message" ucd="meta.code.error" arraysize="*"/>
10+
<FIELD datatype="char" name="description" ucd="meta.note" arraysize="*"/>
11+
<FIELD datatype="char" name="semantics" ucd="meta.code" arraysize="*"/>
12+
<FIELD datatype="char" name="content_type" ucd="meta.code.mime" arraysize="*"/>
13+
<FIELD unit="byte" datatype="long" name="content_length" ucd="phys.size;meta.file"/>
14+
<FIELD ID="authenticatedIdToken" datatype="char" name="authenticated_id_token" ucd="meta.id" arraysize="*"/>
15+
<DATA>
16+
<TABLEDATA>
17+
<TR>
18+
<TD>3242</TD>
19+
<TD/>
20+
<TD/>
21+
<TD>DefaultFault: Sorry, but you do not have permission to access this data product</TD>
22+
<TD/>
23+
<TD>#error</TD>
24+
<TD/>
25+
<TD/>
26+
<TD/>
27+
</TR>
28+
</TABLEDATA>
29+
</DATA>
30+
</TABLE>
31+
</RESOURCE>
32+
</VOTABLE>

astroquery/casda/tests/test_casda.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
pytest.skip("Install mock for the casda tests.", allow_module_level=True)
2222

2323
DATA_FILES = {'CIRCLE': 'cone.xml', 'RANGE': 'box.xml', 'DATALINK': 'datalink.xml', 'RUN_JOB': 'run_job.xml',
24-
'COMPLETED_JOB': 'completed_job.xml'}
24+
'COMPLETED_JOB': 'completed_job.xml', 'DATALINK_NOACCESS': 'datalink_noaccess.xml'}
2525

2626

2727
class MockResponse:
@@ -59,7 +59,10 @@ def get_mockreturn(self, method, url, data=None, timeout=10,
5959
else:
6060
raise ValueError("Unexpected SODA async {} call to url {}".format(method, url))
6161
elif 'datalink' in str(url):
62-
key = 'DATALINK'
62+
if 'cube-244' in str(url):
63+
key = 'DATALINK'
64+
else:
65+
key = 'DATALINK_NOACCESS'
6366
else:
6467
key = params['POS'].split()[0] if params['POS'] else None
6568
filename = data_path(DATA_FILES[key])
@@ -257,6 +260,19 @@ def test_stage_data_invalid_credentials(patch_get):
257260
casda.stage_data(table)
258261

259262

263+
def test_stage_data_no_link(patch_get):
264+
prefix = 'https://somewhere/casda/datalink/links?'
265+
access_urls = [prefix + 'cube-240']
266+
table = Table([Column(data=access_urls, name='access_url')])
267+
casda = Casda('user', 'password')
268+
casda.POLL_INTERVAL = 1
269+
270+
with pytest.raises(ValueError) as excinfo:
271+
casda.stage_data(table)
272+
273+
assert "You do not have access to any of the requested data files." in str(excinfo.value)
274+
275+
260276
def test_stage_data(patch_get):
261277
prefix = 'https://somewhere/casda/datalink/links?'
262278
access_urls = [prefix + 'cube-244']

docs/casda/casda.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ For example:
2727
>>> from astropy import units as u
2828
>>> centre = SkyCoord.from_name('NGC 7232')
2929
>>> result_table = Casda.query_region(centre, radius=30*u.arcmin)
30-
>>> print(result_table['obs_publisher_did','s_ra', 's_dec', 'obs_released_date'])
31-
obs_publisher_did s_ra s_dec obs_released_date
30+
>>> print(result_table['obs_publisher_did','s_ra', 's_dec', 'obs_release_date'])
31+
obs_publisher_did s_ra s_dec obs_release_date
3232
deg deg
3333
----------------- --------------- ---------------- ------------------------
3434
cube-502 333.16767306594 -45.302084636451 2017-08-02T03:51:19.728Z
@@ -64,8 +64,8 @@ For example to filter out the 30 non-public results from the above data set:
6464
.. code-block:: python
6565
6666
>>> public_results = Casda.filter_out_unreleased(result_table)
67-
>>> print(public_results['obs_publisher_did','s_ra', 's_dec', 'obs_released_date'])
68-
obs_publisher_did s_ra s_dec obs_released_date
67+
>>> print(public_results['obs_publisher_did','s_ra', 's_dec', 'obs_release_date'])
68+
obs_publisher_did s_ra s_dec obs_release_date
6969
deg deg
7070
----------------- --------------- ---------------- ------------------------
7171
cube-502 333.16767306594 -45.302084636451 2017-08-02T03:51:19.728Z

0 commit comments

Comments
 (0)