88import warnings
99from astropy .io import ascii
1010from astropy import units as u
11+ from astropy import log
1112from ..query import BaseQuery
1213from ..utils import async_to_sync
1314from ..utils .docstr_chompers import prepend_docstr_noreturns
@@ -129,7 +130,8 @@ def _parse_kwargs(self, min_frequency=None, max_frequency=None,
129130 show_upper_degeneracy = None , show_molecule_tag = None ,
130131 show_qn_code = None , show_lovas_labref = None ,
131132 show_lovas_obsref = None , show_orderedfreq_only = None ,
132- show_nrao_recommended = None ):
133+ show_nrao_recommended = None ,
134+ parse_chemistry_locally = False ):
133135 """
134136 The Splatalogue service returns lines with rest frequencies in the
135137 range [min_frequency, max_frequency].
@@ -164,7 +166,9 @@ def _parse_kwargs(self, min_frequency=None, max_frequency=None,
164166
165167 ``' H2CO '`` - Just 1 species, H2CO. The spaces prevent including
166168 others.
167-
169+ parse_chemistry_locally : bool
170+ Attempt to determine the species ID #'s locally before sending the
171+ query? This will prevent queries that have no matching species.
168172 chem_re_flags : int
169173 See the `re` module
170174 energy_min : `None` or float
@@ -185,7 +189,9 @@ def _parse_kwargs(self, min_frequency=None, max_frequency=None,
185189 exclude : list
186190 Types of lines to exclude. Default is:
187191 (``'potential'``, ``'atmospheric'``, ``'probable'``)
188- Can also exclude ``'known'``
192+ Can also exclude ``'known'``.
193+ To exclude nothing, use 'none', not the python object None, since
194+ the latter is meant to indicate 'leave as default'
189195 only_NRAO_recommended : bool
190196 Show only NRAO recommended species?
191197 line_lists : list
@@ -264,10 +270,13 @@ def _parse_kwargs(self, min_frequency=None, max_frequency=None,
264270 # include all
265271 payload ['sid[]' ] = []
266272 elif chemical_name is not None :
267- species_ids = self .get_species_ids (chemical_name , chem_re_flags )
268- if len (species_ids ) == 0 :
269- raise ValueError ("No matching chemical species found." )
270- payload ['sid[]' ] = list (species_ids .values ())
273+ if parse_chemistry_locally :
274+ species_ids = self .get_species_ids (chemical_name , chem_re_flags )
275+ if len (species_ids ) == 0 :
276+ raise ValueError ("No matching chemical species found." )
277+ payload ['sid[]' ] = list (species_ids .values ())
278+ else :
279+ payload ['chemical_name' ] = chemical_name
271280
272281 if energy_min is not None :
273282 payload ['energy_range_from' ] = float (energy_min )
@@ -291,7 +300,12 @@ def _parse_kwargs(self, min_frequency=None, max_frequency=None,
291300 raise ValueError ("Invalid version specified. Allowed versions "
292301 "are {vers}" .format (vers = str (self .versions )))
293302
294- if exclude is not None :
303+ if exclude == 'none' :
304+ for e in ('potential' , 'atmospheric' , 'probable' , 'known' ):
305+ # Setting a keyword value to 'None' removes it (see query_lines_async)
306+ log .debug ("Setting no_{0} to None" .format (e ))
307+ payload ['no_' + e ] = None
308+ elif exclude is not None :
295309 for e in exclude :
296310 payload ['no_' + e ] = 'no_' + e
297311
@@ -383,6 +397,9 @@ def query_lines_async(self, min_frequency=None, max_frequency=None,
383397 max_frequency = max_frequency ,
384398 ** kwargs ))
385399
400+ # Add an extra step: sometimes, need to REMOVE keywords
401+ data_payload = {k :v for k ,v in data_payload .items () if v is not None }
402+
386403 if get_query_payload :
387404 return data_payload
388405
0 commit comments