pySimBlocks.blocks.sources.file_source¶
- class pySimBlocks.blocks.sources.file_source.FileSource(name: str, file_path: str, key: str | None = None, repeat: bool = False, use_time: bool = False, sample_time: float | None = None)[source]¶
Bases:
BlockSourceSource block that plays samples loaded from a file.
Supported file formats:
.npz,.npy, and.csv. Each simulation step emits one row of the loaded data as a column vector. When the end of the data is reached, the block either restarts from the first sample (repeat=True) or outputs zeros.Expected data shapes:
.npz/.npy: 1D(N,)treated as(N, 1), or 2D(N, n)where N is the number of samples and n the signal dimension. Each step outputs a(n, 1)column vector..csv: a single column is selected bykey, always producing shape(N, 1). Output per step is(1, 1).
Alternatively, when
use_time=True, the output is selected by looking up the closest past timestamp in a time column bundled with the file, rather than advancing by index.- file_path¶
Resolved path to the data file as a string.
- file_type¶
Inferred file extension (
"npz","npy", or"csv").
- key¶
Array key (NPZ) or column name (CSV) to load. None for NPY files.
- repeat¶
If True, restart from the first sample after the last one.
- use_time¶
If True, select samples by time lookup instead of index.
- VALID_FILE_TYPES = {'csv', 'npy', 'npz'}¶
- classmethod adapt_params(params: Dict[str, Any], params_dir: Path | None = None) Dict[str, Any][source]¶
Resolve a relative
file_pathagainst the project directory.- Parameters:
params – Raw parameter dict loaded from the YAML project file.
params_dir – Directory of the project file, for resolving relative paths. None if not applicable.
- Returns:
Parameter dict with
file_pathresolved to an absolute path.
- initialize(t0: float) None[source]¶
Set the output to the first sample (or time-matched sample) at t0.
- Parameters:
t0 – Initial simulation time in seconds.