#NEWLINE# def getdata( filename , * args , **kwargs ) : #NEWLINE# #INDENT# "\n    Get the data from an extension of a FITS file (and optionally the\n    header).\n\n    Parameters\n    ----------\n    filename : file path, file object, or file like object\n        File to get data from.  If opened, mode must be one of the\n        following rb, rb+, or ab+.\n\n    ext\n        The rest of the arguments are for extension specification.\n        They are flexible and are best illustrated by examples.\n\n        No extra arguments implies the primary header::\n\n            >>> getdata('in.fits')\n\n        By extension number::\n\n            >>> getdata('in.fits', 0)      # the primary header\n            >>> getdata('in.fits', 2)      # the second extension\n            >>> getdata('in.fits', ext=2)  # the second extension\n\n        By name, i.e., ``EXTNAME`` value (if unique)::\n\n            >>> getdata('in.fits', 'sci')\n            >>> getdata('in.fits', extname='sci')  # equivalent\n\n        Note ``EXTNAME`` values are not case sensitive\n\n        By combination of ``EXTNAME`` and EXTVER`` as separate\n        arguments or as a tuple::\n\n            >>> getdata('in.fits', 'sci', 2)  # EXTNAME='SCI' & EXTVER=2\n            >>> getdata('in.fits', extname='sci', extver=2)  # equivalent\n            >>> getdata('in.fits', ('sci', 2))  # equivalent\n\n        Ambiguous or conflicting specifications will raise an exception::\n\n            >>> getdata('in.fits', ext=('sci',1), extname='err', extver=2)\n\n    header : bool, optional\n        If `True`, return the data and the header of the specified HDU as a\n        tuple.\n\n    lower, upper : bool, optional\n        If ``lower`` or ``upper`` are `True`, the field names in the\n        returned data object will be converted to lower or upper case,\n        respectively.\n\n    view : ndarray, optional\n        When given, the data will be returned wrapped in the given ndarray\n        subclass by calling::\n\n           data.view(view)\n\n    kwargs\n        Any additional keyword arguments to be passed to `pyfits.open`.\n\n    Returns\n    -------\n    array : array, record array or groups data object\n        Type depends on the type of the extension being referenced.\n\n        If the optional keyword ``header`` is set to `True`, this\n        function will return a (``data``, ``header``) tuple.\n    " #NEWLINE# ( mode , closed ) = _get_file_mode ( filename ) #NEWLINE# header = kwargs . pop ( 'header' , None ) #NEWLINE# lower = kwargs . pop ( 'lower' , None ) #NEWLINE# upper = kwargs . pop ( 'upper' , None ) #NEWLINE# view = kwargs . pop ( 'view' , None ) #NEWLINE# ( hdulist , extidx ) = _getext ( filename , mode , * args , ** kwargs ) #NEWLINE# hdu = hdulist [ extidx ] #NEWLINE# data = hdu . data #NEWLINE# if ( ( data is None ) and ( extidx == 0 ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# hdu = hdulist [ 1 ] #NEWLINE# data = hdu . data #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# raise IndexError ( 'No data in this HDU.' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( data is None ) : #NEWLINE# #INDENT# raise IndexError ( 'No data in this HDU.' ) #NEWLINE# #UNINDENT# if header : #NEWLINE# #INDENT# hdr = hdu . header #NEWLINE# #UNINDENT# hdulist . close ( closed = closed ) #NEWLINE# trans = None #NEWLINE# if lower : #NEWLINE# #INDENT# trans = ( lambda s : s . lower ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if upper : #NEWLINE# #INDENT# trans = ( lambda s : s . upper ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# if trans : #NEWLINE# #INDENT# if ( data . dtype . names is None ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if ( data . dtype . descr [ 0 ] [ 0 ] == '' ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# data . dtype . names = [ trans ( n ) for n in data . dtype . names ] #NEWLINE# #UNINDENT# if ( isinstance ( view , type ) and issubclass ( view , np . ndarray ) ) : #NEWLINE# #INDENT# data = data . view ( view ) #NEWLINE# #UNINDENT# if header : #NEWLINE# #INDENT# return ( data , hdr ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return data