Skip to content

Commit ac341f3

Browse files
authored
Merge pull request #2696 from keflavich/splatalogue_args
Revert kwarg-only function arguments for splatalogue
2 parents 529721b + 8c24bb6 commit ac341f3

File tree

4 files changed

+162
-128
lines changed

4 files changed

+162
-128
lines changed

astroquery/splatalogue/core.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from . import load_species_table
1717
from .utils import clean_column_headings
1818

19+
from astropy.utils.decorators import deprecated_renamed_argument
20+
1921
__all__ = ['Splatalogue', 'SplatalogueClass']
2022

2123
# example query of SPLATALOGUE directly:
@@ -76,16 +78,18 @@ def set_default_options(self, **kwargs):
7678
"""
7779
self.data.update(self._parse_kwargs(**kwargs))
7880

79-
def get_species_ids(self, *, restr=None, reflags=0, recache=False):
81+
@deprecated_renamed_argument("restr", "species_regex", since="0.4.7")
82+
def get_species_ids(self, species_regex=None, *, reflags=0, recache=False):
8083
"""
8184
Get a dictionary of "species" IDs, where species refers to the molecule
8285
name, mass, and chemical composition.
8386
8487
Parameters
8588
----------
86-
restr : str
87-
String to compile into an re, if specified. Searches table for
88-
species whose names match
89+
species_regex : str
90+
String to search for among the species names, if specified.
91+
The string will be compiled into a regular expression using the
92+
python `re` module.
8993
reflags : int
9094
Flags to pass to `re`.
9195
recache : bool
@@ -95,7 +99,7 @@ def get_species_ids(self, *, restr=None, reflags=0, recache=False):
9599
--------
96100
>>> import re
97101
>>> import pprint # unfortunate hack required for documentation testing
98-
>>> rslt = Splatalogue.get_species_ids(restr='Formaldehyde')
102+
>>> rslt = Splatalogue.get_species_ids(species_regex='Formaldehyde')
99103
>>> pprint.pprint(rslt)
100104
{'03023 H2CO - Formaldehyde': '194',
101105
'03106 H213CO - Formaldehyde': '324',
@@ -106,8 +110,8 @@ def get_species_ids(self, *, restr=None, reflags=0, recache=False):
106110
'03204 HD13CO - Formaldehyde': '1219',
107111
'03301 D213CO - Formaldehyde': '1220',
108112
'03315 HDC18O - Formaldehyde': '21141',
109-
'0348 D2C18O - Formaldehyde': '21140'}
110-
>>> rslt = Splatalogue.get_species_ids(restr='H2CO')
113+
'03410 D2C18O - Formaldehyde': '21140'}
114+
>>> rslt = Splatalogue.get_species_ids(species_regex='H2CO')
111115
>>> pprint.pprint(rslt)
112116
{'03023 H2CO - Formaldehyde': '194',
113117
'03109 H2COH+ - Hydroxymethylium ion': '224',
@@ -125,9 +129,9 @@ def get_species_ids(self, *, restr=None, reflags=0, recache=False):
125129
'08903 CH3CHNH2COOH - II - α-Alanine': '1322'}
126130
>>> # note the whitespace, preventing H2CO within other
127131
>>> # more complex molecules
128-
>>> Splatalogue.get_species_ids(restr=' H2CO ')
132+
>>> Splatalogue.get_species_ids(species_regex=' H2CO ')
129133
{'03023 H2CO - Formaldehyde': '194'}
130-
>>> Splatalogue.get_species_ids(restr=' h2co ', reflags=re.IGNORECASE)
134+
>>> Splatalogue.get_species_ids(species_regex=' h2co ', reflags=re.IGNORECASE)
131135
{'03023 H2CO - Formaldehyde': '194'}
132136
133137
"""
@@ -136,8 +140,8 @@ def get_species_ids(self, *, restr=None, reflags=0, recache=False):
136140
if not hasattr(self, '_species_ids'):
137141
self._species_ids = load_species_table.species_lookuptable(recache=recache)
138142

139-
if restr is not None:
140-
return self._species_ids.find(restr, flags=reflags)
143+
if species_regex is not None:
144+
return self._species_ids.find(species_regex, flags=reflags)
141145
else:
142146
return self._species_ids
143147

@@ -319,7 +323,7 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None,
319323
payload['sid[]'] = []
320324
elif chemical_name is not None:
321325
if parse_chemistry_locally:
322-
species_ids = self.get_species_ids(restr=chemical_name, reflags=chem_re_flags)
326+
species_ids = self.get_species_ids(species_regex=chemical_name, reflags=chem_re_flags)
323327
if len(species_ids) == 0:
324328
raise ValueError("No matching chemical species found.")
325329
payload['sid[]'] = list(species_ids.values())
@@ -419,7 +423,7 @@ def _validate_kwargs(self, *, min_frequency=None, max_frequency=None,
419423
"a valid Band.")
420424

421425
@prepend_docstr_nosections("\n" + _parse_kwargs.__doc__)
422-
def query_lines_async(self, *, min_frequency=None, max_frequency=None,
426+
def query_lines_async(self, min_frequency=None, max_frequency=None, *,
423427
cache=True, **kwargs):
424428
"""
425429

astroquery/splatalogue/data/splat-species.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

astroquery/splatalogue/load_species_table.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ def species_lookuptable(*, filename='splat-species.json', recache=False):
6666
# check to see if the file exists; if not, we run the
6767
# scraping routine
6868
if recache or not os.path.isfile(file_cache):
69-
species = get_json_species_ids(filename)
69+
species = get_json_species_ids(outfile=filename)
7070
else:
7171
with open(data_path(filename), 'r') as f:
7272
species = json.load(f)
73+
7374
lookuptable = SpeciesLookuptable(dict((v, k) for d in species.values()
7475
for k, v in d.items()))
7576

0 commit comments

Comments
 (0)