Skip to content

Commit d0e8773

Browse files
authored
Merge pull request #2678 from nkphysics/vectorize-nist
NIST Vectorizing
2 parents 770949e + 0475354 commit d0e8773

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ mast
144144

145145
- Expanding ``Cutouts`` functionality to support TICA HLSPs now available through
146146
``TesscutClass``. [##2668]
147+
148+
nist
149+
^^^^
150+
151+
- Vectoized ``linename`` option to query multiple spectral lines with one call
152+
of ``Nist.query``. [#2678]
147153

148154
oac
149155
^^^

astroquery/nist/core.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ def _args_to_payload(self, *args, **kwargs):
6363
The lower wavelength for the spectrum in appropriate units.
6464
maxwav : `astropy.units.Quantity` object
6565
The upper wavelength for the spectrum in appropriate units.
66-
linename : str, optional
67-
The spectrum to fetch. Defaults to "H I"
66+
linename : str or iterable of str, optional
67+
The spectrum/spectra to fetch. Defaults to "H I"
6868
energy_level_unit : str, optional
6969
The energy level units must be one of the following:
7070
'R', 'Rydberg', 'rydberg', 'cm', 'cm-1', 'EV', 'eV',
@@ -85,7 +85,8 @@ def _args_to_payload(self, *args, **kwargs):
8585
8686
"""
8787
request_payload = {}
88-
request_payload["spectra"] = kwargs['linename']
88+
linename = kwargs["linename"]
89+
request_payload["spectra"] = linename if isinstance(linename, str) else "; ".join(linename)
8990
(min_wav, max_wav, wav_unit) = _parse_wavelength(args[0], args[1])
9091
request_payload["low_wl"] = min_wav
9192
request_payload["upp_wl"] = max_wav

astroquery/nist/tests/test_nist.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ def test_query_async(patch_get):
4545
linename="H I", get_query_payload=True)
4646
assert response['spectra'] == "H I"
4747
assert response['unit'] == nist.core.Nist.unit_code['nm']
48+
response = nist.core.Nist.query_async(4000 * u.nm, 7000 * u.nm,
49+
linename=["H I", "Fe I"], get_query_payload=True)
50+
assert response["spectra"] == "H I; Fe I"
4851
response = nist.core.Nist.query_async(4000 * u.nm, 7000 * u.nm, linename="H I")
4952
assert response is not None
5053

docs/nist/nist.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ nanometer, or angstrom or the like. For example, to use a lower wavelength
1818
value of 4000 Angstroms, you should use ```4000 * u.AA``` and if you want the
1919
same in nanometers, just use ```400 * u.nm```. Of course there are several optional
2020
parameters you can also specify. For instance use the ``linename`` parameter to
21-
specify the spectrum you wish to fetch. By default this is set to "H I", but
22-
you can set it to several other values like "Na;Mg", etc. Lets now see a simple example.
21+
specify the spectrum you wish to fetch.
22+
``linename`` also accepts multiple line strings in an iterable (e.g. ``["Na", "H I"]``)
23+
or you can specify multiple lines as a single string value separated with a
24+
semicolon (e.g. ``"Na;Mg"``). Now let's see a simple example:
2325

2426
.. doctest-remote-data::
2527

0 commit comments

Comments
 (0)