FITS problem reading binary table with variable length columns
See original GitHub issueI want to read a certain FITS file (P190mm-PAFBE-FEBEPAR.fits.zip), which is part of a Multi-Beam-FITS measurement set (MBFITS) as used by several radio observatories around the world. The file has a binary table extension with variable length columns. Usually this works fine, but this particular example has some columns with a “1PJ(1)” type (and one row only), which seems to lead to problems when reading with astropy.io.fits:
import astropy
astropy.__version__
# '3.0.4'
from astropy.io import fits
data = fits.getdata('P190mm-PAFBE-FEBEPAR.fits', 1)
data
# FITS_rec([(1, 1)],
# dtype=(numpy.record, {'names':['USEBAND','NUSEFEED','USEFEED','BESECTS','FEEDTYPE','FEEDOFFX','FEEDOFFY','REFFEED','POLTY','POLA','APEREFF','BEAMEFF','ETAFSS','HPBW','ANTGAIN','TCAL','BOLCALFC','BEGAIN','BOLDCOFF','FLATFIEL','GAINIMAG','GAINELE1','GAINELE2'], 'formats':['>i4','>i4',('>i4', (1, 1)),('>i4', (1, 1)),('>i4', (1, 1)),'>f8','>f8','>i4','S1','>f4',('>f4', (1, 1)),('>f4', (1, 1)),('>f4', (1, 1)),('>f4', (1, 1)),('>f4', (1, 1)),('>f4', (1, 1)),'>f4','>f4',('>f4', (1, 1)),('>f4', (1, 1)),('>f4', (1, 1)),'>f4','>f4'], 'offsets':[0,4,8,16,24,32,40,48,52,53,57,61,65,69,73,77,81,85,89,93,97,101,105], 'itemsize':109}))
Here it appears already, that the content of the record (“(1, 1)”] is smaller than the ‘itemsize’ (109). In fact, accessing the first two columns works, but all var-length columns raise an error:
data['USEBAND']
# array([1], dtype=int32)
data['NUSEFEED']
# array([1], dtype=int32)
data['USEFEED']
# IndexError Traceback (most recent call last)
# ...
# site-packages/astropy/io/fits/fitsrec.py in _convert_p(self, column, field, recformat)
# 792
# 793 for idx in range(len(self)):
# --> 794 offset = field[idx, 1] + self._heapoffset
# 795 count = field[idx, 0]
# 796
# IndexError: index 1 is out of bounds for axis 1 with size 1
I checked the file with fitsverify, which results in zero warnings and errors.
Thanks a lot for your help!
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (10 by maintainers)
Top Results From Across the Web
4.10 Variable-Length Arrays in Binary Tables - HEASARC
All the data in a variable length field is written into an area called the `heap' which follows the main fixed-length FITS binary...
Read more >Less Familiar Objects — Astropy v5.1.1
In this chapter, we will discuss less frequently used FITS data structures. They include ASCII tables, variable length tables, and random access group...
Read more >readFITSbintable: Read a FITS binary table in FITSio - Rdrr.io
Read a FITS binary table from an open connection to a FITS file. ... Other lengths are not supported. ... Vector of column...
Read more >MRDFITS - L3HarrisGeospatial.com
FITS scaling keywords will be modified. ... binary tables. /POINTER_VAR- Use pointer arrays for variable length columns. ... first). ... So that the...
Read more >Binary table extension to FITS. - NASA/ADS
Binary table extension to FITS reader can decide if it wants (or ... The data for the variable length arrays in a table...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve noticed a few more problems besides those listed above. Specifically:
chararray
type, and thus display poorly. In theio.fits
interface, they interfere with the table being displayed at all.table
interface, and theio.fits
interface writes them incorrectly.I’ve noticed this issue on both Linux and Mac OS. Tested with python versions
3.6.0
and3.7.2
, ipython version3.7.2
, astropy version3.1.1
, and numpy version1.16.0
.@saimn I’m not sure if you are still working on this, but if not I’m happy to hack on this and try to submit a patch.
To reproduce:
vla-example.fits
from astropy-fits-bug.tar.gz, or use this program to generate it.io.fits
interface.table
interface. (Here I’m starting a newipython
session for clarity.)table
interface.Sounds about right for FITS. 😬