{ } Raw JSON

bundles / astropy 7.0.1 / astropy / io / fits / convenience / getdata

function

astropy.io.fits.convenience:getdata

source: /astropy/io/fits/convenience.py :131

Signature

def   getdata ( filename * args header = None lower = None upper = None view = None ** kwargs )

Summary

Get the data from an HDU of a FITS file (and optionally the header).

Parameters

filename : path-like or file-like

File to get data from. If opened, mode must be one of the following rb, rb+, or ab+.

ext

The rest of the arguments are for HDU specification. They are flexible and are best illustrated by examples.

No extra arguments implies the primary HDU

getdata('in.fits')

By HDU number

getdata('in.fits', 0)      # the primary HDU
getdata('in.fits', 2)      # the second extension HDU
getdata('in.fits', ext=2)  # the second extension HDU

By name, i.e., EXTNAME value (if unique)

getdata('in.fits', 'sci')
getdata('in.fits', extname='sci')  # equivalent

Note EXTNAME values are not case sensitive

By combination of EXTNAME and EXTVER`` as separate arguments or as a tuple

getdata('in.fits', 'sci', 2)  # EXTNAME='SCI' & EXTVER=2
getdata('in.fits', extname='sci', extver=2)  # equivalent
getdata('in.fits', ('sci', 2))  # equivalent

Ambiguous or conflicting specifications will raise an exception

getdata('in.fits', ext=('sci',1), extname='err', extver=2)
header : bool, optional

If True, return the data and the header of the specified HDU as a tuple.

lower, upper : bool, optional

If lower or upper are True, the field names in the returned data object will be converted to lower or upper case, respectively.

view : ndarray, optional

When given, the data will be returned wrapped in the given ndarray subclass by calling

data.view(view)
**kwargs

Any additional keyword arguments to be passed to astropy.io.fits.open.

Returns

array : ndarray or `~numpy.recarray` or `~astropy.io.fits.Group`

Type depends on the type of the extension being referenced.

If the optional keyword header is set to True, this function will return a (data, header) tuple.

Raises

: IndexError

If no data is found in searched HDUs.

Aliases

  • astropy.io.fits.getdata