Skip to content

Instantiating an Image with a cube FITS should raise an error

It is possible to instantiate a mpdaf.obj.Image object while passing a cube FITS:

In [1]: from mpdaf.obj import Image

In [2]: i = Image("DATACUBE_UDF-10.fits")

In [3]: i
Out[3]: <Image(shape=(3681, 322, 323), unit='1e-20 erg / (Angstrom cm2 s)', dtype='None')>

Of course, accessing image specific methods fails:

In [6]: i.subimage((100, 100), 100, unit_center=None, unit_size=None)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-d03ecc7e27ba> in <module>()
----> 1 i.subimage((100, 100), 100, unit_center=None, unit_size=None)

~/sources/mpdaf/lib/mpdaf/obj/image.py in subimage(self, center, size, unit_center, unit_size, minsize)
    672         [sy, sx], [uy, ux], center = bounding_box(
    673             form="rectangle", center=center, radii=radius,
--> 674             shape=self.shape, step=step)
    675 
    676         if (sx.start >= self.shape[1] or

~/sources/mpdaf/lib/mpdaf/obj/objs.py in bounding_box(form, center, radii, shape, posangle, step)
    226     # Are the selected pixels of the axes outside the bounds of the array?
    227     max_indexes = np.asarray(shape) - 1
--> 228     outside = np.logical_or(last < 0, first > max_indexes)
    229 
    230     # Clip the first and last pixels to ensure that they lie within

ValueError: operands could not be broadcast together with shapes (2,) (3,) 

An exception should be raised when the number of axis is more than 2 (maybe test for WCS to check if it's an actual image data).

Yannick