torchsig.utils.file_handlers.npy.NPYReader

class torchsig.utils.file_handlers.npy.NPYReader(root: str)[source]

Bases: FileReader

Read a directory that contains *.npy files, a metadata.csv and an info.json.

The class presents the whole collection as a flat, indexable dataset: reader[idx] returns a Signal whose data attribute holds the waveform (as a 1-D np.ndarray) and whose metadata attribute holds the parsed CSV row for that index.

Parameters:

root – Path to the directory that holds the *.npy files, metadata.csv and info.json. root may be a string or a pathlib.Path.

npy_files

List[Path] - sorted list of discovered *.npy files.

file_start_indices

List[int] - cumulative start index of each file in the global index space.

total_elements

int - actual number of samples stored across all *.npy files.

class_list

List[str] - ordered list of class names used to compute class_index.

dataset_size

int - size advertised by info.json (returned by len(reader)).

Methods

read

Return the waveform and its metadata for the global index idx.

__init__(root: str)[source]

File reader base class

Parameters:

root (str) – Dataset location on disk.

read(idx: int) Signal[source]

Return the waveform and its metadata for the global index idx.

Parameters:

idx – Zero-based global index of the waveform to retrieve.

Returns:

A Signal whose data attribute is a np.ndarray of shape (1,) containing the complex sample, and whose metadata attribute holds the parsed CSV row for that index.

Return type:

Signal

Raises:

IndexError – If idx is negative or greater than or equal to self.total_elements.

__repr__() str

Return repr(self).

__str__() str

Return str(self).