def __init__(self, filename, chunk_size=0.1, version='1.1'): """Initialize an HDF5 file for writing h5features. Parameters ---------- filename : str --- The name of the HDF5 file to write on. For clarity you should use a *.h5 extension but this is not required. chunk_size : float, optional --- The size in Mo of a chunk in the file. Default is 0.1 Mo. A chunk size below 8 Ko is not allowed as it results in poor performances. Raise ----- IOError if the file exists but is not HDF5. IOError if the chunk size is below 8 Ko. """ if not is_supported_version(version): raise IOError('version {} is not supported'.format(version)) self.version = version # Raise if the file exists but is not HDF5 if os.path.isfile(filename) and not h5py.is_hdf5(filename): raise IOError('{} is not a HDF5 file.'.format(filename)) self.filename = filename if chunk_size < 0.008: raise IOError('chunk size is below 8 Ko') self.chunk_size = chunk_size
def _read_version(self): """Return the h5features version of the readed file. This method raise IOError if version is not either 0.1, 1.0 or 1.1 """ version = ('0.1' if not 'version' in self.group.attrs else self.group.attrs['version']) # decode from bytes to str if type(version) == bytes: version = version.decode() if not is_supported_version(version): raise IOError('version {} is not supported'.format(version)) return version