Added function raw_traces_plot
This commit is contained in:
@ -22,6 +22,10 @@ from dask import delayed
|
||||
|
||||
import time
|
||||
|
||||
import ipywidgets as widgets
|
||||
from IPython.display import display, clear_output
|
||||
|
||||
|
||||
|
||||
# %% Functions for listing files with specific string in name
|
||||
|
||||
@ -2088,3 +2092,58 @@ def resample_to_dt(dir_path_pbp, dt=60, path_parquet='', save_final_data=False):
|
||||
append=False)
|
||||
|
||||
|
||||
#%% Widget to plot raw traces
|
||||
|
||||
|
||||
def raw_traces_plot(ch0_plot=[], ch1_plot=[],
|
||||
add_str_title='',
|
||||
xmin=None, xmax=None,
|
||||
ddf_processed=False, verbose=False,
|
||||
):
|
||||
current_event_index = 1
|
||||
|
||||
def update_plot(event_index):
|
||||
fig, ax1 = plt.subplots(figsize=(5, 3), layout='constrained')
|
||||
|
||||
if verbose and ddf_processed.any().any():
|
||||
ax1.text(0.75, 0.4, 'ch0_flag_000: '+str(ddf_processed.iloc[event_index]['ch0_flag_000']), fontsize=8, transform=ax1.transAxes)
|
||||
|
||||
|
||||
ax1.set_title(add_str_title+' , idx: '+str(event_index)+'\n'+str(ch0_plot.iloc[event_index].name))
|
||||
ax1t = ax1.twinx()
|
||||
|
||||
if len(ch0_plot)!=0:
|
||||
ax1.plot(ch0_plot.iloc[event_index], label='ch0', c='C0', ls='-')
|
||||
if len(ch1_plot)!=0:
|
||||
ax1t.plot(ch1_plot.iloc[event_index], label='ch1', c='C1', ls='-')
|
||||
|
||||
ax1.set_ylabel('Scattering', color='tab:blue')
|
||||
ax1.tick_params(axis='y', labelcolor='tab:blue')
|
||||
ax1.legend(loc=1)
|
||||
ax1t.legend(loc=4)
|
||||
|
||||
if xmin and xmax is not None:
|
||||
ax1.set_xlim(xmin, xmax)
|
||||
|
||||
plt.show()
|
||||
|
||||
def handle_forward_button_click(b):
|
||||
nonlocal current_event_index
|
||||
current_event_index = min(current_event_index + 1, len(ch0_plot) - 1)
|
||||
event_slider.value = current_event_index
|
||||
|
||||
def handle_backward_button_click(b):
|
||||
nonlocal current_event_index
|
||||
current_event_index = max(current_event_index - 1, 0)
|
||||
event_slider.value = current_event_index
|
||||
|
||||
event_slider = widgets.IntSlider(min=0, max=len(ch0_plot) - 1, step=1, value=current_event_index, description='Event:')
|
||||
forward_button = widgets.Button(description='Forward')
|
||||
backward_button = widgets.Button(description='Backward')
|
||||
|
||||
forward_button.on_click(handle_forward_button_click)
|
||||
backward_button.on_click(handle_backward_button_click)
|
||||
|
||||
display(widgets.HBox([backward_button, forward_button]))
|
||||
interactive_plot = widgets.interactive(update_plot, event_index=event_slider)
|
||||
display(interactive_plot)
|
Reference in New Issue
Block a user