Skip to content

Commit

Permalink
Merge pull request #2760 from keflavich/update_cdms
Browse files Browse the repository at this point in the history
Update cdms table
  • Loading branch information
bsipocz authored Jul 5, 2023
2 parents 91f2b0b + 21a81bb commit a99ad27
Show file tree
Hide file tree
Showing 5 changed files with 1,240 additions and 1,105 deletions.
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

0 comments on commit a99ad27

Please sign in to comment.