Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions astroquery/linelists/jplspec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class Conf(_config.ConfigNamespace):
'https://spec.jpl.nasa.gov/cgi-bin/catform',
'JPL Spectral Catalog URL.')

ftp_cat_server = _config.ConfigItem(
['https://spec.jpl.nasa.gov/ftp/pub/catalog/',
'https://web.archive.org/web/20250630185813/https://spec.jpl.nasa.gov/ftp/pub/catalog/'],
'JPL FTP Catalog URL'
)

timeout = _config.ConfigItem(
60,
'Time limit for connecting to JPL server.')
Expand Down
15 changes: 11 additions & 4 deletions astroquery/linelists/jplspec/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class JPLSpecClass(BaseQuery):

# use the Configuration Items imported from __init__.py
URL = conf.server
FTP_CAT_URL = conf.ftp_cat_server
TIMEOUT = conf.timeout

def __init__(self):
Expand Down Expand Up @@ -142,6 +143,7 @@ def query_lines(self, min_frequency, max_frequency, *,
parse_name_locally=False,
get_query_payload=False,
fallback_to_getmolecule=True,
use_getmolecule=True,
cache=True):
"""
Query the JPLSpec service for spectral lines.
Expand All @@ -153,6 +155,9 @@ def query_lines(self, min_frequency, max_frequency, *,
governs whether `get_molecule` will be used when no results are returned
by the query service. This workaround is needed while JPLSpec's query
tool is broken.

use_getmolecule is an option to force the query to use get_molecule.
It is needed if the JPL server is completely unresponsive.
"""
response = self.query_lines_async(min_frequency=min_frequency,
max_frequency=max_frequency,
Expand All @@ -166,11 +171,13 @@ def query_lines(self, min_frequency, max_frequency, *,
if get_query_payload:
return response
else:
return self._parse_result(response, fallback_to_getmolecule=fallback_to_getmolecule)
return self._parse_result(response, fallback_to_getmolecule=fallback_to_getmolecule,
use_getmolecule=use_getmolecule)

query_lines.__doc__ = process_asyncs.async_to_sync_docstr(query_lines_async.__doc__)

def _parse_result(self, response, *, verbose=False, fallback_to_getmolecule=False):
def _parse_result(self, response, *, verbose=False, fallback_to_getmolecule=False,
use_getmolecule=True):
"""
Parse a response into an `~astropy.table.Table`

Expand Down Expand Up @@ -201,7 +208,7 @@ def _parse_result(self, response, *, verbose=False, fallback_to_getmolecule=Fals
QN": Quantum numbers for the lower state.
"""

if 'Zero lines were found' in response.text:
if 'Zero lines were found' in response.text or use_getmolecule:
if fallback_to_getmolecule:
self.lookup_ids = build_lookup()
payload = parse_qs(response.request.body)
Expand Down Expand Up @@ -320,7 +327,7 @@ def get_molecule(self, molecule_id, *, cache=True):
molecule_str = parse_molid(molecule_id)

# Construct the URL to the catalog file
url = f'https://spec.jpl.nasa.gov/ftp/pub/catalog/c{molecule_str}.cat'
url = f'{self.FTP_CAT_URL}/c{molecule_str}.cat'

# Request the catalog file
response = self._request(method='GET', url=url,
Expand Down
Loading