Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 12 additions & 3 deletions astroquery/linelists/cdms/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ def _parse_result(self, response, *, verbose=False):

def get_species_table(self, *, catfile='partfunc.cat', use_cached=True,
catfile_url=conf.catfile_url,
catfile2='catdir.cat', catfile_url2=conf.catfile_url2):
catfile2='catdir.cat', catfile_url2=conf.catfile_url2,
write=True):
"""
A directory of the catalog is found in a file called 'catdir.cat.'

Expand All @@ -304,6 +305,13 @@ def get_species_table(self, *, catfile='partfunc.cat', use_cached=True,
----------
catfile : str, name of file, default 'catdir.cat'
The catalog file, installed locally along with the package
use_cached : bool, optional
If True, use the cached file if it exists. If False, download the
file from the CDMS server and save it to the cache (if ``write`` is set).
write : bool, optional

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more verbose arg would be nice, maybe call this write_cached or refresh_cashed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be more verbose, but I think a different keyword is warranted... write_new_cache, probably.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Anything more that just write is an improvement, and write_new_cache is quite good. Though maybe it will need a switch in logic, e.g. if it's set then ignore whatever is in use_cache rather than the other way around.

If True, and if ``use_cached`` is set, write the file to the cache. Use this
option if you need to update the index from CDMS; this should be set to False
for testing.

Returns
-------
Expand Down Expand Up @@ -332,8 +340,9 @@ def get_species_table(self, *, catfile='partfunc.cat', use_cached=True,
else:
result = retrieve_catfile(catfile_url)
result2 = retrieve_catfile2(catfile_url2)
result.write(data_path(catfile), format='ascii.fixed_width', delimiter='|', overwrite=True)
result2.write(data_path(catfile2), format='ascii.fixed_width', delimiter='|', overwrite=True)
if write:
result.write(data_path(catfile), format='ascii.fixed_width', delimiter='|', overwrite=True)
result2.write(data_path(catfile2), format='ascii.fixed_width', delimiter='|', overwrite=True)

merged = table.join(result, result2, keys=['tag'])
if not all(merged['#lines'] == merged['# lines']):
Expand Down
4 changes: 2 additions & 2 deletions astroquery/linelists/cdms/tests/test_cdms_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_complex_molecule_remote():

@pytest.mark.remote_data
def test_retrieve_species_table():
species_table = CDMS.get_species_table(use_cached=False)
species_table = CDMS.get_species_table(use_cached=False, write=False)
# as of 2025/01/16
assert len(species_table) >= 1293
assert 'int' in species_table['tag'].dtype.name
Expand All @@ -127,7 +127,7 @@ def test_regression_allcats():
"""
Expensive test - try all the molecules
"""
species_table = CDMS.get_species_table()
species_table = CDMS.get_species_table(write=False)
for row in species_table:
tag = f"{row['tag']:06d}"
result = CDMS.get_molecule(tag)
Expand Down