Jupyter Notebook Examples¶
biosigIO can be used effectively in Jupyter Notebooks for interactive data analysis and visualization. This page provides an overview of working with biosigIO in Jupyter environments.
Available Example Notebooks¶
The biosigIO repository includes several example Jupyter notebooks that demonstrate different aspects of working with EMG data:
- Trigno Example Notebook: Working with Delsys Trigno data
-
Location:
examples/trigno_example.ipynb -
MATLAB Example Notebook: Working with MATLAB-exported data
- Location:
examples/matlab_example.ipynb
Running the Example Notebooks¶
To run the example notebooks:
-
Install biosigIO in development mode:
-
Start Jupyter (no separate install needed):
-
Navigate to the
examplesdirectory and open one of the notebooks.
Key Features for Jupyter Notebooks¶
When working with biosigIO in Jupyter notebooks, you can take advantage of these features:
Interactive Plotting¶
from biosigio import Recording
import matplotlib.pyplot as plt
%matplotlib inline # For displaying plots in the notebook
# Load EMG data
rec = Recording.from_file('data.csv', importer='trigno')
# Plot signals with customized appearance (plot_signals manages its own figure)
rec.plot_signals(
channels=['EMG1', 'EMG2'],
time_range=(0, 5),
title='EMG Signals',
grid=True
)
Data Exploration¶
Jupyter notebooks are excellent for interactively exploring your EMG data:
# Load data
rec = Recording.from_file('data.otb+', importer='otb')
# Display channel information
channel_types = rec.get_channel_types()
for ch_type in channel_types:
channels = rec.get_channels_by_type(ch_type)
print(f"{ch_type} channels: {len(channels)}")
# Show details of the first channel
if channels:
ch_name = channels[0]
ch_info = rec.channels[ch_name]
print(f" Sample channel: {ch_name}")
for key, value in ch_info.items():
print(f" {key}: {value}")
Creating Interactive Widgets¶
You can use ipywidgets to create interactive controls for exploring your data:
import ipywidgets as widgets
from IPython.display import display
# Load data
rec = Recording.from_file('data.set', importer='eeglab')
# Get all channels
all_channels = list(rec.channels.keys())
# Create widgets
channel_dropdown = widgets.Dropdown(
options=all_channels,
description='Channel:',
disabled=False,
)
time_slider = widgets.FloatRangeSlider(
value=[0, 5],
min=0,
max=rec.get_duration(),
step=1,
description='Time (s):',
disabled=False,
continuous_update=False,
readout=True,
readout_format='.1f',
)
# Define update function
def update_plot(channel, time_range):
plt.figure(figsize=(12, 6))
rec.plot_signals(
channels=[channel],
time_range=time_range,
title=f'Channel: {channel}, Time: {time_range[0]}-{time_range[1]}s',
grid=True
)
plt.show()
# Create interactive output
out = widgets.interactive_output(
update_plot,
{'channel': channel_dropdown, 'time_range': time_slider}
)
# Display widgets and output
display(widgets.HBox([channel_dropdown, time_slider]), out)
Exporting Figures¶
You can easily export high-quality figures for publications:
# Create a figure
plt.figure(figsize=(10, 6), dpi=300) # High DPI for publication quality
rec.plot_signals(
channels=rec.get_channels_by_type('EMG')[:4], # First 4 EMG channels
time_range=(10, 15),
title='EMG Signals During Movement',
grid=True,
show=False, # keep the figure open so savefig below captures it
)
plt.tight_layout()
# Save the figure in various formats
plt.savefig('emg_plot.png', dpi=300) # PNG for presentations
plt.savefig('emg_plot.pdf') # PDF for publications
plt.savefig('emg_plot.svg') # SVG for editing
plt.show()
Tips for Jupyter Notebooks¶
-
Loading data:
Recording.from_fileinfers the importer from the file extension and returns aRecording. You can also call an importer directly; importers take no constructor arguments and theirload(filepath)returns aRecording(not a tuple): -
Progress tracking: For long operations, use
tqdmfor progress bars: -
Table display: Format channel information as a dataframe for better visualization:
These examples show how to leverage Jupyter notebooks for interactive exploration and analysis of EMG data with biosigIO.