From c2c7b8f3708a3770d2b0416d8112a097d8ab1a45 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Thu, 14 Sep 2017 17:21:06 -0400 Subject: [PATCH] Give a nice error if no data is present in the selected HDU --- CHANGES.rst | 4 ++++ spectral_cube/io/fits.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 3ee1d6ffa..632fc614e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,5 +1,9 @@ 0.4.1 (unreleased) ------------------ + + - Raise a nicer error if no data is present in the default or + selected HDU + (https://github.com/radio-astro-tools/spectral-cube/pull/424) - Check mask inputs to OneDSpectrum and add mask handling for OneDSpectrum.spectral_interpolate (https://github.com/radio-astro-tools/spectral-cube/pull/400) diff --git a/spectral_cube/io/fits.py b/spectral_cube/io/fits.py index 062d94b4a..2e4961e5e 100644 --- a/spectral_cube/io/fits.py +++ b/spectral_cube/io/fits.py @@ -134,6 +134,10 @@ def load_fits_cube(input, hdu=0, meta=None, **kwargs): data, header, beam_table = read_data_fits(input, hdu=hdu, **kwargs) + if data is None: + raise Exception('No data found in HDU {0}. You can try using the hdu= ' + 'keyword argument to read data from another HDU.'.format(hdu)) + if meta is None: meta = {}