torchsig.utils.file_handlers.hdf5.HDF5Writer

class torchsig.utils.file_handlers.hdf5.HDF5Writer(root, compression: str = 'lzf', compression_opts: int | None = None, shuffle: bool = True, fletcher32: bool = True, chunk_cache_size: int = 10485760, max_batches_in_memory: int = 4)[source]

Bases: FileWriter

Handles writing Signal data to HDF5 files with specified compression and buffering.

Methods

exists

Check if the dataset directory already exists.

setup

Prepare resources before writing begins.

teardown

Clean up resources and close HDF5 file.

write

Write a batch of data to HDF5 file.

__init__(root, compression: str = 'lzf', compression_opts: int | None = None, shuffle: bool = True, fletcher32: bool = True, chunk_cache_size: int = 10485760, max_batches_in_memory: int = 4)[source]

Initializes the HDF5FileHandler.

Parameters:
  • root (str) – Where to write dataset on disk.

  • compression (str, optional) – Compression algorithm (‘gzip’, ‘szip’, ‘lzf’). Defaults to ‘lzf’.

  • compression_opts (int | None, optional) – Compression level (0-9 for gzip). Defaults to None.

  • shuffle (bool, optional) – Enable shuffle filter for better compression. Defaults to True.

  • fletcher32 (bool, optional) – Enable Fletcher32 checksum filter. Defaults to True.

  • chunk_cache_size (int, optional) – HDF5 chunk cache size in bytes. Defaults to 10MB.

  • max_batches_in_memory (int, optional) – Maximum batches to keep in memory before flushing. Defaults to 4.

teardown() None[source]

Clean up resources and close HDF5 file.

write(batch_idx: int, data) None[source]

Write a batch of data to HDF5 file.

Parameters:
  • batch_idx (int) – Index of the batch being written.

  • data (Any) – Signal data to write.

__repr__() str

Return repr(self).

__str__() str

Return str(self).

exists() bool

Check if the dataset directory already exists.

Returns:

True if self.root exists on disk, False otherwise.

Return type:

bool

setup() None

Prepare resources before writing begins.

This resets the root folder and then calls the subclass _setup.