Skip to content

Commit a99ad27

Browse files
authored
Merge pull request #2760 from keflavich/update_cdms
Update cdms table
2 parents 91f2b0b + 21a81bb commit a99ad27

File tree

5 files changed

+1240
-1105
lines changed

5 files changed

+1240
-1105
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ linelists.cdms
131131

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

135138
mast
136139
^^^^

astroquery/linelists/cdms/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class Conf(_config.ConfigNamespace):
1717
'https://cdms.astro.uni-koeln.de/cgi-bin/cdmssearch',
1818
'CDMS Search and Conversion Form URL.')
1919

20+
catfile_url = _config.ConfigItem(
21+
'https://cdms.astro.uni-koeln.de/classic/entries/partition_function.html',
22+
'CDMS partition function table listing all available molecules.')
23+
2024
timeout = _config.ConfigItem(
2125
60,
2226
'Time limit for connecting to the CDMS server.')

astroquery/linelists/cdms/core.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22
import numpy as np
3+
import requests
34
import os
45

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

278279
return result
279280

280-
def get_species_table(self, *, catfile='catdir.cat'):
281+
def get_species_table(self, *, catfile='catdir.cat', use_cached=True,
282+
catfile_url=conf.catfile_url):
281283
"""
282284
A directory of the catalog is found in a file called 'catdir.cat.'
283285
@@ -299,8 +301,10 @@ def get_species_table(self, *, catfile='catdir.cat'):
299301
300302
"""
301303

302-
result = ascii.read(data_path('catdir.cat'), format='csv',
303-
delimiter='|')
304+
if use_cached:
305+
result = ascii.read(data_path(catfile), format='fixed_width', delimiter='|')
306+
else:
307+
result = retrieve_catfile(catfile_url)
304308

305309
meta = {'lg(Q(1000))': 1000.0,
306310
'lg(Q(500))': 500.0,
@@ -364,7 +368,7 @@ def find(self, st, flags):
364368
Can be entered non-specific for broader results
365369
('H2O' yields 'H2O' but will also yield 'HCCCH2OD')
366370
or as the specific desired regular expression for
367-
catered results, for example: ('H20$' yields only 'H2O')
371+
catered results, for example: ('H2O$' yields only 'H2O')
368372
369373
flags : int
370374
Regular expression flags.
@@ -390,9 +394,24 @@ def find(self, st, flags):
390394
def build_lookup():
391395

392396
result = CDMS.get_species_table()
393-
keys = list(result[1][:]) # convert NAME column to list
394-
values = list(result[0][:]) # convert TAG column to list
397+
keys = list(result['molecule'][:]) # convert NAME column to list
398+
values = list(result['tag'][:]) # convert TAG column to list
395399
dictionary = dict(zip(keys, values)) # make k,v dictionary
396400
lookuptable = Lookuptable(dictionary) # apply the class above
397401

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

0 commit comments

Comments
 (0)