Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cdms table #2760

Merged
merged 1 commit into from
Jul 5, 2023
Merged
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
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ linelists.cdms

- Fix issues with the line name parser and the line data parser; the original
implementation was incomplete and upstream was not fully documented. [#2385, #2411]
- Added new line list reader and enabled reading line list from remote server.
Also updated local version of line list, which includes some change in column names
[#2760]

mast
^^^^
Expand Down
4 changes: 4 additions & 0 deletions astroquery/linelists/cdms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class Conf(_config.ConfigNamespace):
'https://cdms.astro.uni-koeln.de/cgi-bin/cdmssearch',
'CDMS Search and Conversion Form URL.')

catfile_url = _config.ConfigItem(
'https://cdms.astro.uni-koeln.de/classic/entries/partition_function.html',
'CDMS partition function table listing all available molecules.')

timeout = _config.ConfigItem(
60,
'Time limit for connecting to the CDMS server.')
Expand Down
31 changes: 25 additions & 6 deletions astroquery/linelists/cdms/core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import numpy as np
import requests
import os

from bs4 import BeautifulSoup
Expand Down Expand Up @@ -277,7 +278,8 @@ def _parse_result(self, response, *, verbose=False):

return result

def get_species_table(self, *, catfile='catdir.cat'):
def get_species_table(self, *, catfile='catdir.cat', use_cached=True,
catfile_url=conf.catfile_url):
"""
A directory of the catalog is found in a file called 'catdir.cat.'
Expand All @@ -299,8 +301,10 @@ def get_species_table(self, *, catfile='catdir.cat'):
"""

result = ascii.read(data_path('catdir.cat'), format='csv',
delimiter='|')
if use_cached:
result = ascii.read(data_path(catfile), format='fixed_width', delimiter='|')
else:
result = retrieve_catfile(catfile_url)

meta = {'lg(Q(1000))': 1000.0,
'lg(Q(500))': 500.0,
Expand Down Expand Up @@ -364,7 +368,7 @@ def find(self, st, flags):
Can be entered non-specific for broader results
('H2O' yields 'H2O' but will also yield 'HCCCH2OD')
or as the specific desired regular expression for
catered results, for example: ('H20$' yields only 'H2O')
catered results, for example: ('H2O$' yields only 'H2O')
flags : int
Regular expression flags.
Expand All @@ -390,9 +394,24 @@ def find(self, st, flags):
def build_lookup():

result = CDMS.get_species_table()
keys = list(result[1][:]) # convert NAME column to list
values = list(result[0][:]) # convert TAG column to list
keys = list(result['molecule'][:]) # convert NAME column to list
values = list(result['tag'][:]) # convert TAG column to list
dictionary = dict(zip(keys, values)) # make k,v dictionary
lookuptable = Lookuptable(dictionary) # apply the class above

return lookuptable


def retrieve_catfile(url='https://cdms.astro.uni-koeln.de/classic/entries/partition_function.html'):
"""
Simple retrieve index function
"""
response = requests.get(url)
response.raise_for_status()
tbl = ascii.read(response.text, header_start=None, data_start=15, data_end=-5,
names=['tag', 'molecule', '#lines', 'lg(Q(1000))', 'lg(Q(500))', 'lg(Q(300))', 'lg(Q(225))',
'lg(Q(150))', 'lg(Q(75))', 'lg(Q(37.5))', 'lg(Q(18.75))', 'lg(Q(9.375))', 'lg(Q(5.000))',
'lg(Q(2.725))'],
col_starts=(0, 7, 34, 41, 53, 66, 79, 92, 106, 117, 131, 145, 159, 173),
format='fixed_width', delimiter=' ')
return tbl
Loading