コード例 #1
0
ファイル: io.py プロジェクト: esheldon/esutil
def _get_fname_ftype_from_inputs(fileobj, **keywords):
    """
    Get filename, file type, and file system
    """

    fs='local'

    try:
        fname = fileobj.name
        fobj = fileobj
    except AttributeError:
        if is_in_hdfs(fileobj):
            fs='hdfs'

        # make sure we expand all ~username and other variables
        fname=ostools.expand_filename(fileobj)
        fobj = fname

    ftype=None
    if 'type' in keywords:
        ftype=keywords['type']
    elif 'typ' in keywords:
        ftype = keywords['typ']

    if ftype is None:
        ftype=get_ftype(fname)
    ftype = ftype.lower()

    return fname, fobj, ftype, fs
コード例 #2
0
def _get_fname_ftype_from_inputs(fileobj, **keywords):
    """
    Get filename, file type, and file system
    """

    fs='local'

    if isinstance(fileobj, file):
        fname = fileobj.name
        fobj = fileobj
    elif isinstance(fileobj, (str,unicode)):
        if is_in_hdfs(fileobj):
            fs='hdfs'

        # make sure we expand all ~username and other variables
        fname=ostools.expand_filename(fileobj)
        fobj = fname
    else:
        raise ValueError("Input must be a string or file object, or a "
                         "list thereof")


    ftype=None
    if 'type' in keywords:
        ftype=keywords['type']
    elif 'typ' in keywords:
        ftype = keywords['typ']

    if ftype is None:
        ftype=get_ftype(fname)
    ftype = ftype.lower()

    return fname, fobj, ftype, fs
コード例 #3
0
def _get_fname_ftype_from_inputs(fileobj, **keywords):
    """
    Get filename, file type, and file system
    """

    fs = 'local'

    try:
        fname = fileobj.name
        fobj = fileobj
    except AttributeError:
        if is_in_hdfs(fileobj):
            fs = 'hdfs'

        # make sure we expand all ~username and other variables
        fname = ostools.expand_filename(fileobj)
        fobj = fname

    ftype = None
    if 'type' in keywords:
        ftype = keywords['type']
    elif 'typ' in keywords:
        ftype = keywords['typ']

    if ftype is None:
        ftype = get_ftype(fname)
    ftype = ftype.lower()

    return fname, fobj, ftype, fs
コード例 #4
0
def read_fits_pyfits(fileobj, **keywords):
    import numpy
    import pyfits
    header = keywords.get('header', False)
    rows=None
    fields=None
    columns=None

    if 'verbose' in keywords:
        del keywords['verbose']

    if 'rows' in keywords:
        rows=keywords['rows']
        del keywords['rows']

    if 'fields' in keywords:
        fields=keywords['fields']
        del keywords['fields']
    if 'columns' in keywords:
        columns=keywords['columns']
        del keywords['columns']

    if fields is None:
        if columns is not None:
            # allow columns to be synonymous with fields
            fields=columns

    if isinstance(fileobj,(str,unicode)):
        fileobj=ostools.expand_filename(fileobj)

    if 'ignore_missing_end' not in keywords:
        # the ignore_missing_end=True is for the multitude
        # of malformed FITS files out there
        keywords['ignore_missing_end'] = True

    if header == 'only':
        return pyfits.getheader(fileobj, **keywords)

    if header:
        d,h = pyfits.getdata(fileobj, **keywords)
    else:
        d = pyfits.getdata(fileobj, **keywords)

    view = keywords.get('view',numpy.ndarray)
    if view is not None:
        d = d.view(view)

    # extract subsets of the data
    if rows is not None:
        d = d[rows]

    if fields is not None:
        d = numpy_util.extract_fields(d.view(numpy.ndarray), fields)

    if header:
        return d,h
    else:
        return d