Skip to content

Commit 681de92

Browse files
antialiasing and window plotting (no_window) functions added
1 parent 21390d3 commit 681de92

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

ephys/classes/plot/plot_params.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class PlotParams:
3232
show (bool): Whether to show the plot.
3333
return_fig (bool): Whether to return the figure object.
3434
window_mode (str): Mode for handling windows
35-
('use_plot', 'use_trace', 'add_to_trace').
35+
('use_plot', 'use_trace', 'add_to_trace', 'no_window').
3636
theme (str): Theme for the plot ('dark' or 'light').
3737
"""
3838

@@ -60,10 +60,12 @@ def __init__(
6060
self.xlim = kwargs.get("xlim", (0, 0))
6161
self.show = kwargs.get("show", True)
6262
self.return_fig = kwargs.get("return_fig", False)
63+
self.plot_window = kwargs.get("plot_window", True)
6364
self.window_mode = kwargs.get(
6465
"window_mode", "add_to_trace"
6566
) # Default mode for handling windows
6667
self.line_width = kwargs.get("line_width", 1.0)
68+
self.antialiasing = kwargs.get("antialiasing", True)
6769

6870
def apply_theme(self, theme="dark") -> None:
6971
"""Apply the specified theme to the plot parameters.
@@ -120,10 +122,17 @@ def validate(self) -> None:
120122
raise TypeError("show must be a boolean value.")
121123
if not isinstance(self.return_fig, bool):
122124
raise TypeError("return_fig must be a boolean value.")
123-
if self.window_mode not in ["use_plot", "use_trace", "add_to_trace"]:
125+
if not isinstance(self.plot_window, bool):
126+
raise TypeError("plot_window must be a boolean value.")
127+
if self.window_mode not in [
128+
"use_plot",
129+
"use_trace",
130+
"add_to_trace",
131+
"no_window",
132+
]:
124133
raise ValueError(
125134
f"Invalid window_mode: {self.window_mode}. "
126-
"Must be 'use_plot', 'use_trace', or 'add_to_trace'."
135+
"Must be 'use_plot', 'use_trace', 'add_to_trace', or 'no_window'."
127136
)
128137
if not isinstance(self.align_onset, bool):
129138
raise TypeError("align_onset must be a boolean value.")
@@ -135,6 +144,8 @@ def validate(self) -> None:
135144
raise TypeError("line_width must be a number (int or float).")
136145
if not isinstance(self.theme, str) and self.theme not in ["dark", "light"]:
137146
raise TypeError("theme must be a string and either 'dark' or 'light'.")
147+
if not isinstance(self.antialiasing, bool):
148+
raise TypeError("antialiasing must be a boolean value.")
138149

139150
def to_dict(self) -> dict:
140151
"""Convert the plot parameters to a dictionary."""
@@ -153,12 +164,14 @@ def to_dict(self) -> dict:
153164
"bg_color": self.bg_color,
154165
"axis_color": self.axis_color,
155166
"window": self.window,
167+
"plot_window": self.plot_window,
156168
"window_color": self.window_color,
157169
"xlim": self.xlim,
158170
"show": self.show,
159171
"return_fig": self.return_fig,
160172
"window_mode": self.window_mode,
161173
"theme": self.theme,
174+
"antialiasing": self.antialiasing,
162175
}
163176

164177
def __iter__(self):

ephys/classes/plot/plot_trace.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
from ephys.classes.plot.plot_params import PlotParams, _set_axs_color
2323

2424

25-
# switch off antialiasing for pyqtgraph
26-
# pg.setConfigOptions(antialias=False)
27-
28-
2925
class TracePlot:
3026
"""Base class for plotting traces."""
3127

@@ -84,7 +80,11 @@ def handle_windows(self) -> list:
8480
else:
8581
windows_to_display = self.trace.window
8682

87-
# Case 3: Use windows from plot without modifying trace.window
83+
# Case 3: No windows to display
84+
elif self.params.window_mode == "no_window":
85+
windows_to_display = []
86+
87+
# Case 4: Use windows from plot without modifying trace.window
8888
else: # self.params.window_mode == "use_plot"
8989
if isinstance(self.params.window, tuple):
9090
windows_to_display = [self.params.window]
@@ -308,6 +308,8 @@ def plot(
308308
if kwargs:
309309
self.params.update_params(**kwargs)
310310

311+
pg.setConfigOptions(antialias=self.params.antialiasing)
312+
311313
def sync_channels(source_region, channel_items, window_index=0):
312314
# Get region bounds from the source region
313315
min_val, max_val = source_region.getRegion()
@@ -481,7 +483,7 @@ def make_region_callback(region_obj, channel_items, window_index=0):
481483
time_array[0, :],
482484
channel.average.trace,
483485
skipFiniteCheck=True,
484-
antialias=False,
486+
antialias=self.params.antialiasing,
485487
)
486488
channel_tmp.addItem(average_sweep)
487489

@@ -529,7 +531,7 @@ def update_theme(self, theme: str, **kwargs) -> None:
529531
self._set_curve_pen(plot_item.listDataItems())
530532

531533
def sweep_highlight(
532-
self, sweep_index: int | None = None, color="red", alpha=1, width=2
534+
self, sweep_index: int | None = None, color="red", alpha=1, width=1
533535
) -> None:
534536
"""
535537
Highlights a specific sweep in the plot by adjusting the pen properties of the curves.
@@ -562,12 +564,7 @@ def sweep_highlight(
562564
for plot_item in plot_items:
563565
for sweep in plot_item.listDataItems():
564566
if isinstance(sweep, HighlightCurve):
565-
sweep.update_data(
566-
sweep_index=sweep_index,
567-
)
568-
sweep.setPen(
569-
pen=pen_opts,
570-
)
567+
sweep.update_data(sweep_index=sweep_index, pen=pen_opts)
571568
highlight_exists = sweep.sweep_index is not None
572569

573570
if not highlight_exists and isinstance(sweep_index, int):

0 commit comments

Comments
 (0)