radio-astro-tools / spectral-cube

Library for reading and analyzing astrophysical spectral data cubes
http://spectral-cube.rtfd.org
BSD 3-Clause "New" or "Revised" License
97 stars 65 forks source link

Handle bad files better #734

Open keflavich opened 3 years ago

keflavich commented 3 years ago

I have a file in which the CASA beam table contains some NAN beams and some beams where minor > major because of numerical errors.

It results in this traceback:

>>> cube = SpectralCube.read('w51test.fits')
Traceback (most recent call last):
  File "<ipython-input-44-6b8606503efb>", line 1, in <module>
    cube = SpectralCube.read('w51test.fits')
  File "/home/adam/repos/spectral-cube/spectral_cube/io/core.py", line 118, in __call__
    return registry.read(BaseSpectralCube, filename, *args, **kwargs)
  File "/home/adam/anaconda3/envs/python3.9/lib/python3.9/site-packages/astropy/io/registry.py", line 527, in read
    data = reader(*args, **kwargs)
  File "/home/adam/repos/spectral-cube/spectral_cube/io/fits.py", line 185, in load_fits_cube
    cube = VRSC(data, wcs, mask, meta=meta, header=header,
  File "/home/adam/repos/spectral-cube/spectral_cube/spectral_cube.py", line 3636, in __init__
    beams = Beams(major=u.Quantity(beam_data_table['BMAJ'], u.arcsec),
  File "/home/adam/anaconda3/envs/python3.9/lib/python3.9/site-packages/radio_beam/multiple_beams.py", line 91, in __new__
    raise ValueError("Minor axis greater than major axis.")
ValueError: Minor axis greater than major axis.

This cube unfortunately exists in the wild, with DOI:

response = requests.get('https://dataverse.harvard.edu/api/access/datafile/:persistentId?persistentId=doi:10.7910/DVN/8QJT3K/IBNYSN', stream=True)
with open('w51test.fits', 'wb') as fh:
    fh.write(response.content)

This is basically a radio_beam issue, but spectral-cube needs to do some things to handle this.