Skip to content

Commit 9cb449d

Browse files
keflavichburnout87
authored andcommitted
add a local test
whitespace cleanup pep8 cleanup pep8 cleanup escaped character fix. The previous commit fixed the outstanding pep8 issue but the fix was not recognized fix import yay tests pass more cleanup of the tags more fixes fix local tests
1 parent d378115 commit 9cb449d

File tree

4 files changed

+136
-16
lines changed

4 files changed

+136
-16
lines changed

astroquery/linelists/cdms/core.py

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from astroquery.exceptions import InvalidQueryError, EmptyResponseError
1414

1515
import re
16+
import string
1617

1718
__all__ = ['CDMS', 'CDMSClass']
1819

@@ -53,7 +54,7 @@ def query_lines_async(self, min_frequency, max_frequency, *,
5354
Identifiers of the molecules to search for. If this parameter
5455
is not provided the search will match any species. Default is 'All'.
5556
Note that if the molecule name contains parentheses, they must be
56-
escaped. For exmaple, 'H2C(CN)2' must be specified as 'H2C\(CN\)2'.
57+
escaped. For exmaple, 'H2C(CN)2' must be specified as 'H2C\\(CN\\)2'.
5758
5859
temperature_for_intensity : float
5960
The temperature to use when computing the intensity Smu^2. Set
@@ -198,12 +199,14 @@ def _parse_result(self, response, verbose=False):
198199
199200
ELO: Lower state energy in cm^{-1} relative to the ground state.
200201
GUP: Upper state degeneracy.
201-
TAG: Species tag or molecular identifier.
202-
A negative value flags that the line frequency has
203-
been measured in the laboratory. The absolute value of TAG is then the
204-
species tag and ERR is the reported experimental error. The three most
205-
significant digits of the species tag are coded as the mass number of
206-
the species.
202+
MOLWT: The first half of the molecular weight tag, which is the mass in atomic
203+
mass units (Daltons).
204+
TAG: Species tag or molecular identifier. This only includes the
205+
last 3 digits of the CDMS tag
206+
207+
A negative value of MOLWT flags that the line frequency has been
208+
measured in the laboratory. We record this boolean in the 'Lab'
209+
column. ERR is the reported experimental error.
207210
208211
QNFMT: Identifies the format of the quantum numbers
209212
Ju/Ku/vu and Jl/Kl/vl are the upper/lower QNs
@@ -226,15 +229,21 @@ def _parse_result(self, response, verbose=False):
226229
'DR': 36,
227230
'ELO': 38,
228231
'GUP': 48,
229-
'TAG': 51,
232+
'MOLWT': 51,
233+
'TAG': 54,
230234
'QNFMT': 58,
231235
'Ju': 61,
232236
'Ku': 63,
233237
'vu': 65,
234-
'Jl': 67,
235-
'Kl': 69,
236-
'vl': 71,
237-
'F': 73,
238+
'F1u': 67,
239+
'F2u': 69,
240+
'F3u': 71,
241+
'Jl': 73,
242+
'Kl': 75,
243+
'vl': 77,
244+
'F1l': 79,
245+
'F2l': 81,
246+
'F3l': 83,
238247
'name': 89}
239248

240249
result = ascii.read(text, header_start=None, data_start=0,
@@ -243,9 +252,23 @@ def _parse_result(self, response, verbose=False):
243252
col_starts=list(starts.values()),
244253
format='fixed_width', fast_reader=False)
245254

255+
246256
result['FREQ'].unit = u.MHz
247257
result['ERR'].unit = u.MHz
248258

259+
result['Lab'] = result['MOLWT'] < 0
260+
result['MOLWT'] = np.abs(result['MOLWT'])
261+
result['MOLWT'].unit = u.Da
262+
263+
for suf in 'ul':
264+
for qn in ('J', 'v', 'K', 'F1', 'F2', 'F3'):
265+
qnind = qn+suf
266+
if result[qnind].dtype != int:
267+
intcol = np.array(list(map(parse_letternumber, result[qnind])),
268+
dtype=int)
269+
result[qnind] = intcol
270+
271+
249272
# if there is a crash at this step, something went wrong with the query
250273
# and the _last_query_temperature was not set. This shouldn't ever
251274
# happen, but, well, I anticipate it will.
@@ -314,6 +337,24 @@ def tryfloat(x):
314337
CDMS = CDMSClass()
315338

316339

340+
def parse_letternumber(st):
341+
"""
342+
Parse CDMS's two-letter QNs
343+
344+
Very Important:
345+
Exactly two characters are available for each quantum number. Therefore, half
346+
integer quanta are rounded up ! In addition, capital letters are used to
347+
indicate quantum numbers larger than 99. E. g. A0 is 100, Z9 is 359. Small
348+
types are used to signal corresponding negative quantum numbers.
349+
"""
350+
asc = string.ascii_lowercase
351+
ASC = string.ascii_uppercase
352+
newst = ''.join(['-' + str(asc.index(x)+10) if x in asc else
353+
str(ASC.index(x)+10) if x in ASC else
354+
x for x in st])
355+
return int(newst)
356+
357+
317358
class Lookuptable(dict):
318359

