[AstroPy] Accessing a FITS table generates "ValueError: Inconsistent data column lengths: set([0, 27645])"

Jordan Alexander jordan.alexander at aut.ac.nz
Tue Apr 17 15:58:28 EDT 2018


> On 17 April 2018 at 13:52, Derek Homeier <derek at astro.physik.uni-goettingen.de> wrote:
>Jordan, then I’d also suggest to file an issue on https://github.com/astropy/astropy/issues
>if you could provide an example file. I guess reading the HDU directly into a Table as

>dat = Table.read('WS001H.0.bin0000.source0000.FITS’, hdu=8)

>fails in the same way?

>Cheers,
>                                       Derek

Thanks for responding, Derek, Daniel, and Tom.

Yes, it fails in the same way, as shown below.

Also, 

> Can you read hdulist[1].data (which has a zero width column as well)?

fails in the same way, as you predicted, given the zero width column.

As suggested, I will file this issue with https://github.com/astropy/astropy/issues.  

The FITS file in question with tables containing zero-width columns that generates this issue is ~0.5Gbytes, so will try to find a smaller-sized example file.... 

Will follow-up with your untested work-around, Tom...

---------

Table.read("WS001H.0.bin0000.source0000.FITS", hdu=8)

<generates>

ValueError                                Traceback (most recent call last)
<ipython-input-92-aecce75bbb33> in <module>()
      3 #Table(hdulist[1].data)
      4 #Table(hdulist[8].data)
----> 5 Table.read("WS001H.0.bin0000.source0000.FITS", hdu=8)

/usr/local/lib/python2.7/dist-packages/astropy/table/table.pyc in read(cls, *args, **kwargs)
   2519         out = io_registry.read(cls, *args, **kwargs)
   2520         # For some readers (e.g., ascii.ecsv), the returned `out` class is not
-> 2521         # guaranteed to be the same as the desired output `cls`.  If so,
   2522         # try coercing to desired class without copying (io.registry.read
   2523         # would normally do a copy).  The normal case here is swapping

/usr/local/lib/python2.7/dist-packages/astropy/io/registry.pyc in read(cls, *args, **kwargs)
    529 
    530         reader = get_reader(format, cls)
--> 531         data = reader(*args, **kwargs)
    532 
    533         if not isinstance(data, cls):

/usr/local/lib/python2.7/dist-packages/astropy/io/fits/connect.pyc in read_table_fits(input, hdu)
    134 
    135         try:
--> 136             return read_table_fits(hdulist, hdu=hdu)
    137         finally:
    138             hdulist.close()

/usr/local/lib/python2.7/dist-packages/astropy/io/fits/connect.pyc in read_table_fits(input, hdu)
    146 
    147     # Convert to an astropy.table.Table object
--> 148     t = Table(table.data, masked=masked)
    149 
    150     # Copy over null values if needed

/usr/local/lib/python2.7/dist-packages/astropy/table/table.pyc in __init__(self, data, masked, names, dtype, meta, copy, rows, copy_indices, **kwargs)
    411         init_func(data, names, dtype, n_cols, copy)
    412 
--> 413         # Whatever happens above, the masked property should be set to a boolean
    414         if type(self.masked) is not bool:
    415             raise TypeError("masked property has not been set to True or False")

/usr/local/lib/python2.7/dist-packages/astropy/table/table.pyc in _init_from_ndarray(self, data, names, dtype, n_cols, copy)
    700             self._init_from_list(cols, names, dtype, n_cols, copy)
    701         else:
--> 702             dtype = [(name, col.dtype, col.shape[1:]) for name, col in zip(names, cols)]
    703             newdata = data.view(dtype).ravel()
    704             columns = self.TableColumns()

/usr/local/lib/python2.7/dist-packages/astropy/table/table.pyc in _init_from_list(self, data, names, dtype, n_cols, copy)
    684         self._init_from_cols(cols)
    685 
--> 686     def _init_from_ndarray(self, data, names, dtype, n_cols, copy):
    687         """Initialize table from an ndarray structured array"""
    688 

/usr/local/lib/python2.7/dist-packages/astropy/table/table.pyc in _init_from_cols(self, cols)
    749                              .format(lengths))
    750 
--> 751         # Set the table masking
    752         self._set_masked_from_cols(cols)
    753 

ValueError: Inconsistent data column lengths: set([0, 27645])


More information about the AstroPy mailing list