perda.analyzer.analyzer#
- class perda.analyzer.analyzer.Analyzer(filepath, ts_offset=0, parsing_errors_limit=100, verbose=1, preprocessing=None)[source]#
Bases:
objectPrimary class for loading and analyzing car log data.
After loading, all variables live in
analyzer.data(aSingleRunData), which supports dictionary-like access returningDataInstanceobjects.Access by name or variable ID#
>>> di = aly.data["pcm.wheelSpeeds.frontRight"] # by cpp_name >>> di = aly.data[42] # by variable ID
Check membership#
>>> "pcm.wheelSpeeds.frontRight" in aly.data # True / False
Read raw arrays#
>>> di.timestamp_np # NDArray[int64] — timestamps in the log's native unit >>> di.value_np # NDArray[float64] — sample values
Arithmetic between variables#
>>> avg_speed = (aly.data["pcm.wheelSpeeds.frontRight"] + aly.data["pcm.wheelSpeeds.frontLeft"]) / 2.0
Trim to a time window (timestamps in the log’s native unit)#
>>> di_trimmed = aly.data["pcm.wheelSpeeds.frontRight"].trim(ts_start=10_000, ts_end=30_000)
Find variables when you don’t know the exact name#
>>> results = aly.search("front wheel speed") # prints + returns list[SearchResult] >>> di = aly.data[results[0].cpp_name]
Enumerate all variables with summary stats#
>>> summaries = aly.variable_summary() # list[VariableSummary], sorted by name >>> [v.cpp_name for v in summaries]
- analyze_frequency(var, expected_frequency_hz=None, gap_threshold_multiplier=2.0, font_config=FontConfig(large=20, medium=14, small=10), layout_config=LayoutConfig(width=1200, height=700, margin={'l': 70, 'r': 50, 't': 90, 'b': 70}, plot_bgcolor='white', title_x=0.5, title_xanchor='center', title_yanchor='top', grid_width_per_col=400, grid_height_per_row=350, grid_horizontal_spacing=0.08, grid_vertical_spacing=0.12, max_display_resolution=50), plot_config=ScatterHistogramPlotConfig(color_scatter='blue', color_line='crimson', color_histogram='blue', histogram_bins=80))[source]#
Analyse the sampling frequency of a variable and return a diagnostic figure.
Prints a summary to stdout and returns a Plotly figure with two subplots: instantaneous frequency over time and an inter-sample interval histogram.
- Parameters:
var (Union[str, int]) – Variable name or ID to look up in the parsed data.
expected_frequency_hz (float | None, optional) – Nominal expected sampling frequency in Hz for error and gap diagnostics. Default is None.
gap_threshold_multiplier (float, optional) – Intervals exceeding this multiple of the expected (or median) interval are flagged as gaps. Default is 2.0.
font_config (FontConfig, optional) – Font sizes for plot elements.
layout_config (LayoutConfig, optional) – Plot dimensions and margins.
plot_config (ScatterHistogramPlotConfig)
- Returns:
Plotly figure with frequency diagnostics.
- Return type:
go.Figure
Examples
>>> fig = aly.analyze_frequency("ams.stack.thermistors.temperature[38]", expected_frequency_hz=100) >>> fig.show()
- diff(server_data, timestamp_tolerance_s=0.002, diff_rtol=0.001, diff_atol=0.001, diff_plot_config=DiffPlotConfig(bucket_size_s=1.0, color_base_extra='blue', color_incom_extra='darkorange', color_value_mismatch='crimson', color_total='gray'), layout_config=LayoutConfig(width=1200, height=700, margin={'l': 70, 'r': 50, 't': 90, 'b': 70}, plot_bgcolor='white', title_x=0.5, title_xanchor='center', title_yanchor='top', grid_width_per_col=400, grid_height_per_row=350, grid_horizontal_spacing=0.08, grid_vertical_spacing=0.12, max_display_resolution=50), font_config=FontConfig(large=20, medium=14, small=10))[source]#
Compute the differences between the current data (assumed to be from RPI) and server data.
- Parameters:
server_data (SingleRunData) – The server data to compare against.
timestamp_tolerance_s (float, optional) – Timestamp tolerance in seconds used to match points between streams. Defaults to 0.002 (2 ms).
diff_rtol (float, optional) – Relative tolerance for value comparison (numpy.isclose).
diff_atol (float, optional) – Absolute tolerance for value comparison (numpy.isclose).
diff_plot_config (DiffPlotConfig, optional)
layout_config (LayoutConfig, optional)
font_config (FontConfig, optional)
- Return type:
Figure
Examples
>>> fig = aly.diff(server_data) >>> fig.show()
- get_accel_times()[source]#
Intelligently detect and extract segments of the log where an acceleration run occurs, then compute acceleration times.
- Returns:
List of acceleration segment results.
- Return type:
list[AccelSegmentResult]
Examples
>>> results = aly.get_accel_times() >>> for r in results: ... print(r)
- plot(var_1, var_2=None, ts_start=None, ts_end=None, title=None, y_label_1=None, y_label_2=None, show_legend=True, font_config=FontConfig(large=20, medium=14, small=10), layout_config=LayoutConfig(width=1200, height=700, margin={'l': 70, 'r': 50, 't': 90, 'b': 70}, plot_bgcolor='white', title_x=0.5, title_xanchor='center', title_yanchor='top', grid_width_per_col=400, grid_height_per_row=350, grid_horizontal_spacing=0.08, grid_vertical_spacing=0.12, max_display_resolution=50), vline_config=VLineConfig(color='gray', width=2, dash='dash', opacity=0.7))[source]#
Display variables from the parsed data on an interactive Plotly plot.
Concat boundaries (if any) are automatically shown as vertical lines.
- Parameters:
var_1 (Union[str, int, DataInstance, List[Union[str, int, DataInstance]]]) – Variable(s) to plot on the left y-axis. Can be variable name(s), variable ID(s), or DataInstance(s)
var_2 (Union[str, int, DataInstance, List[Union[str, int, DataInstance]]] | None, optional) – Optional variable(s) to plot on the right y-axis. Can be variable name(s), variable ID(s), or DataInstance(s).
ts_start (float | None, optional) – Start of the time window in seconds. Data points before this time are excluded. Default is None (no lower bound).
ts_end (float | None, optional) – End of the time window in seconds. Data points after this time are excluded. Default is None (no upper bound).
title (str | None, optional)
y_label_1 (str | None, optional) – Label for left y-axis (or only y-axis if no right input).
y_label_2 (str | None, optional) – Label for right y-axis.
show_legend (bool, optional) – Whether to show plot legends. Default is True
font_config (FontConfig, optional) – Font configuration for plot elements.
layout_config (LayoutConfig, optional) – Layout configuration for plot dimensions.
vline_config (VLineConfig, optional) – Visual configuration for concat boundary lines.
- Return type:
Figure
Examples
>>> fig = aly.plot("pcm.wheelSpeeds.frontRight") >>> fig = aly.plot(["pcm.wheelSpeeds.frontRight", "pcm.wheelSpeeds.frontLeft"], title="Front Wheel Speeds") >>> fig = aly.plot("pcm.moc.motor.requestedTorque", "pcm.wheelSpeeds.frontRight", ts_start=10.0, ts_end=30.0) >>> # Plot a derived DataInstance (e.g. average of two signals) >>> avg_speed = (aly.data["pcm.wheelSpeeds.frontRight"] + aly.data["pcm.wheelSpeeds.frontLeft"]) / 2.0 >>> fig = aly.plot(avg_speed) >>> fig.show()
- search(query, top_n=10)[source]#
Natural language search for available variables in the parsed data.
Prints matching results to stdout and returns them for programmatic use.
- Parameters:
query (str) – Free-text search query (e.g. “front wheel speed”).
top_n (int) – Maximum number of results to return and display (default 10).
- Returns:
Top matches in descending relevance order (at most
top_nentries). Each entry hasrank,score,var_id,cpp_name, anddescript.- Return type:
list[SearchResult]
Examples
>>> results = aly.search("front wheel speed") >>> results = aly.search("front wheel speed", top_n=5) >>> names = [r.cpp_name for r in results]
- subplots(rows, title=None, row_y_labels=None, ts_start=None, ts_end=None, show_legend=True, layout_config=LayoutConfig(width=1200, height=700, margin={'l': 70, 'r': 50, 't': 90, 'b': 70}, plot_bgcolor='white', title_x=0.5, title_xanchor='center', title_yanchor='top', grid_width_per_col=400, grid_height_per_row=350, grid_horizontal_spacing=0.08, grid_vertical_spacing=0.12, max_display_resolution=50), font_config=FontConfig(large=20, medium=14, small=10))[source]#
Plot multiple variables as stacked subplots on a shared time axis.
Each entry in
rowsbecomes one subplot row. Pass a list of variables for a row to overlay multiple signals on the same panel, or a single variable for a dedicated panel.- Parameters:
rows (List[str | int | DataInstance | List[str | int | DataInstance]]) – One entry per subplot row (top to bottom). Each entry may be a single variable (name, ID, or DataInstance) or a list of variables to overlay on that row.
title (str | None, optional) – Figure-level title. Default is None.
row_y_labels (List[str | None] | None, optional) – Y-axis label for each row.
Noneentries fall back to the DataInstance labels. Must match the length ofrowswhen provided. Default is None.ts_start (float | None, optional) – Start of the time window in seconds. Data before this time is excluded from all rows. Default is None (no lower bound).
ts_end (float | None, optional) – End of the time window in seconds. Data after this time is excluded from all rows. Default is None (no upper bound).
show_legend (bool, optional) – Whether to show the figure legend. Default is True.
layout_config (LayoutConfig, optional) – Figure dimensions and spacing.
font_config (FontConfig, optional) – Font sizes for plot elements.
- Return type:
go.Figure
Examples
>>> fig = aly.subplots(["pcm.wheelSpeeds.frontRight", "pcm.moc.motor.requestedTorque"]) >>> fig = aly.subplots( ... rows=[ ... ["pcm.wheelSpeeds.frontRight", "pcm.wheelSpeeds.frontLeft"], ... "pcm.moc.motor.requestedTorque", ... ], ... title="Run Overview", ... row_y_labels=["Wheel Speed (mph)", "Torque (Nm)"], ... ts_start=5.0, ... ts_end=30.0, ... ) >>> fig.show()
- Parameters:
filepath (str)
ts_offset (int)
parsing_errors_limit (int)
verbose (int)
preprocessing (list[Callable[[SingleRunData], SingleRunData]] | None)