Skip to content

Commit be0938f

Browse files
authored
Merge pull request #2419 from mkelley/jplspec-doc-cleanup-2022.05
Test all jplspec code blocks except plots.
2 parents 4d54b64 + 012ac9a commit be0938f

File tree

1 file changed

+68
-77
lines changed

1 file changed

+68
-77
lines changed

docs/jplspec/jplspec.rst

Lines changed: 68 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ The units of the columns of the query can be displayed by calling
7171
... max_lines = 7)
7272
>>> print(response.info)
7373
<Table length=7>
74-
name dtype unit
74+
name dtype unit
7575
----- ------- -------
7676
FREQ float64 MHz
7777
ERR float64 MHz
@@ -213,108 +213,99 @@ to query these directly.
213213

214214
>>> from astroquery.jplspec import JPLSpec
215215
>>> import astropy.units as u
216-
>>> response = JPLSpec.query_lines_async(min_frequency=100 * u.GHz,
217-
... max_frequency=1000 * u.GHz,
218-
... min_strength=-500,
219-
... molecule="H2O",
220-
... parse_name_locally=True)
216+
>>> result = JPLSpec.query_lines(min_frequency=100 * u.GHz,
217+
... max_frequency=1000 * u.GHz,
218+
... min_strength=-500,
219+
... molecule="H2O",
220+
... parse_name_locally=True)
221+
>>> print(result)
222+
FREQ ERR LGINT DR ELO GUP TAG QNFMT QN' QN"
223+
MHz MHz MHz nm2 1 / cm
224+
----------- -------- -------- --- --------- --- ------ ----- -------- --------
225+
115542.5692 0.6588 -13.2595 3 4606.1683 35 18003 1404 17 810 0 18 513 0
226+
139614.293 0.15 -9.3636 3 3080.1788 87 -18003 1404 14 6 9 0 15 312 0
227+
177317.068 0.15 -10.3413 3 3437.2774 31 -18003 1404 15 610 0 16 313 0
228+
183310.087 0.001 -3.6463 3 136.1639 7 -18003 1404 3 1 3 0 2 2 0 0
229+
...
230+
Length = 2000 rows
231+
232+
Searches like these can lead to very broad queries, and may be limited in
233+
response length:
221234

222-
Searches like these can lead to very broad queries. Since the table yields
223-
extensive results, we will only show a dictionary of the tags that
224-
went into the payload to create a response:
235+
.. doctest-remote-data::
225236

237+
>>> print(result.meta['comments'])
238+
['', '', '', '', '', 'form is currently limited to 2000 lines. Please limit your search.']
226239

227-
.. We don't get these dictionaries as reponses, fix these examples and
228-
remove skip. #2408
240+
Inspecting the returned molecules shows that the 'H2O' string was processed as a
241+
regular expression, and the search matched any molecule that contained the
242+
combination of characters 'H2O':
229243

230-
.. doctest-skip::
244+
.. doctest-remote-data::
231245

232-
>>> {'CH2OO': 46014,
233-
... 'H2O': 18003,
234-
... 'H2O v2,2v2,v': 18005,
235-
... 'H2O-17': 19003,
236-
... 'H2O-18': 20003,
237-
... 'H2O2': 34004,
238-
... 'HCCCH2OD': 57003,
239-
... 'HCCCH2OH': 56010,
240-
... 'HCOCH2OH': 60006,
241-
... 'NH2CH2CH2OH': 61004}
242-
243-
As you can see, the 'H2O' string was processed as a regular expression,
244-
and the search matched any molecule that contained the combination of
245-
characters 'H20'.
246+
>>> tags = set(abs(result['TAG'])) # discard negative signs
247+
>>> species = {species: tag
248+
... for (species, tag) in JPLSpec.lookup_ids.items()
249+
... if tag in tags}
250+
>>> print(species)
251+
{'H2O': 18003, 'H2O v2,2v2,v': 18005, 'H2O-17': 19003, 'H2O-18': 20003, 'H2O2': 34004}
246252

247253
A few examples that show the power of the regex option are the following:
248254

249255
.. doctest-remote-data::
250256

