astropy / astroquery

Functions and classes to access online data resources. Maintainers: @keflavich and @bsipocz and @ceb8
http://astroquery.readthedocs.org/en/latest/
BSD 3-Clause "New" or "Revised" License
706 stars 398 forks source link

ned.query_ned_basic_posn result table columns not set #40

Closed cdeil closed 11 years ago

cdeil commented 11 years ago

The docstring of ned.query_ned_basic_posn says this:

Definition: ned.query_ned_basic_posn(objname='M31', root_url='http://nedwww.ipac.caltech.edu/cgi-bin/nph-objsearch')
Docstring:
Retrieve best available position data from NED for a particular target
    Equivalent to query_ned_by_objname(objname,tid=2)

keywords:
    objname - astronomical object to search for

Returns NED_PositionDataTable with the following information:

    -----------------------------------------------------------
    |                    Name |       Unit |    Type | Format |
    -----------------------------------------------------------
    |                 pos_ref |       None |    |S19 |    19s |
    |      pos_ra_equ_B1950_d |    degrees | float64 | 25.17e |
    |     pos_dec_equ_B1950_d |    degrees | float64 | 25.17e |
    |      pos_ra_equ_B1950_s |       None |    |S14 |    14s |
    |     pos_dec_equ_B1950_s |       None |    |S14 |    14s |
    |  maj_axis_unc_equ_B1950 | arcseconds | float64 | 25.17e |
...

But actually the column names are not set to meaningful names as advertised in the docstring:

In [37]: ned.query_ned_basic_posn('M32').names[:5]
Out[37]: ('posn_col1', 'posn_col2', 'posn_col3', 'posn_col4', 'posn_col5')

Also, is this the expected error when a query is made for an unknown name (I would have expected a more explicit error)?

In [39]: ned.query_ned_basic_posn('M1234')          
ERROR: Exception: There are no tables present in this file [atpy.votable]
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-39-3cc388c541ef> in <module>()
----> 1 ned.query_ned_basic_posn('M1234')

/Users/deil/Library/Python/2.7/lib/python/site-packages/astroquery/ned/nedpy.pyc in query_ned_basic_posn(objname, root_url)
    356     print >>tf,R
    357     tf.file.flush()
--> 358     t = atpy.Table(tf.name,type='vo',verbose=False)
    359 
    360     # Return atpy table

/Users/deil/Library/Python/2.7/lib/python/site-packages/atpy/basetable.pyc in __init__(self, *args, **kwargs)
    166 
    167         if len(args) + len(kwargs) > 0:
--> 168             self.read(*args, **kwargs)
    169 
    170         return

/Users/deil/Library/Python/2.7/lib/python/site-packages/atpy/basetable.pyc in read(self, *args, **kwargs)
    212 
    213             if table_type in registry._readers:
--> 214                 registry._readers[table_type](self, *args, **kwargs)
    215             else:
    216                 raise Exception("Unknown table type: " + table_type)

<string> in read(self, filename, pedantic, tid, verbose)

/Users/deil/Library/Python/2.7/lib/python/site-packages/atpy/decorators.pyc in _auto_download_to_file(read, table, filename, *args, **kwargs)
     36 
     37     # Otherwise just proceed as usual
---> 38     return read(table, filename, *args, **kwargs)
     39 
     40 

<string> in read(self, filename, pedantic, tid, verbose)

/Users/deil/Library/Python/2.7/lib/python/site-packages/atpy/decorators.pyc in _auto_decompress_to_fileobj(read, table, filename, *args, **kwargs)
     55             return read(table, bz2.BZ2File(filename), *args, **kwargs)
     56         else:
---> 57             return read(table, filename, *args, **kwargs)
     58 
     59     return read(table, filename, *args, **kwargs)

<string> in read(self, filename, pedantic, tid, verbose)

/Users/deil/Library/Python/2.7/lib/python/site-packages/atpy/decorators.pyc in _auto_fileobj_to_file(read, table, filename, *args, **kwargs)
     76         filename = output.name
     77 
