canml Module
This is the top‐level package for canml.
- canml.iter_blf_chunks(blf_path: str, db: Database, chunk_size: int = 10000, filter_ids: Set[int] | None = None) Iterator[DataFrame][source]
Stream‐decode a BLF file in manageable pandas DataFrame chunks.
- Parameters:
blf_path – Path to the BLF log.
db – cantools Database with message definitions (possibly prefixed).
chunk_size – Rows per DataFrame chunk.
filter_ids – If set, only decode messages with these arbitration IDs.
- Yields:
DataFrame chunks with decoded signals + timestamp column.
- Raises:
FileNotFoundError – If BLF file not found.
- canml.load_blf(blf_path: str, db: Database | str | List[str], message_ids: Set[int] | None = None, expected_signals: List[str] | None = None, force_uniform_timing: bool = False, interval_seconds: float = 0.01) DataFrame[source]
Load an entire BLF file into a DataFrame, with optional filters and signal injection.
- Parameters:
blf_path – Path to the BLF log.
db – Database instance or DBC path(s).
message_ids – Set of arbitration IDs to include (default all).
expected_signals – List of signal names to ensure exist (fill NaN if missing).
force_uniform_timing – If True, override timestamps with uniform spacing.
interval_seconds – Interval for uniform timing.
- Returns:
A DataFrame with ‘timestamp’ + decoded signal columns.
- Raises:
FileNotFoundError – If files missing.
- canml.load_dbc_files(dbc_paths: str | List[str], prefix_signals: bool = False) Database[source]
Load and merge one or more DBC files into a single Database. Optionally prefix signal names with message names to avoid collisions.
- Parameters:
dbc_paths – Path or list of paths to DBC files.
prefix_signals – If True, automatically rename signals to “<MessageName>_<SignalName>”.
- Returns:
A cantools Database with all definitions loaded.
- Raises:
FileNotFoundError – If any DBC file is missing.
ValueError – If loading fails.
- canml.to_csv(df_or_iter: DataFrame | Iterator[DataFrame], output_path: str, mode: str = 'w', header: bool = True) None[source]
Write DataFrame or iterator of DataFrames to CSV incrementally.
- Parameters:
df_or_iter – DataFrame or iterator of DataFrames.
output_path – Destination CSV file.
mode – Write mode (‘w’ or ‘a’).
header – Write header for first block.
- Raises:
ValueError – If write fails.