torchsig.utils.file_handlers.npy.NPYReader¶
- class torchsig.utils.file_handlers.npy.NPYReader(root: str)[source]¶
Bases:
FileReaderRead a directory that contains
*.npyfiles, ametadata.csvand aninfo.json.The class presents the whole collection as a flat, indexable dataset:
reader[idx]returns aSignalwhosedataattribute holds the waveform (as a 1-Dnp.ndarray) and whosemetadataattribute holds the parsed CSV row for that index.- Parameters:
root – Path to the directory that holds the
*.npyfiles,metadata.csvandinfo.json.rootmay be a string or apathlib.Path.
- npy_files¶
List[Path] - sorted list of discovered
*.npyfiles.
- 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
*.npyfiles.
- class_list¶
List[str] - ordered list of class names used to compute
class_index.
- dataset_size¶
int - size advertised by
info.json(returned bylen(reader)).
Methods
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
Signalwhosedataattribute is anp.ndarrayof shape(1,)containing the complex sample, and whosemetadataattribute holds the parsed CSV row for that index.- Return type:
- Raises:
IndexError – If
idxis negative or greater than or equal toself.total_elements.