251-
>>> response = JPLSpec.query_lines_async(min_frequency=100 * u.GHz,
252-
... max_frequency=1000 * u.GHz,
253-
... min_strength=-500,
254-
... molecule="H2O$",
255-
... parse_name_locally=True)
256-
257-
258-
The response:
259-
260-
.. doctest-skip::
261-
262-
>>> {'H2O': 18003}
263-
257+
>>> result = JPLSpec.query_lines(min_frequency=100 * u.GHz,
258+
... max_frequency=1000 * u.GHz,
259+
... min_strength=-500,
260+
... molecule="H2O$",
261+
... parse_name_locally=True)
262+
>>> tags = set(abs(result['TAG'])) # discard negative signs
263+
>>> species = {species: tag
264+
... for (species, tag) in JPLSpec.lookup_ids.items()
265+
... if tag in tags}
266+
>>> print(species)
267+
{'H2O': 18003}
264268

265269
As seen above, the regular expression "H2O$" yields only an exact match because
266270
the special character $ matches the end of the line. This functionality allows
267271
you to be as specific or vague as you want to allow the results to be:
268272

269273
.. doctest-remote-data::
270274

271-
>>> from astroquery.jplspec import JPLSpec
272-
>>> import astropy.units as u
273-
>>> response = JPLSpec.query_lines_async(min_frequency=100 * u.GHz,
274-
... max_frequency=1000 * u.GHz,
275-
... min_strength=-500,
276-
... molecule="^H.O$",
277-
... parse_name_locally=True)
275+
>>> result = JPLSpec.query_lines(min_frequency=100 * u.GHz,
276+
... max_frequency=1000 * u.GHz,
277+
... min_strength=-500,
278+
... molecule="^H.O$",
279+
... parse_name_locally=True)
280+
>>> tags = set(abs(result['TAG'])) # discard negative signs
281+
>>> species = {species: tag
282+
... for (species, tag) in JPLSpec.lookup_ids.items()
283+
... if tag in tags}
284+
>>> print(species)
285+
{'H2O': 18003, 'HDO': 19002, 'HCO': 29004, 'HNO': 31005}
278286

279287

280288
This pattern matches any word that starts with an H, ends with an O, and
281-
contains any character in between, it results in the following molecules
282-
being queried:
283-
284-
.. doctest-skip::
285-
286-
>>> {'H2O': 18003,
287-
... 'HDO': 19002
288-
... 'HCO': 29004
289-
... 'HNO': 31005 }
290-
289+
contains any character in between.
291290

292291
Another example of the functionality of this option is the option to obtain
293292
results from a molecule and its isotopes, in this case H2O and HDO:
294293

295294
.. doctest-remote-data::
296295

297-
>>> from astroquery.jplspec import JPLSpec
298-
>>> import astropy.units as u
299-
>>> response = JPLSpec.query_lines_async(min_frequency=100 * u.GHz,
300-
... max_frequency=1000 * u.GHz,
301-
... min_strength=-500,
302-
... molecule=r"^H[2D]O(-\d\d|)$",
303-
... parse_name_locally=True)
304-
305-
306-
This pattern matches any H2O and HDO isotopes and it results in the following
307-
molecules being part of the payload:
308-
309-
.. doctest-skip::
310-
311-
>>> {'H2O': 18003,
312-
... 'H2O-17': 19003,
313-
... 'H2O-18': 20003,
314-
... 'HDO': 19002,
315-
... 'HDO-18': 21001}
316-
317-
Remember to print your response to see the table of your results.
296+
>>> result = JPLSpec.query_lines(min_frequency=100 * u.GHz,
297+
... max_frequency=1000 * u.GHz,
298+
... min_strength=-500,
299+
... molecule=r"^H[2D]O(-\d\d|)$",
300+
... parse_name_locally=True)
301+
>>> tags = set(abs(result['TAG'])) # discard negative signs
302+
>>> species = {species: tag
303+
... for (species, tag) in JPLSpec.lookup_ids.items()
304+
... if tag in tags}
305+
>>> print(species)
306+
{'H2O': 18003, 'HDO': 19002, 'H2O-17': 19003, 'H2O-18': 20003, 'HDO-18': 21001}
307+
308+
This pattern matches any H2O and HDO isotopes.
318309

319310

320311
Reference/API

0 commit comments

Comments
 (0)