Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug while reading information from CDMS table #2375

Closed
Amani-Sagri opened this issue Apr 25, 2022 · 2 comments · Fixed by #2385
Closed

Bug while reading information from CDMS table #2375

Amani-Sagri opened this issue Apr 25, 2022 · 2 comments · Fixed by #2385
Labels

Comments

@Amani-Sagri
Copy link

astroquery/lineslists/cdms/core.py:

There are 2 issues I found in this file:

  • Line 128:

The function find() doesn't work with molecules that have parenthesis in their names and gives an IndexError in this case because the find() function from class Lookuptable uses the re package that consider the parenthesis as a specific symbol. To avoid this confusion, the parenthesis "(" in name of the molecules should be replaced by the string : "\(" so that the find() function understand it as a parenthesis.

This is a few lines I added in my own version of core.py to take into account molecules with parenthesis:

       if molecule is not None:
            if parse_name_locally:
                self.lookup_ids = build_lookup()
                
                _**####added lines##########
                name_molecule = molecule.replace("(","\\(")
                name_molecule_corrected = name_molecule.replace(")","\\)")
                molecule = name_molecule_corrected
                #########################**_
                
                luts = self.lookup_ids.find(molecule, flags)
                payload['Molecules'] = tuple(f"{val:06d} {key}"
                                             for key, val in luts.items())[0]
                if len(molecule) == 0:
                    raise InvalidQueryError('No matching species found. Please '
                                            'refine your search or read the Docs '
                                            'for pointers on how to search.')
            else:
                payload['Molecules'] = molecule
  • Line 217 and 218:

I found that the actual value of GUP starts at 47 not 48
For the TAG it starts at 50 not 51.
Because of this shift, this commande gives a TypeError:

freqs, aij, deg, EU, partfunc = get_molecular_parameters("H2C(CN)2", catalog="CDMS", fmin=232567.224454 * u.MHz, fmax=234435.809432 * u.MHz)

The Error I've got before making changes in my own version:

TypeError Traceback (most recent call last)
Input In [5], in
----> 1 freqs, aij, deg, EU, partfunc = get_molecular_parameters(
2 "H2C(CN)2", catalog="CDMS", fmin=232567.224454 * u.MHz, fmax=234435.809432 * u.MHz
3 )

File ~/venv/lib/python3.9/site-packages/pyspeckit/spectrum/models/lte_molecule.py:271, in get_molecular_parameters(molecule_name, tex, fmin, fmax, catalog, **kwargs)
269 freq_MHz = freqs.to(u.MHz).value
270 deg = np.array(jpltbl['GUP'])
--> 271 EL = jpltbl['ELO'].quantity.to(u.erg, u.spectral())
272 dE = freqs.to(u.erg, u.spectral())
273 EU = EL + dE

File ~/venv/lib/python3.9/site-packages/astropy/table/column.py:927, in BaseColumn.quantity(self)
920 """
921 A view of this table column as a ~astropy.units.Quantity object with
922 units given by the Column's unit parameter.
923 """
924 # the Quantity initializer is used here because it correctly fails
925 # if the column's values are non-numeric (like strings), while .view
926 # will happily return a quantity with gibberish for numerical values
--> 927 return Quantity(self, self.unit, copy=False, dtype=self.dtype, order='A', subok=True)

File ~/venv/lib/python3.9/site-packages/astropy/units/quantity.py:511, in Quantity.new(cls, value, unit, dtype, copy, order, subok, ndmin)
507 # check that array contains numbers or long int objects
508 if (value.dtype.kind in 'OSU' and
509 not (value.dtype.kind == 'O' and
510 isinstance(value.item(0), numbers.Number))):
--> 511 raise TypeError("The value must be a valid Python or "
512 "Numpy numeric type.")
514 # by default, cast any integer, boolean, etc., to float
515 if dtype is None and value.dtype.kind in 'iuO':

TypeError: The value must be a valid Python or Numpy numeric type.

This is the change I made:

        starts = {'FREQ': 0,
                  'ERR': 14,
                  'LGINT': 25,
                  'DR': 36,
                  'ELO': 38,
                  'GUP': 47,#line modified: was 48 turned into 47
                  'TAG': 50,#line modified was 51
                  'QNFMT': 57,
                  'Ju': 61,
                  'Ku': 63,
                  'vu': 65,
                  'Jl': 67,
                  'Kl': 69,
                  'vl': 71,
                  'F': 73,
                  'name': 89}
@bsipocz bsipocz added the cdms label Apr 25, 2022
@bsipocz
Copy link
Member

bsipocz commented Apr 25, 2022

cc @keflavich

@keflavich
Copy link
Contributor

The error reported here is actually:

from astroquery.linelists.cdms import CDMS
CDMS.query_lines(232567.224454 * u.MHz, 234435.809432 * u.MHz, molecule='H2C(CN)2', parse_name_locally=True)

leading to

IndexError: tuple index out of range

Then, if correctly queried:

In [39]: CDMS.query_lines(232567.224454 * u.MHz, 234435.809432 * u.MHz, molecule='H2C\(CN\)2', parse_name_locally=True)
Out[39]:
<Table length=49>
    FREQ      ERR    LGINT    DR     ELO      GUP   TAG  QNFMT  Ju    Ku   vu    Jl    Kl    vl    F      name
    MHz       MHz   MHz nm2         1 / cm
  float64   float64 float64 int64   str10    int64 int64 int64 str2 int64 str2 int64 int64 int64  str6    str8
----------- ------- ------- ----- ---------- ----- ----- ----- ---- ----- ---- ----- ----- ----- ------ --------
232588.7246  0.2828 -4.1005     3  293.85404    45 66506   303   44    14   30    --    --    -- 451333 H2C(CN)2

Unfortunately, I can't see a way to make the parser behave generally here. It looks like every CDMS file has a different fixed-format table. I'll try to figure out a way to generalize it, but for now, it looks like this molecule is just wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants