torchsig.utils.file_handlers.base_handler.FileWriter

class torchsig.utils.file_handlers.base_handler.FileWriter(root: str, **kwargs)[source]

Bases: object

Base class for writing datasets to disk.

root

Location on disk to write dataset.

Type:

pathlib.Path

Methods

exists

Check if the dataset directory already exists.

setup

Prepare resources before writing begins.

teardown

Hook for cleaning up resources after writing is complete.

write

Write a single batch to disk.

__init__(root: str, **kwargs)[source]

Initializes the FileWriter.

Parameters:

root (str) – Location on disk to write dataset.

setup() None[source]

Prepare resources before writing begins.

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

teardown() None[source]

Hook for cleaning up resources after writing is complete.

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

Write a single batch to disk.

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

  • data (Any) – Data to be written.

Raises:

NotImplementedError – Must be implemented in subclasses.

exists() bool[source]

Check if the dataset directory already exists.

Returns:

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

Return type:

bool

__str__() str[source]

Return str(self).

__repr__() str[source]

Return repr(self).