def __init__(self, filename, mode='r', first_byte = 0, verbose=False, local_cache = None, use_memmap=True):
        """
        local_cache : {None, str}
          Specify path to local cache. Local cache will be used to
          temporarily store files from external devises such as NFS.
        """

        self.verbose = verbose
        self.first_byte = first_byte
        self.use_memmap = use_memmap
        try:
            if local_cache is not None:
                cache_filename = local_cache + '/' + filename
                if os.path.exists(cache_filename):
                    filename = cache_filename
                elif not isindisk(filename):
                    assert isindisk(local_cache),`local_cache`
                    dirname = os.path.dirname (cache_filename)
                    if not os.path.isdir(dirname):
                        os.makedirs(dirname)
                    shutil.copyfile(filename, cache_filename)
                    filename = cache_filename
            if verbose:
                sys.stdout.write ('Opening file %r\n' % (filename)); sys.stdout.flush()
            if mode!='r':
                raise NotImplementedError(`mode`)
            if not os.path.isfile (filename):
                raise ValueError ('file does not exists')
            if not os.stat(filename).st_size:
                raise ValueError ('file has zero size')
            if use_memmap:
                self.data = numpy.memmap(filename, dtype=numpy.ubyte, mode=mode)
            else:
                assert mode=='r',`mode`
                f = open (filename, 'rb')
                self.data = numpy.frombuffer(f.read(), dtype=numpy.ubyte)
                f.close()
        except IOError, msg:
            if 'Too many open files' in str (msg):
                raise IOError(IOError_too_many_open_files_hint % msg)
            if 'Operation not permitted' in str (msg):
                raise IOError(OSError_operation_not_permitted_hint % msg)
            raise
        except OSError, msg:
            if 'Operation not permitted' in str (msg):
                raise OSError(OSError_operation_not_permitted_hint % msg)
            raise
        except mmap.error, msg:
            if 'Too many open files' in str (msg):
                raise mmap.error(IOError_too_many_open_files_hint % msg)
            raise

        self.filename = filename

        self.memory_usage = [(self.data.nbytes, self.data.nbytes, 'eof')]

        byteorder = self.data[first_byte:first_byte+2].view(dtype=numpy.uint16)[0]

        if byteorder==0x4949:
            self.endian = 'little'
            self.dtypes = LittleEndianNumpyDTypes
        elif byteorder==0x4d4d:
            self.endian = 'big'
            self.dtypes = BigEndianNumpyDTypes
        else:
            raise ValueError('unrecognized byteorder: %s' % (hex(byteorder)))
        magic = self.get_uint16(first_byte+2)
        if magic!=42:
            raise ValueError('wrong magic number for TIFF file: %s' % (magic))
        self.IFD0 = IFD0 = first_byte + self.get_uint32(first_byte+4)

        self.memory_usage.append((first_byte, first_byte+8, 'file header'))

        n = self.get_uint16(IFD0)
        IFD_list = []
        IFD_offset = IFD0
        while IFD_offset:
            n = self.get_uint16(IFD_offset)
            ifd = IFD(self)
            exif_offset = 0
            for i in range(n):
                entry = IFDEntry(ifd, self, IFD_offset + 2 + i*12)
                ifd.append(entry)
                if entry.tag == 0x8769: # TIFFTAG_EXIFIFD
                    exif_offset=entry.value
            ifd.finalize()
            IFD_list.append(ifd)
            self.memory_usage.append((IFD_offset, IFD_offset + 2 + n*12 + 4, 'IFD%s entries (%s)' % (len(IFD_list), len(ifd))))
            IFD_offset = self.get_uint32(IFD_offset + 2 + n*12)
            if IFD_offset == 0 and exif_offset != 0:
                IFD_offset = exif_offset
                exif_offset = 0
            if verbose:
                sys.stdout.write('\rIFD information read: %s..' % (len (IFD_list))); sys.stdout.flush()

        self.IFD = IFD_list
        if verbose:
            sys.stdout.write(' done\n'); sys.stdout.flush()

        self.time = None
dataset/ETHPy150Open pearu/pylibtiff/libtiff/tiff_file.py/TIFFfile.__init__/original