diff options
| author | Sam Scholten | 2025-10-31 07:39:10 +1000 |
|---|---|---|
| committer | Sam Scholten | 2025-10-31 07:39:10 +1000 |
| commit | 016f0c4b1815555965100eb5a58a9e81197d8a34 (patch) | |
| tree | c035084b06ad8e3142373b9689f5932e3c21e9ea | |
| parent | fb256f5add760d891835c89ac26387cc4e2bac12 (diff) | |
| download | scopekit-main.tar.gz scopekit-main.zip | |
- Only pre-decimate elements that will be shown in envelope mode (MODE_ENVELOPE or MODE_BOTH)
- MODE_DETAIL-only elements skip pre-decimation to improve performance with large datasets
- In _show_custom_elements, only use envelope decimation if element's display_mode includes MODE_ENVELOPE
- Maintains full functionality while significantly reducing computational overhead
Version 1.0.7
| -rw-r--r-- | pyproject.toml | 2 | ||||
| -rw-r--r-- | src/scopekit/plot.py | 80 |
2 files changed, 50 insertions, 32 deletions
diff --git a/pyproject.toml b/pyproject.toml index 0e83725..74b0acf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "scopekit" -version = "1.0.6" +version = "1.0.7" description = "General-purpose oscilloscope plotting components." authors = [{ name = "Sam Scholten", email = "s.scholten@uq.edu.au" }] requires-python = ">=3.8" diff --git a/src/scopekit/plot.py b/src/scopekit/plot.py index 0b96722..17c7ec5 100644 --- a/src/scopekit/plot.py +++ b/src/scopekit/plot.py @@ -283,14 +283,16 @@ class OscilloscopePlot: # and ensure uniqueness across custom lines. line_id = -(len(self._lines[trace_idx]) + 1) # Negative, unique per trace - # Pre-decimate this custom line's data for envelope view - self.decimator.pre_decimate_data( - data_id=line_id, - t=t_array, - x=data_array, - max_points=self.max_plot_points, - envelope_window_samples=None, # Envelope window calculated automatically - ) + # Only pre-decimate if this line will be used in envelope mode + # If it's MODE_DETAIL only, we don't need pre-decimation for envelope view + if display_mode & self.MODE_ENVELOPE: + self.decimator.pre_decimate_data( + data_id=line_id, + t=t_array, + x=data_array, + max_points=self.max_plot_points, + envelope_window_samples=None, # Envelope window calculated automatically + ) # Store line definition with raw data and its assigned ID line_def = { @@ -377,15 +379,16 @@ class OscilloscopePlot: len(self._ribbons[trace_idx]) + 1001 ) # Negative, unique per trace, offset from lines - # Pre-decimate this custom ribbon's center data for envelope view - # We only pre-decimate the center, as width is applied later - self.decimator.pre_decimate_data( - data_id=ribbon_id, - t=np.asarray(t, dtype=np.float32), - x=center_data, - max_points=self.max_plot_points, - envelope_window_samples=None, # Envelope window calculated automatically - ) + # Only pre-decimate if this ribbon will be used in envelope mode + # If it's MODE_DETAIL only, we don't need pre-decimation for envelope view + if display_mode & self.MODE_ENVELOPE: + self.decimator.pre_decimate_data( + data_id=ribbon_id, + t=np.asarray(t, dtype=np.float32), + x=center_data, + max_points=self.max_plot_points, + envelope_window_samples=None, # Envelope window calculated automatically + ) # Store ribbon definition ribbon_def = { @@ -478,13 +481,16 @@ class OscilloscopePlot: + np.asarray(max_data, dtype=np.float32) ) / 2 - self.decimator.pre_decimate_data( - data_id=envelope_id, - t=t_raw, - x=avg_data, # Pass average for decimation - max_points=self.max_plot_points, - envelope_window_samples=None, # Envelope window calculated automatically - ) + # Only pre-decimate if this envelope will be used in envelope mode + # If it's MODE_DETAIL only, we don't need pre-decimation for envelope view + if display_mode & self.MODE_ENVELOPE: + self.decimator.pre_decimate_data( + data_id=envelope_id, + t=t_raw, + x=avg_data, # Pass average for decimation + max_points=self.max_plot_points, + envelope_window_samples=None, # Envelope window calculated automatically + ) # Store envelope definition envelope_def = { @@ -695,12 +701,17 @@ class OscilloscopePlot: # Dynamically decimate the line data for the current view # Use the same max_plot_points as the main signal for consistency # For custom lines, we want mean decimation if in envelope mode, not min/max envelope + # But only use envelope mode if this line is displayed in envelope mode + use_envelope_for_line = ( + current_mode == self.MODE_ENVELOPE + and (line_def["display_mode"] & self.MODE_ENVELOPE) + ) t_line_raw, line_data, _, _ = self.decimator.decimate_for_view( line_def["t_raw"], line_def["data_raw"], current_xlim_raw, # Decimate to current view self.max_plot_points, - use_envelope=(current_mode == self.MODE_ENVELOPE), + use_envelope=use_envelope_for_line, data_id=line_def[ "id" ], # Pass the custom line's ID for pre-decimated data lookup @@ -740,6 +751,11 @@ class OscilloscopePlot: # Ribbons are always plotted as fills, so we need to decimate their center and width # We'll treat the center_data as the 'signal' for decimation purposes + # But only use envelope mode if this ribbon is displayed in envelope mode + use_envelope_for_ribbon = ( + current_mode == self.MODE_ENVELOPE + and (ribbon_def["display_mode"] & self.MODE_ENVELOPE) + ) ( t_ribbon_raw, center_data_decimated, @@ -750,9 +766,7 @@ class OscilloscopePlot: ribbon_def["center_data_raw"], current_xlim_raw, self.max_plot_points, - use_envelope=( - current_mode == self.MODE_ENVELOPE - ), # Use envelope for ribbons if in envelope mode + use_envelope=use_envelope_for_ribbon, data_id=ribbon_def[ "id" ], # Pass the custom ribbon's ID for pre-decimated data lookup @@ -815,7 +829,11 @@ class OscilloscopePlot: # For custom envelopes, we need to handle min/max data specially # We'll decimate the min and max data separately using the envelope's stored data - # Since we stored min/max in the pre-decimated data, we can retrieve them + # But only use envelope mode if this envelope is displayed in envelope mode + use_envelope_for_custom_envelope = ( + current_mode == self.MODE_ENVELOPE + and (envelope_def["display_mode"] & self.MODE_ENVELOPE) + ) # Get the pre-decimated envelope data for this custom envelope if envelope_def["id"] in self.decimator._pre_decimated_envelopes: @@ -833,7 +851,7 @@ class OscilloscopePlot: / 2, # Average for decimation current_xlim_raw, self.max_plot_points, - use_envelope=True, # Always treat custom envelopes as envelopes + use_envelope=use_envelope_for_custom_envelope, data_id=envelope_def[ "id" ], # Pass the custom envelope's ID for pre-decimated data lookup @@ -858,7 +876,7 @@ class OscilloscopePlot: / 2, current_xlim_raw, self.max_plot_points, - use_envelope=True, + use_envelope=use_envelope_for_custom_envelope, data_id=None, # No pre-decimated data available return_envelope_min_max=True, envelope_window_samples=None, # Envelope window calculated automatically |
