canml Module

canml icon

This is the top‐level package for canml.

class canml.CanmlConfig(chunk_size: int = 10000, progress_bar: bool = True, dtype_map: Dict[str, Any] | None = None, sort_timestamps: bool = False, force_uniform_timing: bool = False, interval_seconds: float = 0.01, interpolate_missing: bool = False)[source]

Bases: object

Configuration for BLF processing.

chunk_size

Number of messages per DataFrame chunk.

Type:

int

progress_bar

Show tqdm progress bar if True.

Type:

bool

dtype_map

Mapping from signal name to pandas dtype.

Type:

Dict[str, Any] | None

sort_timestamps

Sort final DataFrame by timestamp.

Type:

bool

force_uniform_timing

Override timestamps with uniform spacing.

Type:

bool

interval_seconds

Interval between timestamps for uniform timing.

Type:

float

interpolate_missing

Interpolate missing signal values if True.

Type:

bool

chunk_size: int = 10000
dtype_map: Dict[str, Any] | None = None
force_uniform_timing: bool = False
interpolate_missing: bool = False
interval_seconds: float = 0.01
progress_bar: bool = True
sort_timestamps: bool = False
canml.iter_blf_chunks(blf_path: str, db: Database, config: CanmlConfig, filter_ids: Set[int] | None = None, filter_signals: Iterable[Any] | None = None) Iterator[DataFrame][source]

Stream-decode a BLF file into DataFrame chunks.

Parameters:
  • blf_path – Path to .blf log.

  • db – Loaded CantoolsDatabase.

  • config – CanmlConfig for chunk_size & progress_bar.

  • filter_ids – Optional set of arbitration IDs to include.

  • filter_signals – Optional iterable of signal identifiers to include.

Yields:

pandas.DataFrame chunks containing decoded signals + ‘timestamp’.

canml.load_blf(blf_path: str, db: Database | str | List[str], config: CanmlConfig | None = None, message_ids: Set[int] | None = None, expected_signals: Iterable[Any] | None = None) DataFrame[source]

Load a BLF log into a pandas DataFrame with decoding, filtering, timing normalization, missing-signal injection, and metadata.

Parameters:
  • blf_path – Path to .blf log file.

  • db – CantoolsDatabase instance or path(s) to DBC file(s).

  • config – CanmlConfig instance (optional).

  • message_ids – Set of arbitration IDs to include (None = all).

  • expected_signals – Iterable of signals to include (None = all).

Returns:

pandas.DataFrame with columns [‘timestamp’, …signals].

canml.load_dbc_files(dbc_paths: str | List[str], prefix_signals: bool = False) Database[source]

Public API: Load and merge DBC file(s) into a CantoolsDatabase.

Parameters:
  • dbc_paths – Path or list of paths to .dbc files.

  • prefix_signals – If True, prefix each signal name with its message name.

Returns:

A CantoolsDatabase containing all loaded definitions.

canml.to_csv(df_or_iter: DataFrame | Iterable[DataFrame], output_path: str, mode: str = 'w', header: bool = True, pandas_kwargs: Dict[str, Any] | None = None, columns: List[str] | None = None, metadata_path: str | None = None) None[source]

Write DataFrame or iterable of DataFrames to CSV, exporting metadata JSON.

Parameters:
  • df_or_iter – Single DataFrame or iterable of chunks.

  • output_path – CSV file path.

  • mode – ‘w’ or ‘a’.

  • header – Write header row if True.

  • pandas_kwargs – Extra pandas.to_csv kwargs.

  • columns – Optional list of columns (subset/order).

  • metadata_path – Path to side-car JSON with df.attrs[“signal_attributes”].

canml.to_parquet(df: DataFrame, output_path: str, compression: str = 'snappy', pandas_kwargs: Dict[str, Any] | None = None, metadata_path: str | None = None) None[source]

Write DataFrame to Parquet with optional metadata export.

Parameters:
  • df – DataFrame to write.

  • output_path – Path to .parquet file.

  • compression – Parquet codec (snappy, gzip, zstd).

  • pandas_kwargs – Extra pandas.to_parquet kwargs.

  • metadata_path – Path to side-car JSON with df.attrs[“signal_attributes”].