Data Readers¶
Signal readers for time series data.
SourceEntry
dataclass
¶
A source signal to read: a file path plus the rate it is sampled at.
This is the unit a :class:~tsfast.tsdata.dataset.WindowedDataset enumerates
and the key :class:Cached stores under. Because it is frozen (hashable), one
file resampled to several rates is several entries — one per factor — that
never collide in the cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
filesystem path to the source file |
required |
factor
|
float
|
resampling factor in resampled coordinates (1.0 = no resampling) |
1.0
|
HDF5Signals ¶
Temporal reader: reads named 1-D datasets from HDF5 files.
Uses np.memmap for contiguous datasets (~2x faster than h5py), falls back to h5py for chunked/compressed datasets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
list[str]
|
dataset column names to extract |
required |
dataset
|
str | None
|
HDF5 group name containing the datasets, None for root |
None
|
use_mmap
|
bool
|
if True (default), use np.memmap for contiguous datasets; if False, use direct seek+read to avoid kernel VMA pressure with many files / DataLoader workers |
True
|
Source code in tsfast/tsdata/readers.py
probe ¶
Probe HDF5 datasets and cache access info for contiguous ones.
Source code in tsfast/tsdata/readers.py
read ¶
Read columns into pre-allocated array -> [seq_len, n_features].
Source code in tsfast/tsdata/readers.py
file_len ¶
Length of first named dataset. Cached per path.
HDF5Attrs ¶
Reader for named HDF5 attributes (scalar or array).
Scalar and array attributes are flattened into a single 1-D output vector.
For example, reading a scalar dt and a (3,) array ja_rr produces
a 4-element vector [dt, ja_rr[0], ja_rr[1], ja_rr[2]].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
list[str]
|
attribute names to extract |
required |
dataset
|
str | None
|
HDF5 group name containing the attributes, None for root |
None
|
dtype
|
dtype
|
output data type |
float32
|
Source code in tsfast/tsdata/readers.py
probe ¶
Probe attribute sizes from a file.
Source code in tsfast/tsdata/readers.py
Resampled ¶
Resampled(block: HDF5Signals, fs_idx: int | None = None, dt_idx: int | None = None, fast_resample: bool = True)
Wraps a temporal reader, reading in original space and resampling to a target rate.
A pure resampling view over an inner reader. The factor is read per call from
the :class:SourceEntry (entry.factor), so read/file_len keep the
same signature as every other temporal reader — there is no factor to store
and no marker to dispatch on, and a single Resampled instance serves every
file at every rate. file_len is reported in resampled coordinates, which
makes read(entry, 0, file_len) the whole-file resample; wrapping the view in
:class:Cached therefore caches one resampled copy per (path, factor) and
serves windows as slices (create_dls(..., cache_resampled=True) does this).
Reading the whole file once and slicing is also more correct than resampling each window independently: per-window resampling rebuilds the interpolation grid and lowpass-filter state from each window's own length, drifting the sample grid and leaving filter transients at window boundaries. One resample of the whole signal yields a single, consistent grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block
|
HDF5Signals
|
temporal reader with read(entry, l_slc, r_slc) and file_len(entry) |
required |
fs_idx
|
int | None
|
column index of sampling rate, scaled by resampling factor |
None
|
dt_idx
|
int | None
|
column index of time step, scaled by resampling factor |
None
|
fast_resample
|
bool
|
use linear interpolation (True) or FFT resampling (False) |
True
|
Source code in tsfast/tsdata/readers.py
read ¶
Read a window in resampled coordinates.
Reads only the raw span covering [l_slc, r_slc] and resamples it.
Called with the whole resampled range (by :class:Cached) it reads and
resamples the whole file; called per-window (cache disabled) it resamples
just that span.
Source code in tsfast/tsdata/readers.py
file_len ¶
CSVSignals ¶
Cached ¶
Wrapper that caches a reader's whole-file output in memory on first read.
The single caching mechanism in the pipeline, keyed by :class:SourceEntry.
It is reader-agnostic: it asks the inner reader for its whole-file output once
and serves windows as slices. Wrapping a :class:Resampled view therefore
caches the resampled signal — Cached does the caching, Resampled only
the resampling — and because the entry carries the factor, one file at several
rates is several keys in the same cache that never collide.
The inner reader supplies its whole-file output via read(entry, 0, file_len)
when it is temporal (has file_len), else read(entry) (scalars).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block
|
any signal reader to wrap |
required |
Source code in tsfast/tsdata/readers.py
FilenameScalar ¶
Scalar reader: extracts numbers from filenames via regex.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
regex with capture groups to extract from the filename stem |
'(\\d+\\.?\\d*)'
|
Source code in tsfast/tsdata/readers.py
read ¶
Search filename stem and return captured groups as float32 array.