def read_rec(fileobj, **keys): import numpy header=keys.get('header',False) view=keys.get('view',numpy.ndarray) rows=keys.get('rows',None) columns=keys.get('columns',None) fields=keys.get('fields',None) ensure_native = keys.get('ensure_native',False) if header == 'only': return sfile.read_header(fileobj) # if dtype is sent, we assume there is no header at all dtype = keys.get('dtype',None) if dtype is not None: data = read_rec_plain(fileobj, **keys) header=False else: if header: data,hdr = sfile.read(fileobj, header=header, view=view, rows=rows, fields=fields, columns=columns) else: data = sfile.read(fileobj, header=header, view=view, rows=rows, fields=fields, columns=columns) if ensure_native: numpy_util.to_native(data, inplace=True) if header: return data,hdr else: return data
def read_fits(fname, **keywords): """ Name: read_fits Purpose: Read data from a single fits file. Calling Sequence: data=read_fits(fname, **keywords) Inputs: fname: The file name Keywords: ext: Which extension, or HDU, to read. Default first with data. view: What view of the data to return. Default is numpy.ndarray header: Return the data,header tuple? Default False. rows: Subset of the rows to return if reading a binary table extension. columns: Subset of the columns to return if reading a binary table. fields: synonymous with columns lower: Force the field names to be lower case. upper: Force the field names to be upper case. ensure_native: FITS always stores big-endian byte order. Sending ensure_native=True forces the byte ordering to be machine native. Example: import esutil data=esutil.io.read('test.fits', ext=1, ) """ import numpy if fname[-4:] == '.bz2': return read_fits_bz2(fname, **keywords) if fits_package is None: raise ImportError("Could not import fitsio or pyfits") if fits_package == 'fitsio': result = read_fits_fitsio(fname, **keywords) elif fits_package == 'pyfits': result = read_fits_pyfits(fname, **keywords) else: raise ValueError("expected fitsio or pyfits") h=None if isinstance(result,tuple): d,h = result elif keywords.get('header') == 'only': return result else: d = result lower= keywords.get('lower',False) upper= keywords.get('upper',False) if lower: d.dtype.names = [n.lower() for n in d.dtype.names] elif upper: d.dtype.names = [n.upper() for n in d.dtype.names] view = keywords.get('view',numpy.ndarray) if view is not None: d=d.view(view) ensure_native = keywords.get('ensure_native',False) if ensure_native: numpy_util.to_native(d, inplace=True) if h is not None: return d,h else: return d
def read_fits(fileobj, **keywords): """ Name: read_fits Purpose: Read data from a single fits file. Calling Sequence: data=read_fits(fileobj, **keywords) Inputs: fileobj: The file name/file object for a fits file. Keywords: ext: Which extension, or HDU, to read. Default first with data. view: What view of the data to return. Default is numpy.ndarray header: Return the data,header tuple? Default False. rows: Subset of the rows to return if reading a binary table extension. columns: Subset of the columns to return if reading a binary table. fields: synonymous with columns lower: Force the field names to be lower case. upper: Force the field names to be upper case. ensure_native: FITS always stores big-endian byte order. Sending ensure_native=True forces the byte ordering to be machine native. Example: import esutil data=esutil.io.read('test.fits', ext=1, ) """ import numpy if isinstance(fileobj,basestring) and 'bz2' in fileobj: return read_fits_bz2(fileobj, **keywords) if fits_package is None: raise ImportError("Could not import fitsio or pyfits") if fits_package == 'fitsio': result = read_fits_fitsio(fileobj, **keywords) elif fits_package == 'pyfits': result = read_fits_pyfits(fileobj, **keywords) else: raise ValueError("expected fitsio or pyfits") h=None if isinstance(result,tuple): d,h = result elif keywords.get('header') == 'only': return result else: d = result lower= keywords.get('lower',False) upper= keywords.get('upper',False) if lower: d.dtype.names = [n.lower() for n in d.dtype.names] elif upper: d.dtype.names = [n.upper() for n in d.dtype.names] view = keywords.get('view',numpy.ndarray) if view is not None: d=d.view(view) ensure_native = keywords.get('ensure_native',False) if ensure_native: numpy_util.to_native(d, inplace=True) if h is not None: return d,h else: return d