This section includes information for using the pure Python API of bob.io.base.
Bases: object
File(filename, [mode=’r’, [pretend_extension=’‘]]) -> new bob::io::File
Use this object to read and write data into files.
Constructor parameters:
Adds the contents of an object to the file.
Parameters:
This method appends data to the file. If the file does not exist, creates a new file, else, makes sure that the inserted array respects the previously set file structure.
Returns the current position of the newly written array.
Name of the File class implementation – available for compatibility reasons with the previous versions of this library.
Returns a description (dtype, shape, stride) of data at the file.
Parameters:
The path to the file being read/written
Reads a specific object in the file, or the whole file.
Parameters:
This method reads data from the file. If you specified an index, it reads just the object indicated by the index, as you would do using the [] operator. If an index is not specified, reads the whole contents of the file into a numpy.ndarray.
Writes the contents of an object to the file.
Parameters:
This method writes data to the file. It acts like the given array is the only piece of data that will ever be written to such a file. No more data appending may happen after a call to this method.
Bases: object
HDF5File(filename, [mode=’r’]) -> new bob::io::HDF5File
Reads and writes data to HDF5 files.
Constructor parameters:
HDF5 stands for Hierarchical Data Format version 5. It is a flexible, binary file format that allows one to store and read data efficiently into files. It is a cross-platform, cross-architecture format.
Objects of this class allows users to read and write data from and to files in HDF5 format. For an introduction to HDF5, visit the HDF5 Website.
Appends a scalar or an array to a dataset
Parameters:
Changes the current prefix path.
Parameters:
When this object is started, the prefix path is empty, which means all following paths to data objects should be given using the full path. If you set this to a different value, it will be used as a prefix to any subsequent operation until you reset it. If path starts with '/', it is treated as an absolute path. '..' and '.' are supported. This object should be an str object. If the value is relative, it is added to the current path. If it is absolute, it causes the prefix to be reset. Note all operations taking a relative path, following a cd(), will be considered relative to the value defined by the cwd property of this object.
Closes this file
This function closes the HDF5File after flushing all its contents to disk.After the HDF5File is closed, any operation on it will result in an exception.
Copies all accessible content to another HDF5 file
Parameters:
Creates a new path (group) inside the file.
Parameters:
Creates a new directory (i.e., a group in HDF5 parlance) inside the file. A relative path is taken w.r.t. to the current directory. If the directory already exists (check it with HDF5File.has_group(), an exception will be raised.
The current working directory set on the file
Removes a given attribute at the named resource.
Parameters:
Removes attributes in a given (existing) path
Parameters:
Describes a dataset type/shape, if it exists inside a file
Parameters:
If a given path to an HDF5 dataset exists inside the file, return a type description of objects recorded in such a dataset, otherwise, raises an exception. The returned value type is a tuple of tuples (HDF5Type, number-of-objects, expandable) describing the capabilities if the file is read using theses formats.
str <– The name (and path) of the underlying file on hard disk
Flushes the content of the HDF5 file to disk
When the HDF5File is open for writing, this function synchronizes the contents on the disk with the one from the file.When the file is open for reading, nothing happens.
Retrieve a given attribute from the named resource.
Parameters:
This method returns a single value corresponding to what is stored inside the attribute container for the given resource. If you would like to retrieve all attributes at once, use HDF5File.get_attributes() instead.
All attributes of the given path organized in dictionary
Parameters:
Attributes are returned in a dictionary in which each key corresponds to the attribute name and each value corresponds to the value stored inside the HDF5 file. To retrieve only a specific attribute, use HDF5File.get_attribute().
Checks existence of a given attribute at the named resource.
Parameters:
Checks if a dataset exists inside a file
Parameters:
Checks if a dataset exists inside a file, on the specified path. If the given path is relative, it is take w.r.t. to the current working directory.
Checks if a path (group) exists inside a file
Parameters:
Checks if a path (i.e. a group in HDF5 parlance) exists inside a file. This method does not work for datasets, only for directories. If the given path is relative, it is take w.r.t. to the current working directory.
x.has_dataset(key) -> bool
Checks if a dataset exists inside a file
Parameters:
Checks if a dataset exists inside a file, on the specified path. If the given path is relative, it is take w.r.t. to the current working directory.
x.paths([relative=False]) -> tuple
Lists datasets available inside this file
Parameters:
Returns all paths to datasets available inside this file, stored under the current working directory. If relative is set to True, the returned paths are relative to the current working directory, otherwise they are absolute.
Reads some contents of the dataset.
Parameters:
This method reads contents from a dataset, treating the N-dimensional dataset like a container for multiple objects with N-1 dimensions. It returns a single numpy.ndarray in case pos is set to a value >= 0, or a list of arrays otherwise.
Lists datasets available inside this file
Parameters:
Returns all paths to datasets available inside this file, stored under the current working directory. If relative is set to True, the returned paths are relative to the current working directory, otherwise they are absolute.
Reads whole datasets from the file.
Parameters:
Renames datasets in a file
Parameters:
Modifies the value of a scalar/array in a dataset.
Parameters:
Sets the scalar or array at position 0 to the given value.
Parameters:
This method is equivalent to checking if the scalar or array at position 0 exists and then replacing it. If the path does not exist, we append the new scalar or array.
Sets a given attribute at the named resource.
Parameters:
Warning
Attributes in HDF5 files are supposed to be small containers or simple scalars that provide extra information about the data stored on the main resource (dataset or group|directory). Attributes cannot be retrieved in chunks, contrary to data in datasets.
Currently, no limitations for the size of values stored on attributes is imposed.
Sets attributes in a given (existing) path using a dictionary
Parameters:
Warning
Attributes in HDF5 files are supposed to be small containers or simple scalars that provide extra information about the data stored on the main resource (dataset or group|directory). Attributes cannot be retrieved in chunks, contrary to data in datasets.
Currently, no limitations for the size of values stored on attributes is imposed.
Lists groups (directories) in the current file.
Parameters:
Unlinks datasets inside the file making them invisible.
Parameters:
If a given path to an HDF5 dataset exists inside the file, unlinks it. Please note this will note remove the data from the file, just make it inaccessible. If you wish to cleanup, save the reacheable objects from this file to another HDF5File object using copy(), for example.
bool <– Has this file been opened in writable mode?
Loads the contents of a file, an iterable of files, or an iterable of bob.io.File‘s into a numpy.ndarray.
Parameters:
inputs
This might represent several different entities:
- The name of a file (full path) from where to load the data. In this case, this assumes that the file contains an array and returns a loaded numpy ndarray.
- An iterable of filenames to be loaded in memory. In this case, this would assume that each file contains a single 1D sample or a set of 1D samples, load them in memory and concatenate them into a single and returned 2D numpy ndarray.
- An iterable of bob.io.File. In this case, this would assume that each bob.io.File contains a single 1D sample or a set of 1D samples, load them in memory if required and concatenate them into a single and returned 2D numpy ndarray.
- An iterable with mixed filenames and bob.io.File. In this case, this would returned a 2D numpy.ndarray, as described by points 2 and 3 above.
Converts an iterable of filenames into an iterable over read-only bob.io.File’s.
Parameters:
filenames
This might represent:
- A single filename. In this case, an iterable with a single bob.io.File is returned.
- An iterable of filenames to be converted into an iterable of bob.io.File‘s.
Saves the contents of an array-like object to file.
Effectively, this is the same as creating a bob.io.File object with the mode flag set to w (write with truncation) and calling bob.io.File.write() passing array as parameter.
Parameters:
Appends the contents of an array-like object to file.
Effectively, this is the same as creating a bob.io.File object with the mode flag set to a (append) and calling bob.io.File.append() passing array as parameter.
Parameters:
Returns the type of array (frame or sample) saved in the given file.
Effectively, this is the same as creating a bob.io.File object with the mode flag set to r (read-only) and returning bob.io.File.describe().
Parameters:
Returns the type of array (for full readouts) saved in the given file.
Effectively, this is the same as creating a bob.io.File object with the mode flag set to r (read-only) and returning bob.io.File.describe(all=True).
Parameters:
Creates a directory if it does not exists, with concurrent access support. This function will also create any parent directories that might be required. If the dryrun option is selected, it does not actually create the directory, but just writes the (Linux) command that would have been executed.
Parameters: