Skip to content

Commit 34bd35b

Browse files
committed
expand test coverage and resolve some problems discovered as a result
1 parent de4038b commit 34bd35b

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

astroquery/linelists/cdms/core.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# import configurable items declared in __init__.py
1313
from astroquery.linelists.cdms import conf
1414
from astroquery.exceptions import InvalidQueryError, EmptyResponseError
15+
from astroquery import log
1516

1617
import re
1718
import string
@@ -409,7 +410,7 @@ def tryfloat(x):
409410

410411
return result
411412

412-
def get_molecule(self, molecule_id, *, cache=True):
413+
def get_molecule(self, molecule_id, *, cache=True, return_response=False):
413414
"""
414415
Retrieve the whole molecule table for a given molecule id
415416
"""
@@ -418,6 +419,8 @@ def get_molecule(self, molecule_id, *, cache=True):
418419
url = f'{self.CLASSIC_URL}/entries/c{molecule_id}.cat'
419420
response = self._request(method='GET', url=url,
420421
timeout=self.TIMEOUT, cache=cache)
422+
if return_response:
423+
return response
421424
result = self._parse_cat(response)
422425

423426
species_table = self.get_species_table()
@@ -449,7 +452,7 @@ def _parse_cat(self, response, *, verbose=False):
449452
'GUP': 42,
450453
'TAG': 44,
451454
'QNFMT': 52,
452-
'Q1': 56,
455+
'Q1': 55,
453456
'Q2': 58,
454457
'Q3': 60,
455458
'Q4': 62,
@@ -472,7 +475,7 @@ def _parse_cat(self, response, *, verbose=False):
472475
format='fixed_width', fast_reader=False)
473476

474477
# int truncates - which is what we want
475-
result['MOLWT'] = [int(x/1e4) for x in result['TAG']]
478+
result['MOLWT'] = [int(x/1e3) for x in result['TAG']]
476479

477480
result['FREQ'].unit = u.MHz
478481
result['ERR'].unit = u.MHz
@@ -482,15 +485,18 @@ def _parse_cat(self, response, *, verbose=False):
482485
result['MOLWT'].unit = u.Da
483486

484487
fix_keys = ['GUP']
485-
for suf in '':
486-
for qn in (f'Q{ii}' for ii in range(1, 15)):
487-
qnind = qn+suf
488-
fix_keys.append(qnind)
488+
for qn in (f'Q{ii}' for ii in range(1, 15)):
489+
fix_keys.append(qn)
490+
log.debug(f"fix_keys: {fix_keys} should include Q1, Q2, ..., Q14 and GUP")
489491
for key in fix_keys:
490492
if not np.issubdtype(result[key].dtype, np.integer):
491493
intcol = np.array(list(map(parse_letternumber, result[key])),
492494
dtype=int)
495+
if any(intcol == -999999):
496+
intcol = np.ma.masked_where(intcol == -999999, intcol)
493497
result[key] = intcol
498+
if not np.issubdtype(result[key].dtype, np.integer):
499+
raise ValueError(f"Failed to parse {key} as integer")
494500

495501
result['LGINT'].unit = u.nm**2 * u.MHz
496502
result['ELO'].unit = u.cm**(-1)
@@ -508,9 +514,12 @@ def parse_letternumber(st):
508514
From the CDMS docs:
509515
"Exactly two characters are available for each quantum number. Therefore, half
510516
integer quanta are rounded up ! In addition, capital letters are used to
511-
indicate quantum numbers larger than 99. E. g. A0 is 100, Z9 is 359. Lower case characters
517+
indicate quantum numbers larger than 99. E. g. A0 is 100, Z9 is 359. Lower case characters
512518
are used similarly to signal negative quantum numbers smaller than –9. e. g., a0 is –10, b0 is –20, etc."
513519
"""
520+
if np.ma.is_masked(st):
521+
return -999999
522+
514523
asc = string.ascii_lowercase
515524
ASC = string.ascii_uppercase
516525
newst = ''.join(['-' + str((asc.index(x)+1)) if x in asc else

astroquery/linelists/cdms/tests/test_cdms.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def test_query(patch_post):
8383
assert tbl['LGINT'][0] == -7.1425
8484
assert tbl['GUP'][0] == 3
8585
assert tbl['GUP'][7] == 17
86+
assert tbl['MOLWT'][0] == 28
8687

8788

8889
def test_parseletternumber():
@@ -103,6 +104,8 @@ def test_parseletternumber():
103104
assert parse_letternumber("b0") == -20
104105
assert parse_letternumber("ZZ") == 3535
105106

107+
assert parse_letternumber(np.ma.masked) == -999999
108+
106109

107110
def test_hc7s(patch_post):
108111
"""

astroquery/linelists/cdms/tests/test_cdms_remote.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ def test_remote_300K():
3838
assert tbl['FREQ'][0] == 505366.7875
3939
assert tbl['ERR'][0] == 49.13
4040
assert tbl['LGINT'][0] == -4.2182
41+
assert tbl['MOLWT'][0] == 18
42+
43+
44+
@pytest.mark.remote_data
45+
def test_propanediol():
46+
tbl1 = CDMS.get_molecule('076513')
47+
assert 'int' in tbl1['Q2'].dtype.name
48+
49+
tbl = CDMS.query_lines(min_frequency=100.3 * u.GHz,
50+
max_frequency=100.5 * u.GHz,
51+
molecule='076513',
52+
)
53+
assert isinstance(tbl, Table)
54+
assert len(tbl) >= 1
55+
assert 'aG\'g-1,2-Propanediol' in tbl['name']
56+
# check that the parser worked - this will be string or obj otherwise
57+
assert 'int' in tbl['Ku'].dtype.name
58+
assert tbl['MOLWT'][0] == 76
4159

4260

4361
@pytest.mark.remote_data

0 commit comments

Comments
 (0)