def __init__(self, arg, multifile=True, filesize=None, detectmosaic=True): """Open CZI file and read header. Raise ValueError if file is not a ZISRAW file. Parameters ---------- multifile : bool If True (default), the master file of a multifile CZI file will be opened if applicable. filesize : int Size of file if arg is a file handle pointing to an embedded CZI file. detectmosaic : bool If True (default), mosaic images will be reconstructed from SubBlocks with a tile index. Notes ----- CziFile instances created from file name must be closed using the 'close' method, which is automatically called when using the 'with' statement. """ self._fh = FileHandle(arg, size=filesize) try: if self._fh.read(10) != b'ZISRAWFILE': raise ValueError("not a CZI file") self.header = Segment(self._fh, 0).data() except Exception: self._fh.close() raise if multifile and self.header.file_part and isinstance(arg, basestring): # open master file instead self._fh.close() name, _ = match_filename(arg) self._fh = FileHandle(name) self.header = Segment(self._fh, 0).data() assert (self.header.primary_file_guid == self.header.file_guid) assert (self.header.file_part == 0) if self.header.update_pending: warnings.warn("file is pending update") self._filter_mosaic = detectmosaic