-
Notifications
You must be signed in to change notification settings - Fork 0
Multilog Analysis (Logx) #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jeffrey-Moon
wants to merge
6
commits into
main
Choose a base branch
from
multilog_analysis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7dcefd4
Plotting Max Number of Points Downsampling
Jeffrey-Moon 915fc74
Optimized Hybrid Search Using all-MiniLM-L6-V2
Jeffrey-Moon 9bacda3
Multilog Analysis and CSV Loading Optimization
Jeffrey-Moon 6b88511
Downsampling Fix
Jeffrey-Moon 8e96c66
Added Tests for New Features
Jeffrey-Moon ecedc94
Formatting Fix
Jeffrey-Moon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| # Submodule re-exports | ||
| from .analyzer import * | ||
| from .analyzer_factory import * | ||
| from .concat_helpers import concat | ||
| from .comparison import plot_comparison, compare_summary | ||
| from .csv import * | ||
| from .run_collection import RunCollection, RunMetadata |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| import os | ||
| from typing import Any, Dict, List | ||
| import numpy as np | ||
| import plotly.graph_objects as go | ||
|
|
||
| from ..plotting.plotting_constants import ( | ||
| DEFAULT_FONT_CONFIG, | ||
| DEFAULT_LAYOUT_CONFIG, | ||
| ) | ||
| from ..units import _to_seconds | ||
|
|
||
|
|
||
| def plot_comparison( | ||
| analyzers: List[Any], cpp_name: str, max_points: int | None = None | ||
| ) -> go.Figure: | ||
| """Compare and overlay a variable from multiple runs on a single Plotly figure. | ||
|
|
||
| Aligns each run's timestamps to start at relative seconds (t = 0). | ||
|
|
||
| Parameters | ||
| ---------- | ||
| analyzers : List[Analyzer] | ||
| List of Analyzer instances to compare. | ||
| cpp_name : str | ||
| C++ variable name to plot and overlay. | ||
| max_points : int | None, optional | ||
| Maximum number of data points to plot per run (enables zero-copy step downsampling). Default is None (full fidelity). | ||
|
|
||
| Returns | ||
| ------- | ||
| go.Figure | ||
| Plotly Figure with overlaid traces from all matching runs. | ||
| """ | ||
| fig = go.Figure() | ||
|
|
||
| for aly in analyzers: | ||
| if cpp_name not in aly.data: | ||
| continue | ||
| di = aly.data[cpp_name] | ||
| if len(di) == 0: | ||
| continue | ||
|
|
||
| # Shift timestamps relative to start time and convert to seconds | ||
| raw_start = aly.data.data_start_time | ||
| rel_timestamps_raw = di.timestamp_np - raw_start | ||
|
|
||
| # Downsample coordinates if data points exceed the limit | ||
| n_points = len(di) | ||
| if max_points is not None and n_points > max_points and max_points > 0: | ||
| step = (n_points + max_points - 1) // max_points | ||
| timestamps_s = _to_seconds(rel_timestamps_raw[::step], aly.data.timestamp_unit) | ||
| values_np = di.value_np[::step] | ||
| else: | ||
| timestamps_s = _to_seconds(rel_timestamps_raw, aly.data.timestamp_unit) | ||
| values_np = di.value_np | ||
|
|
||
| # Get file name for legend label | ||
| file_path = getattr(aly, "file_path", None) or getattr(aly, "filename", None) or "Run" | ||
| run_label = os.path.basename(str(file_path)) | ||
|
|
||
| fig.add_trace( | ||
| go.Scattergl( | ||
| x=timestamps_s, | ||
| y=values_np, | ||
| mode="lines", | ||
| name=f"{run_label} ({di.label})", | ||
| ) | ||
| ) | ||
|
|
||
| fig.update_layout( | ||
| title=dict( | ||
| text=f"Multi-Log Comparison: {cpp_name}", | ||
| font=dict(size=DEFAULT_FONT_CONFIG.large) | ||
| ), | ||
| xaxis_title=dict( | ||
| text="Time (seconds from start)", | ||
| font=dict(size=DEFAULT_FONT_CONFIG.medium) | ||
| ), | ||
| yaxis_title=dict( | ||
| text=cpp_name, | ||
| font=dict(size=DEFAULT_FONT_CONFIG.medium) | ||
| ), | ||
| template="plotly_dark", | ||
| width=DEFAULT_LAYOUT_CONFIG.width, | ||
| height=DEFAULT_LAYOUT_CONFIG.height, | ||
| margin=DEFAULT_LAYOUT_CONFIG.margin, | ||
| ) | ||
| return fig | ||
|
|
||
|
|
||
| def compare_summary(analyzers: List[Any], cpp_name: str) -> Dict[str, Dict[str, float]]: | ||
| """Compare basic statistics of a variable across multiple logs. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| analyzers : List[Analyzer] | ||
| List of Analyzer instances to compare. | ||
| cpp_name : str | ||
| C++ variable name to summarize. | ||
|
|
||
| Returns | ||
| ------- | ||
| Dict[str, Dict[str, float]] | ||
| A dictionary mapping run filenames to statistical descriptors: | ||
| {"run_filename.csv": {"min": x, "max": y, "mean": z, "std": w, "len": n}} | ||
| """ | ||
| comparison = {} | ||
| for aly in analyzers: | ||
| if cpp_name not in aly.data: | ||
| continue | ||
| di = aly.data[cpp_name] | ||
| if len(di) == 0: | ||
| continue | ||
|
|
||
| vals = di.value_np | ||
| file_path = getattr(aly, "file_path", None) or getattr(aly, "filename", None) or "Run" | ||
| run_label = os.path.basename(str(file_path)) | ||
|
|
||
| comparison[run_label] = { | ||
| "min": float(np.min(vals)), | ||
| "max": float(np.max(vals)), | ||
| "mean": float(np.mean(vals)), | ||
| "std": float(np.std(vals)), | ||
| "len": int(len(vals)), | ||
| } | ||
| return comparison |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this function need to live in this file?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was originally in csv.py but chukka said to just move it to init unless I misunderstood him. I think once we have more auxiliary functions we can create a new file