HDF5

class mosaic.file_manipulation.h5.HDF5(*args, **kwargs)[source]

Bases: object

This class provides an interface to read and write HDF5 files. It can be used by instantiating the class on its own,

>>> file = HDF5(...)
>>> file.write(...)
>>> file.close()

or as a context manager,

>>> with HDF5(...) as file:
>>>     file.write(...)

If a particular version is given, the filename will be generated without checks. If no version is given, the path will be checked for the latest available version of the file.

The file will have the form <project_name>-<parameter in camelcase><extension> for version 0 and <project_name>-<parameter in camelcase>-<version with width of 5><extension> for higher versions.

Parameters:
  • filename (str) – Full path to a file, instead of a file being formed with version.

  • path (str) – Location of the file in the filesystem, defaults to the current working directory.

  • project_name (str) – Name of the project, the prefix that all files of the project will have.

  • parameter (str) – Parameter that determines which specific type of file to look for.

  • version (int, optional) – Integer version of the file, starting at 0. If not given, the last available version will be found.

  • extension (str, optional) – File extension, defaults to .h5.

  • mode (str) – Mode in which the file will be opened.

append(description)[source]
close()[source]
dump(description)[source]
property file
property filename
load(lazy=True, filter=None)[source]
property mode
mosaic.file_manipulation.h5.file_exists(*args, **kwargs)[source]

Check whether a certain file exists.

The file will have the form <project_name>-<parameter in camelcase><extension> for version 0 and <project_name>-<parameter in camelcase>-<version with width of 5><extension> for higher versions.

Parameters:
  • project_name (str) – Name of the project, the prefix that all files of the project will have.

  • parameter (str) – Parameter that determines which specific type of file to look for.

  • version (int) – Integer version of the file, starting at 0.

  • extension (str, optional) – File extension, defaults to .h5.

  • folder (str, optional) – Location of the file in the filesystem, defaults to the current folder.

Returns:

Whether or not a file of the specified version exists.

Return type:

bool