1212# import configurable items declared in __init__.py
1313from astroquery .linelists .cdms import conf
1414from astroquery .exceptions import InvalidQueryError , EmptyResponseError
15+ from astroquery import log
1516
1617import re
1718import 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
0 commit comments