Beispiel #1
0
def open(file, band_file=None):
    '''
    Returns a SpyFile object for an AVIRIS image file.

    Arguments:

        `file` (str):

            Name of the AVIRIS data file.

        `band_file` (str):

            Optional name of the AVIRIS spectral calibration file.

    Returns:

        A SpyFile object for the image file.

    Raises:

        spectral.io.spyfile.InvalidFileError
    '''
    import numpy as np
    from spectral.io.bipfile import BipFile
    import os
    import glob
    from .spyfile import find_file_path, InvalidFileError
    import spectral

    class Params:
        pass
    p = Params()

    p.filename = find_file_path(file)
    p.nbands = 224
    p.ncols = 614
    fileSize = os.stat(p.filename)[6]
    if fileSize % 275072 != 0:
        raise InvalidFileError('File size not consistent with AVIRIS format.')
    p.nrows = int(fileSize / 275072)
    p.byte_order = 1
    p.dtype = np.dtype('i2').str
    if spectral.byte_order != 1:
        p.dtype = np.dtype(p.dtype).newbyteorder().str
    metadata = {'default bands': ['29', '18', '8']}
    p.offset = 0

    img = BipFile(p, metadata)
    img.scale_factor = 10000.0

    if band_file:
        img.bands = read_aviris_bands(find_file_path(band_file))

    return img
Beispiel #2
0
def open(file, band_file=None):
    '''
    Returns a SpyFile object for an AVIRIS image file.

    Arguments:

        `file` (str):

            Name of the AVIRIS data file.

        `band_file` (str):

            Optional name of the AVIRIS spectral calibration file.

    Returns:

        A SpyFile object for the image file.

    Raises:

        IOError
    '''

    import numpy as np
    from spectral.io.bipfile import BipFile
    import os
    import glob
    from exceptions import IOError
    from spyfile import find_file_path
    import spectral

    class Params:
        pass
    p = Params()

    p.filename = find_file_path(file)
    p.nbands = 224
    p.ncols = 614
    fileSize = os.stat(p.filename)[6]
    if fileSize % 275072 != 0:
        raise IOError('File size not consistent with AVIRIS format.')
    p.nrows = int(fileSize / 275072)
    p.byte_order = 1
    p.dtype = np.dtype('i2').str
    if spectral.byte_order != 1:
        p.dtype = np.dtype(p.dtype).newbyteorder().str
    metadata = {'default bands': ['29', '18', '8']}
    p.offset = 0

    img = BipFile(p, metadata)
    img.scale_factor = 10000.0

    if band_file:
        img.bands = read_aviris_bands(find_file_path(band_file))
    else:
        # Let user know if band cal files are available
        fileDir = os.path.split(p.filename)[0]
        calFiles = glob.glob(fileDir + '/*.spc')
        if len(calFiles) > 0:
            print '\nThe following band calibration files are located in ' \
                'the same directory as the opened AVIRIS file:\n'
            for f in calFiles:
                print "    " + os.path.split(f)[1]
            print '\nTo associate a band calibration file with an AVIRIS ' \
                  'data file, re-open the AVIRIS file with the following ' \
                  'syntax:\n'
            print '    >>> img = aviris.open(fileName, calFileName)\n'
    return img
Beispiel #3
0
def open(file, band_file=None):
    '''
    Returns a SpyFile object for an AVIRIS image file.

    Arguments:

        `file` (str):

            Name of the AVIRIS data file.

        `band_file` (str):

            Optional name of the AVIRIS spectral calibration file.

    Returns:

        A SpyFile object for the image file.

    Raises:

        IOError
    '''

    import numpy as np
    from spectral.io.bipfile import BipFile
    import os
    import glob
    from exceptions import IOError
    from .spyfile import find_file_path
    import spectral

    class Params:
        pass

    p = Params()

    p.filename = find_file_path(file)
    p.nbands = 224
    p.ncols = 614
    fileSize = os.stat(p.filename)[6]
    if fileSize % 275072 != 0:
        raise IOError('File size not consistent with AVIRIS format.')
    p.nrows = int(fileSize / 275072)
    p.byte_order = 1
    p.dtype = np.dtype('i2').str
    if spectral.byte_order != 1:
        p.dtype = np.dtype(p.dtype).newbyteorder().str
    metadata = {'default bands': ['29', '18', '8']}
    p.offset = 0

    img = BipFile(p, metadata)
    img.scale_factor = 10000.0

    if band_file:
        img.bands = read_aviris_bands(find_file_path(band_file))
    else:
        # Let user know if band cal files are available
        fileDir = os.path.split(p.filename)[0]
        calFiles = glob.glob(fileDir + '/*.spc')
        if len(calFiles) > 0:
            print('\nThe following band calibration files are located in ' \
                'the same directory as the opened AVIRIS file:\n')
            for f in calFiles:
                print("    " + os.path.split(f)[1])
            print('\nTo associate a band calibration file with an AVIRIS ' \
                  'data file, re-open the AVIRIS file with the following ' \
                  'syntax:\n')
            print('    >>> img = aviris.open(fileName, calFileName)\n')
    return img