mpdaf.obj.iter_spe(cube, index=False)[source]

An iterator over the spectra of successive image pixels in a Cube

Each call to the iterator as the spectrum of one pixel of the image. The first spectrum to be returned, is the spectrum of image pixel 0,0. Thereafter the X-axis pixel index is incremented by one at each call (modulus the length of the X-axis), and the Y-axis pixel index is incremented by one each time that the X-axis index wraps back to zero.

The return value of iter_spe() is a python generator that can be used in loops, such as in the following example:

from mpdaf.obj import iter_spe
for sp,(y,x) in iter_spe(mycube, index=True):
    print("Peak flux in pixel [%d,%d] = %g" % (y, x,

The cube that contains the spectra to be returned.


If False, return just a spectrum at each iteration. If True, return both a spectrum and the pixel index of that spectrum in the image (a tuple of image-array indexes along the axes (y,x)).