Skip to content

Commit d901a3c

Browse files
authored
Merge pull request #2309 from bsipocz/alma_deprecation_cleanup
Alma deprecation cleanup
2 parents 60db44d + f71fbb7 commit d901a3c

File tree

4 files changed

+34
-264
lines changed

4 files changed

+34
-264
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ esa.hubble
2020

2121
- Changed query_target method to use TAP instead of AIO [#2268]
2222

23+
alma
24+
^^^^
25+
26+
- Deprecated keywords and ``stage_data`` method has been removed. Optional
27+
keyword arguments are now keyword only. [#2309]
28+
2329
casda
2430
^^^^^
2531

astroquery/alma/core.py

Lines changed: 14 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
import string
99
import requests
1010
import warnings
11+
1112
from pkg_resources import resource_filename
1213
from bs4 import BeautifulSoup
1314
import pyvo
14-
1515
from urllib.parse import urljoin
16+
1617
from astropy.table import Table, Column, vstack
1718
from astroquery import log
18-
from astropy.utils import deprecated
1919
from astropy.utils.console import ProgressBar
20-
from astropy.utils.exceptions import AstropyDeprecationWarning
2120
from astropy import units as u
2221
from astropy.time import Time
2322
from pyvo.dal.sia2 import SIA_PARAMETERS_DESC
@@ -236,7 +235,7 @@ def tap(self):
236235
self._tap = pyvo.dal.tap.TAPService(baseurl=self.tap_url)
237236
return self._tap
238237

239-
def query_object_async(self, object_name, cache=None, public=True,
238+
def query_object_async(self, object_name, *, public=True,
240239
science=True, payload=None, **kwargs):
241240
"""
242241
Query the archive for a source name.
@@ -245,7 +244,6 @@ def query_object_async(self, object_name, cache=None, public=True,
245244
----------
246245
object_name : str
247246
The object name. Will be resolved by astropy.coord.SkyCoord
248-
cache : deprecated
249247
public : bool
250248
True to return only public datasets, False to return private only,
251249
None to return both
@@ -262,7 +260,7 @@ def query_object_async(self, object_name, cache=None, public=True,
262260
return self.query_async(public=public, science=science,
263261
payload=payload, **kwargs)
264262

265-
def query_region_async(self, coordinate, radius, cache=None, public=True,
263+
def query_region_async(self, coordinate, radius, *, public=True,
266264
science=True, payload=None, **kwargs):
267265
"""
268266
Query the ALMA archive with a source name and radius
@@ -273,8 +271,6 @@ def query_region_async(self, coordinate, radius, cache=None, public=True,
273271
the identifier or coordinates around which to query.
274272
radius : str / `~astropy.units.Quantity`, optional
275273
the radius of the region
276-
cache : Deprecated
277-
Cache the query?
278274
public : bool
279275
True to return only public datasets, False to return private only,
280276
None to return both
@@ -299,18 +295,15 @@ def query_region_async(self, coordinate, radius, cache=None, public=True,
299295
return self.query_async(public=public, science=science,
300296
payload=payload, **kwargs)
301297

302-
def query_async(self, payload, cache=None, public=True, science=True,
303-
legacy_columns=False, max_retries=None,
304-
get_html_version=None,
305-
get_query_payload=None, **kwargs):
298+
def query_async(self, payload, *, public=True, science=True,
299+
legacy_columns=False, get_query_payload=None, **kwargs):
306300
"""
307301
Perform a generic query with user-specified payload
308302
309303
Parameters
310304
----------
311305
payload : dictionary
312306
Please consult the `help` method
313-
cache : deprecated
314307
public : bool
315308
True to return only public datasets, False to return private only,
316309
None to return both
@@ -327,17 +320,6 @@ def query_async(self, payload, cache=None, public=True, science=True,
327320
Table with results. Columns are those in the ALMA ObsCore model
328321
(see ``help_tap``) unless ``legacy_columns`` argument is set to True.
329322
"""
330-
local_args = dict(locals().items())
331-
332-
for arg in local_args:
333-
# check if the deprecated attributes have been used
334-
for dep in ['cache', 'max_retries', 'get_html_version']:
335-
if arg[0] == dep and arg[1] is not None:
336-
warnings.warn(
337-
("Argument '{}' has been deprecated "
338-
"since version 4.0.1 and will be ignored".format(arg[0])),
339-
AstropyDeprecationWarning)
340-
del kwargs[arg[0]]
341323

342324
if payload is None:
343325
payload = {}
@@ -385,7 +367,7 @@ def query_async(self, payload, cache=None, public=True, science=True,
385367
return legacy_result
386368
return result
387369

388-
def query_sia(self, pos=None, band=None, time=None, pol=None,
370+
def query_sia(self, *, pos=None, band=None, time=None, pol=None,
389371
field_of_view=None, spatial_resolution=None,
390372
spectral_resolving_power=None, exptime=None,
391373
timeres=None, publisher_did=None,
@@ -500,54 +482,7 @@ def _get_dataarchive_url(self):
500482
"on github.")
501483
return self.dataarchive_url
502484

503-
@deprecated(since="v0.4.1", alternative="get_data_info")
504-
def stage_data(self, uids, expand_tarfiles=False, return_json=False):
505-
"""
506-
Obtain table of ALMA files
507-
508-
DEPRECATED: Data is no longer staged. This method is deprecated and
509-
kept here for backwards compatibility reasons but it's not fully
510-
compatible with the original implementation.
511-
512-
Parameters
513-
----------
514-
uids : list or str
515-
A list of valid UIDs or a single UID.
516-
UIDs should have the form: 'uid://A002/X391d0b/X7b'
517-
expand_tarfiles : DEPRECATED
518-
return_json : DEPRECATED
519-
Note: The returned astropy table can be easily converted to json
520-
through pandas:
521-
output = StringIO()
522-
stage_data(...).to_pandas().to_json(output)
523-
table_json = output.getvalue()
524-
525-
Returns
526-
-------
527-
data_file_table : Table
528-
A table containing 3 columns: the UID, the file URL (for future
529-
downloading), and the file size
530-
"""
531-
532-
if return_json:
533-
raise AttributeError(
534-
'return_json is deprecated. See method docs for a workaround')
535-
table = Table()
536-
res = self.get_data_info(uids, expand_tarfiles=expand_tarfiles)
537-
p = re.compile(r'.*(uid__.*)\.asdm.*')
538-
if res:
539-
table['name'] = [u.split('/')[-1] for u in res['access_url']]
540-
table['id'] = [p.search(x).group(1) if 'asdm' in x else 'None'
541-
for x in table['name']]
542-
table['type'] = res['content_type']
543-
table['size'] = res['content_length']
544-
table['permission'] = ['UNKNOWN'] * len(res)
545-
table['mous_uid'] = [uids] * len(res)
546-
table['URL'] = res['access_url']
547-
table['isProprietary'] = res['readable']
548-
return table
549-
550-
def get_data_info(self, uids, expand_tarfiles=False,
485+
def get_data_info(self, uids, *, expand_tarfiles=False,
551486
with_auxiliary=True, with_rawdata=True):
552487

553488
"""
@@ -685,7 +620,7 @@ def _HEADER_data_size(self, files):
685620

686621
return data_sizes, totalsize.to(u.GB)
687622

688-
def download_files(self, files, savedir=None, cache=True,
623+
def download_files(self, files, *, savedir=None, cache=True,
689624
continuation=True, skip_unauthorized=True,
690625
verify_only=False):
691626
"""
@@ -821,7 +756,7 @@ def _parse_result(self, response, verbose=False):
821756

822757
return response
823758

824-
def retrieve_data_from_uid(self, uids, cache=True):
759+
def retrieve_data_from_uid(self, uids, *, cache=True):
825760
"""
826761
Stage & Download ALMA data. Will print out the expected file size
827762
before attempting the download.
@@ -854,7 +789,7 @@ def retrieve_data_from_uid(self, uids, cache=True):
854789
downloaded_files = self.download_files(file_urls)
855790
return downloaded_files
856791

857-
def _get_auth_info(self, username, store_password=False,
792+
def _get_auth_info(self, username, *, store_password=False,
858793
reenter_password=False):
859794
"""
860795
Get the auth info (user, password) for use in another function
@@ -1032,7 +967,7 @@ def cycle0_table(self):
1032967
self._cycle0_table.rename_column('col2', 'uid')
1033968
return self._cycle0_table
1034969

1035-
def get_files_from_tarballs(self, downloaded_files, regex=r'.*\.fits$',
970+
def get_files_from_tarballs(self, downloaded_files, *, regex=r'.*\.fits$',
1036971
path='cache_path', verbose=True):
1037972
"""
1038973
Given a list of successfully downloaded tarballs, extract files
@@ -1082,7 +1017,7 @@ def get_files_from_tarballs(self, downloaded_files, regex=r'.*\.fits$',
10821017

10831018
return filelist
10841019

1085-
def download_and_extract_files(self, urls, delete=True, regex=r'.*\.fits$',
1020+
def download_and_extract_files(self, urls, *, delete=True, regex=r'.*\.fits$',
10861021
include_asdm=False, path='cache_path',
10871022
verbose=True):
10881023
"""
@@ -1196,53 +1131,7 @@ def help(self, cache=True):
11961131
print("Alma.query(payload=dict(project_code='2017.1.01355.L', "
11971132
"source_name_alma='G008.67'))")
11981133

1199-
def _json_summary_to_table(self, data, base_url):
1200-
"""
1201-
Special tool to convert some JSON metadata to a table Obsolete as of
1202-
March 2020 - should be removed along with stage_data_prefeb2020
1203-
"""
1204-
from ..utils import url_helpers
1205-
columns = {'mous_uid': [], 'URL': [], 'size': []}
1206-
for entry in data['node_data']:
1207-
# de_type can be useful (e.g., MOUS), but it is not necessarily
1208-
# specified
1209-
# file_name and file_key *must* be specified.
1210-
is_file = \
1211-
(entry['file_name'] != 'null' and entry['file_key'] != 'null')
1212-
if is_file:
1213-
# "de_name": "ALMA+uid://A001/X122/X35e",
1214-
columns['mous_uid'].append(entry['de_name'][5:])
1215-
if entry['file_size'] == 'null':
1216-
columns['size'].append(np.nan * u.Gbyte)
1217-
else:
1218-
columns['size'].append(
1219-
(int(entry['file_size']) * u.B).to(u.Gbyte))
1220-
# example template for constructing url:
1221-
# https://almascience.eso.org/dataPortal/requests/keflavich/940238268/ALMA/
1222-
# uid___A002_X9d6f4c_X154/2013.1.00546.S_uid___A002_X9d6f4c_X154.asdm.sdm.tar
1223-
# above is WRONG... except for ASDMs, when it's right
1224-
# should be:
1225-
# 2013.1.00546.S_uid___A002_X9d6f4c_X154.asdm.sdm.tar/2013.1.00546.S_uid___A002_X9d6f4c_X154.asdm.sdm.tar
1226-
#
1227-
# apparently ASDMs are different from others:
1228-
# templates:
1229-
# https://almascience.eso.org/dataPortal/requests/keflavich/946895898/ALMA/
1230-
# 2013.1.00308.S_uid___A001_X196_X93_001_of_001.tar/2013.1.00308.S_uid___A001_X196_X93_001_of_001.tar
1231-
# uid___A002_X9ee74a_X26f0/2013.1.00308.S_uid___A002_X9ee74a_X26f0.asdm.sdm.tar
1232-
url = url_helpers.join(base_url,
1233-
entry['file_key'],
1234-
entry['file_name'])
1235-
if 'null' in url:
1236-
raise ValueError("The URL {0} was created containing "
1237-
"'null', which is invalid.".format(url))
1238-
columns['URL'].append(url)
1239-
1240-
columns['size'] = u.Quantity(columns['size'], u.Gbyte)
1241-
1242-
tbl = Table([Column(name=k, data=v) for k, v in columns.items()])
1243-
return tbl
1244-
1245-
def get_project_metadata(self, projectid, cache=True):
1134+
def get_project_metadata(self, projectid, *, cache=True):
12461135
"""
12471136
Get the metadata - specifically, the project abstract - for a given project ID.
12481137
"""

0 commit comments

Comments
 (0)