|
10 | 10 | from astroquery.utils import async_to_sync
|
11 | 11 | # import configurable items declared in __init__.py
|
12 | 12 | from astroquery.linelists.cdms import conf
|
13 |
| -from astroquery.jplspec import lookup_table |
14 | 13 | from astroquery.exceptions import InvalidQueryError, EmptyResponseError
|
15 | 14 |
|
| 15 | +import re |
16 | 16 |
|
17 | 17 | __all__ = ['CDMS', 'CDMSClass']
|
18 | 18 |
|
@@ -129,11 +129,11 @@ def query_lines_async(self, min_frequency, max_frequency, *,
|
129 | 129 | # escape parentheses in molecule names if needed
|
130 | 130 | # (assumes _no_ escapes done; if you give 'XY\(ZG)', i.e.,
|
131 | 131 | # escape one and not the other, this won't work)
|
132 |
| - if re.search("[()]", molecule): |
133 |
| - if len(re.findall(r'\(', molecule)) != len(re.findall(r'(', molecule)): |
134 |
| - molecule = re.sub(r'(', r'\(', molecule) |
135 |
| - if len(re.findall(r'\)', molecule)) != len(re.findall(r')', molecule)) |
136 |
| - molecule = re.sub(r')', r'\)', molecule) |
| 132 | + # if re.search("[()]", molecule): |
| 133 | + # if len(re.findall(r'\(', molecule)) != len(re.findall(r'(', molecule)): |
| 134 | + # molecule = re.sub(r'(', r'\(', molecule) |
| 135 | + # if len(re.findall(r'\)', molecule)) != len(re.findall(r')', molecule)) |
| 136 | + # molecule = re.sub(r')', r'\)', molecule) |
137 | 137 | if parse_name_locally:
|
138 | 138 | self.lookup_ids = build_lookup()
|
139 | 139 | luts = self.lookup_ids.find(molecule, flags)
|
@@ -227,7 +227,7 @@ def _parse_result(self, response, verbose=False):
|
227 | 227 | 'ELO': 38,
|
228 | 228 | 'GUP': 48,
|
229 | 229 | 'TAG': 51,
|
230 |
| - 'QNFMT': 57, |
| 230 | + 'QNFMT': 58, |
231 | 231 | 'Ju': 61,
|
232 | 232 | 'Ku': 63,
|
233 | 233 | 'vu': 65,
|
@@ -314,12 +314,48 @@ def tryfloat(x):
|
314 | 314 | CDMS = CDMSClass()
|
315 | 315 |
|
316 | 316 |
|
| 317 | +class Lookuptable(dict): |
| 318 | + |
| 319 | + def find(self, st, flags): |
| 320 | + """ |
| 321 | + Search dictionary keys for a regex match to string s |
| 322 | +
|
| 323 | + Parameters |
| 324 | + ---------- |
| 325 | + s : str |
| 326 | + String to compile as a regular expression |
| 327 | + Can be entered non-specific for broader results |
| 328 | + ('H2O' yields 'H2O' but will also yield 'HCCCH2OD') |
| 329 | + or as the specific desired regular expression for |
| 330 | + catered results, for example: ('H20$' yields only 'H2O') |
| 331 | +
|
| 332 | + flags : int |
| 333 | + Regular expression flags. |
| 334 | +
|
| 335 | + Returns |
| 336 | + ------- |
| 337 | + The list of values corresponding to the matches |
| 338 | +
|
| 339 | + """ |
| 340 | + |
| 341 | + R = re.compile(st, flags) |
| 342 | + |
| 343 | + out = {} |
| 344 | + |
| 345 | + for kk, vv in self.items(): |
| 346 | + match = (st in kk) or R.search(str(kk)) |
| 347 | + if match: |
| 348 | + out[kk] = vv |
| 349 | + |
| 350 | + return out |
| 351 | + |
| 352 | + |
317 | 353 | def build_lookup():
|
318 | 354 |
|
319 | 355 | result = CDMS.get_species_table()
|
320 | 356 | keys = list(result[1][:]) # convert NAME column to list
|
321 | 357 | values = list(result[0][:]) # convert TAG column to list
|
322 | 358 | dictionary = dict(zip(keys, values)) # make k,v dictionary
|
323 |
| - lookuptable = lookup_table.Lookuptable(dictionary) # apply the class above |
| 359 | + lookuptable = Lookuptable(dictionary) # apply the class above |
324 | 360 |
|
325 | 361 | return lookuptable
|
0 commit comments