Skip to content

Commit

Permalink
NIST: added ability to query of multiple linenames
Browse files Browse the repository at this point in the history
  • Loading branch information
nkphysics committed Mar 7, 2023
1 parent a6f3e0a commit 41d6b81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 9 additions & 3 deletions astroquery/nist/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def _args_to_payload(self, *args, **kwargs):
The lower wavelength for the spectrum in appropriate units.
maxwav : `astropy.units.Quantity` object
The upper wavelength for the spectrum in appropriate units.
linename : str, optional
The spectrum to fetch. Defaults to "H I"
linename : str or list, optional
The spectrum/spectra to fetch. Defaults to "H I"
energy_level_unit : str, optional
The energy level units must be one of the following:
'R', 'Rydberg', 'rydberg', 'cm', 'cm-1', 'EV', 'eV',
Expand All @@ -85,7 +85,13 @@ def _args_to_payload(self, *args, **kwargs):
"""
request_payload = {}
request_payload["spectra"] = kwargs['linename']
linename = kwargs["linename"]
if isinstance(linename, str):
request_payload["spectra"] = linename
elif isinstance(linename, list):
request_payload["spectra"] = " ".join(linename)
else:
raise TypeError("linename must str or list")
(min_wav, max_wav, wav_unit) = _parse_wavelength(args[0], args[1])
request_payload["low_wl"] = min_wav
request_payload["upp_wl"] = max_wav
Expand Down
7 changes: 7 additions & 0 deletions astroquery/nist/tests/test_nist.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def test_query_async(patch_get):
linename="H I", get_query_payload=True)
assert response['spectra'] == "H I"
assert response['unit'] == nist.core.Nist.unit_code['nm']
response = nist.core.Nist.query_async(4000 * u.nm, 7000 * u.nm,
linename=["H I", "Fe I"], get_query_payload=True)
assert response["spectra"] == "H I Fe I"
with pytest.raises(TypeError) as err:
nist.core.Nist.query_async(4000 * u.nm, 7000 * u.nm,
linename=("H I", "Fe"), get_query_payload=True)
assert str(err.value) == "linename must str or list"
response = nist.core.Nist.query_async(4000 * u.nm, 7000 * u.nm, linename="H I")
assert response is not None

Expand Down

0 comments on commit 41d6b81

Please sign in to comment.