Acoular 25.07 documentation

WriteH5

«  WriteWAV   ::   tprocess   ::   TimeConvolve  »

WriteH5

class acoular.tprocess.WriteH5

Bases: TimeOut

Saves time signal data as a .h5 (HDF5) file.

Inherits from TimeOut and provides functionality for saving multi-channel time-domain signal data to an HDF5 file. The file can be written in blocks and supports metadata storage, precision control, and dynamic file generation based on timestamps.

See also

acoular.base.TimeOut

ABC for signal processing blocks interacting with data from a source.

acoular.base.SamplesGenerator

Interface for generating multi-channel time-domain signal processing blocks.

h5py

Python library for reading and writing HDF5 files.

source = Instance(SamplesGenerator)

The input data source. It must be an instance of a SamplesGenerator-derived class.

file = File(filter=['*.h5'], desc='name of data file')

The name of the file to be saved. If none is given, the name is automatically generated based on the current timestamp.

num_samples_write = Int(-1)

The number of samples to write to file per call to result method. Default is -1, meaning all available data from the source will be written.

write_flag = Bool(True)

A flag that can be set to stop file writing. Default is True.

digest = Property(depends_on=['source.digest'])

A unique identifier for the object, based on its properties. (read-only)

precision = Enum('float32', 'float64', desc='precision of H5 File')

Precision of the entries in the HDF5 file, represented as numpy data types. Default is 'float32'.

metadata = Dict(desc='metadata to be stored in .h5 file')

Metadata to be stored in the HDF5 file.

create_filename()

Generate a filename for the HDF5 file if needed.

Generate a filename for the HDF5 file based on the current timestamp if no filename is provided. If a filename is provided, it is used as the file name.

get_initialized_file()

Initialize the HDF5 file and prepare the necessary datasets and metadata.

This method creates the file (if it doesn’t exist), sets up the main data array, and appends metadata to the file.

Returns:
h5py.File

The initialized HDF5 file object ready for data insertion.

save()

Save the source output to a HDF5 file.

This method writes the processed time-domain signal data from the source to the specified HDF5 file. Data is written in blocks and appended to the extendable 'time_data' array.

Notes

  • If no file is specified, a file name is automatically generated.

  • Metadata defined in the metadata attribute is stored in the file.

add_metadata(f5h)

Add metadata to the HDF5 file.

Metadata is stored in a separate ‘metadata’ group within the HDF5 file. The metadata is stored as arrays with each key-value pair corresponding to a separate array.

Parameters:
f5hh5py.File

The HDF5 file object to which metadata will be added.

result(num)

Python generator that saves source output to an HDF5 file.

This method processes data from the source in blocks and writes the data to the HDF5 file. It yields the processed blocks while the data is being written.

Parameters:
numint

Number of samples per block.

Yields:
numpy.ndarray

A numpy array of shape (num, num_channels), where num_channels is inhereted from the source, delivering the processed time-domain signal data. The last block may contain fewer samples if the total number of samples is not a multiple of num.

Notes

  • If num_samples_write is set to a value other than -1, only that number of samples will be written to the file.

  • The data is echoed as it is yielded, after being written to the file.

«  WriteWAV   ::   tprocess   ::   TimeConvolve  »