319360
def find(self, st, flags):
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html
2+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4+
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
5+
<head>
6+
<title>Untitled Document</title>
7+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
8+
</head>
9+
<body>
10+
<pre>
11+
100694.0650 0.4909 -3.9202 2 210.7681255 117501 224C6-1C7C7 C5 1C6C6 HC7S
12+
100694.0675 0.4909 -3.9237 2 210.7682253 117501 224C6-1C7C6 C5 1C6C5 HC7S
13+
100696.6906 0.4909 -3.9202 2 210.7790255 117501 224C6 1C7C7 C5-1C6C6 HC7S
14+
100696.6933 0.4909 -3.9237 2 210.7789253 117501 224C6 1C7C6 C5-1C6C5 HC7S
15+
100755.6075 0.4921 -4.0157 2 255.1740253 117501 224C7-1C7C6 C6 1C6C5 HC7S
16+
</pre></body></html>

astroquery/linelists/cdms/tests/test_cdms.py

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
from astropy import units as u
66
from astropy.table import Table
7-
from astroquery.linelists.cdms import CDMS
7+
from astroquery.linelists.cdms.core import CDMS, parse_letternumber
88

9+
colname_set = set(['FREQ', 'ERR', 'LGINT', 'DR', 'ELO', 'GUP', 'TAG', 'QNFMT',
10+
'Ju', 'Jl', "vu", "F1u", "F2u", "F3u", "vl", "Ku", "Kl",
11+
"F1l", "F2l", "F3l", "name", "MOLWT", "Lab"])
912

1013
def data_path(filename):
1114

@@ -57,9 +60,54 @@ def test_query():
5760
tbl = CDMS._parse_result(response)
5861
assert isinstance(tbl, Table)
5962
assert len(tbl) == 8
60-
assert set(tbl.keys()) == set(['FREQ', 'ERR', 'LGINT', 'DR', 'ELO', 'GUP',
61-
'TAG', 'QNFMT', 'Ju', 'Jl', "vu", "vl", "Ku", "Kl", "F", "name"])
63+
assert set(tbl.keys()) == colname_set
6264

6365
assert tbl['FREQ'][0] == 115271.2018
6466
assert tbl['ERR'][0] == .0005
6567
assert tbl['LGINT'][0] == -7.1425
68+
69+
70+
def test_parseletternumber():
71+
"""
72+
Very Important:
73+
Exactly two characters are available for each quantum number. Therefore, half
74+
integer quanta are rounded up ! In addition, capital letters are used to
75+
indicate quantum numbers larger than 99. E. g. A0 is 100, Z9 is 359. Small
76+
types are used to signal corresponding negative quantum numbers.
77+
"""
78+
79+
# examples from the docs
80+
assert parse_letternumber("A0") == 100
81+
assert parse_letternumber("Z9") == 359
82+
83+
# inferred?
84+
assert parse_letternumber("z9") == -359
85+
assert parse_letternumber("ZZ") == 3535
86+
87+
88+
def test_hc7s():
89+
"""
90+
Test for a very complicated molecule
91+
92+
CDMS.query_lines_async(100*u.GHz, 100.755608*u.GHz, molecule='HC7S', parse_name_locally=True)
93+
"""
94+
95+
response = MockResponseSpec('HC7S.data')
96+
tbl = CDMS._parse_result(response)
97+
assert isinstance(tbl, Table)
98+
assert len(tbl) == 5
99+
assert set(tbl.keys()) == colname_set
100+
101+
assert tbl['FREQ'][0] == 100694.065
102+
assert tbl['ERR'][0] == 0.4909
103+
assert tbl['LGINT'][0] == -3.9202
104+
assert tbl['MOLWT'][0] == 117
105+
106+
assert tbl['Ju'][0] == 126
107+
assert tbl['Jl'][0] == 125
108+
assert tbl['vu'][0] == 127
109+
assert tbl['vl'][0] == 126
110+
assert tbl['Ku'][0] == -1
111+
assert tbl['Kl'][0] == 1
112+
assert tbl['F1u'][0] == 127
113+
assert tbl['F1l'][0] == 126

astroquery/linelists/cdms/tests/test_cdms_remote.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
import numpy as np
23
from astropy import units as u
34
from astropy.table import Table
45

@@ -57,4 +58,18 @@ def test_remote_regex():
5758

5859
@pytest.mark.remote_data
5960
def test_2375():
60-
pass
61+
"""
62+
Regression test for 2375
63+
"""
64+
tbl = CDMS.query_lines(232567.224454 * u.MHz, 234435.809432 * u.MHz, molecule='H2C(CN)2', parse_name_locally=True)
65+
66+
assert len(tbl) == 49
67+
68+
MC = np.ma.core.MaskedConstant()
69+
70+
for col, val in zip(tbl[0].colnames,
71+
(232588.7246, 0.2828, -4.1005, 3, '293.85404', 45, 66, 506, 303, 44, 14, 30, MC, MC, MC, 45, 13, 33, MC, MC, MC, 'H2C(CN)2', False)):
72+
if val is MC:
73+
assert tbl[0][col].mask
74+
else:
75+
assert tbl[0][col] == val

0 commit comments

Comments
 (0)