---> 78     return read(table, filename, *args, **kwargs)

/Users/deil/Library/Python/2.7/lib/python/site-packages/atpy/votable.pyc in read(self, filename, pedantic, tid, verbose)
     72             tid = 0
     73         elif len(tables) == 0:
---> 74             raise Exception("There are no tables present in this file")
     75         else:
     76             raise TableException(tables, 'tid')

Exception: There are no tables present in this file
willettk commented 11 years ago

I can't reproduce the first error that you reported above. Using the module hosted in this repo, I get the following:

In [21]: import nedpy
In [32]: nedpy.query_ned_basic_posn('M32').names[:5]
Out[32]: 
('pos_ref',
 'pos_ra_equ_B1950_d',
 'pos_dec_equ_B1950_d',
 'pos_ra_equ_B1950_s',
 'pos_dec_equ_B1950_s')

As to the second, I've added some basic error-catching routines to each of the routines in this module; this looks to see if the data returned from the NED server is a formatted XML file and if any results were found for the query. There are still queries which return ill-formatted Tables that result in errors (which cdeil mentioned in another issue). Either we take these examples to NED and ask them about the output format or we have to find a way to read in the string and fix it within the module. I'm open to either, but would like more data on which queries are still making this break.

cdeil commented 11 years ago

Can you try with astroquery? I still only get default, not the actual, column names:

In [1]: from astroquery import ned
WARNING: ConfigurationDefaultMissingWarning: Requested default configuration file /Users/deil/Library/Python/2.7/lib/python/site-packages/astroquery-0.0.dev270-py2.7.egg/astroquery/astroquery.cfg is not a file. Cannot install default profile. If you are importing from source, this is expected. [astroquery]

In [2]: ned.query_ned_basic_posn('M32').colnames[:5]
WARNING: W42: /var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmphqq6fC:2:0: W42: No XML namespace specified [astropy.io.votable.exceptions]
WARNING: W22: /var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmphqq6fC:3:0: W22: The DEFINITIONS element is deprecated in VOTable 1.1.  Ignoring [astropy.io.votable.exceptions]
WARNING: W04: /var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmphqq6fC:18:0: W04: content-type 'char' must be a valid MIME content type [astropy.io.votable.exceptions]
WARNING: W50: /var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmphqq6fC:26:0: W50: Invalid unit string 'degrees' [astropy.io.votable.exceptions]
WARNING: W50: /var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmphqq6fC:29:0: W50: Invalid unit string 'degrees' [astropy.io.votable.exceptions]
WARNING: W50: /var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmphqq6fC:38:0: W50: Invalid unit string 'arcseconds' [astropy.io.votable.exceptions]
WARNING: W50: /var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmphqq6fC:41:0: W50: Invalid unit string 'arcseconds' [astropy.io.votable.exceptions]
WARNING: W50: /var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmphqq6fC:44:0: W50: Invalid unit string 'arcseconds' [astropy.io.votable.exceptions]
WARNING: W50: /var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmphqq6fC:47:0: W50: Invalid unit string 'degrees' [astropy.io.votable.exceptions]
WARNING: W50: /var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmphqq6fC:50:0: W50: Invalid unit string 'degrees' [astropy.io.votable.exceptions]
WARNING: W50: /var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmphqq6fC:59:0: W50: Invalid unit string 'arcseconds' [astropy.io.votable.exceptions]
WARNING: W50: /var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmphqq6fC:62:0: W50: Invalid unit string 'arcseconds' [astropy.io.votable.exceptions]
WARNING: W50: /var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmphqq6fC:65:0: W50: Invalid unit string 'arcseconds' (suppressing further warnings of this type...) [astropy.io.votable.exceptions]
Out[2]: ['posn_col1', 'posn_col2', 'posn_col3', 'posn_col4', 'posn_col5']
keflavich commented 11 years ago

refactor has corrected this, I hope