Reference Guide

trial.TrialInfo

class spike2py.trial.TrialInfo(file: pathlib.Path = None, channels: List[str] = None, name: str = None, subject_id: str = None, path_save_figures: pathlib.Path = None, path_save_trial: pathlib.Path = None)[source]

Information about trial

See spike2py.trial.Trial parameters for details.

trial.Trial

class spike2py.trial.Trial(trial_info: spike2py.trial.TrialInfo)[source]

Class for experimental trial recorded using Spike2

Parameters:trial_info (NamedTuple) –
file : pathlib.Path, str
Absolute path to data file. Only .mat files supported
channels : List[str]
List of channel names, as they appeared in the original .smr file Example: [‘biceps’, ‘triceps’, ‘torque’] If not included, all channels will be processed
name : str
Descriptive name for trial; defaults to filename
subject_id : str
Subject’s study identifier
path_save_figures : pathlib.Path
Path where trial and channel figures are to be saved Defaults to new ‘figures’ folder where .mat was retrieved
path_save_trial : pathlib.Path
Path where trial data to be saved Defaults to new ‘data’ folder where .mat was retrieved
trial_info

Same as parameter

Type:NamedTuple
channels

Pairs of channel names and channel types. For example: [(‘Torque’, ‘waveform’), (‘Trigger’, ‘event’)]

Type:List[Tuple[str, str]]
<Channels>

Each channel appears with its name as an attribute. For example: trial1.Torque

Type:channels.Channel
Raises:ValueError – If parameter info.file is not a valid full path to a data file
save()[source]

Save trial

Trial will be saved (pickled) to info.path_save_trial as info.name + ‘.pkl’

trial.load

spike2py.trial.load(file: Union[pathlib.Path, str]) → spike2py.trial.Trial[source]

Load saved (pickled) trial

Parameters:file (pathlib.Path, str) – Full path and file name to pickled file. For example: ‘/home/tammy/Desktop/trial1.pkl`
Returns:Instance of Trial class that was previously saved
Return type:Trial

channels.ChannelInfo

class spike2py.channels.ChannelInfo[source]

Information about channel

See spike2py.channels.Channel parameters for details.

channels.Channel

class spike2py.channels.Channel(channel_info: spike2py.channels.ChannelInfo, times: numpy.ndarray)[source]

Base class for all channel types

Parameters
channel_info
name
Name of channel (.e.g ‘left biceps’)
units
Units of recorded signal (e.g., ‘Volts’ or ‘Nm’)
sampling_frequency
In Hertz (e.g. 2048)
path
Defaults to path where data initially retrieved
trialname
Defaults to name of data file
subject_id
str indentifier
times
Sample times in seconds

channels.Event

class spike2py.channels.Event(name: str, data_dict: Dict[str, Union[numpy.ndarray, str, pathlib.Path]])[source]

Event channel class

Inherits from Channel

Parameters:
  • name – Name of Event channel
  • data_dict
    • [‘path_save_figures’]: Path - Directory where channel figure saved
    • [‘trial_name’]: str - Name of trial where Event was recorded
    • [‘subject_id’]: str - Identifier
    • [‘times’]: np.ndarray - Event times in seconds
plot(save: Literal[True, False] = False) → None[source]

Save Event channel figure

Parameters:save – Set to True to save Event figure to path_save_figures

channels.Keyboard

class spike2py.channels.Keyboard(name: str, data_dict: Dict[str, Union[List[str], numpy.ndarray, str, pathlib.Path]])[source]

Keyboard channel class

Inherits from Channel

Parameters:
  • name – Name of Keyboard channel; default is ‘keyboard’
  • data_dict
    • [‘path_save_figures’]: Path - Directory where channel figure saved
    • [‘trial_name’]: str - Name of trial where Keyboard was recorded
    • [‘subject_id’]: str - Identifier
    • [‘times’]: np.ndarray - Event times in seconds
    • [‘codes’]: np.ndarray of str associated with keyboard events
plot(save: Literal[True, False] = False) → None[source]

Save Keyboard channel figure

Parameters:save – Set to True to save Keyboard figure to path_save_figures

channels.Waveform

class spike2py.channels.Waveform(name: str, data_dict: Dict[str, Union[int, numpy.ndarray, str, pathlib.Path]])[source]

Waveform channel class

Inherits from Channel and sig_proc.SignalProcessing

Parameters:
  • name – Name of Waveform channel
  • data_dict
    • [‘path_save_figures’]: Path - Directory where channel figure saved
    • [‘trial_name’]: str - Name of trial where Waveform was recorded
    • [‘subject_id’]: str - Identifier
    • [‘times’]: np.ndarray - Waveform times in seconds
    • [‘values’]: np.ndarray - Waveform float values
    • [‘units’]: str - Measurement units (e.g. ‘Volts’)
    • [‘sampling_frequency’]: int - Sampling frequency of Wavemark
plot(save: Literal[True, False] = None) → None[source]

Save Waveform channel figure

Parameters:save – Set to True to save Waveform figure to path_save_figures

channels.Wavemark

class spike2py.channels.Wavemark(name: str, data_dict: Dict[str, Union[int, List[int], str, numpy.ndarray, pathlib.Path]])[source]

Wavemark channel class

Inherits from Channel

Parameters:
  • name – Name of Wavemark channel
  • data_dict
    • [‘path_save_figures’]: Path - Directory where channel figure saved
    • [‘trial_name’]: str - Name of trial where Wavemark was recorded
    • [‘subject_id’]: str - Identifier
    • [‘times’]: np.ndarray - Wavemark times in seconds
    • [‘values’]: np.ndarray - Waveform float values
    • [‘action_potentials’]: list of lists - Each list is a Wavemark
    • [‘units’]: str - Measurement units (e.g. ‘Volts’)
    • [‘sampling_frequency’]: int - Sampling frequency of Wavemark
plot(save: Literal[True, False] = None)[source]

Save Waveform channel figure

Parameters:save – Set to True to save Wavemark figure to path_save_figures

sig_proc.SignalProcessing

class spike2py.sig_proc.SignalProcessing[source]

Mixin class that adds signal processing methods

bandpass(cutoff: List[float], order: int = 4)[source]

Apply dual-pass Butterworth bandpass filter to values

bandstop(cutoff: List[float], order: int = 4)[source]

Apply dual-pass Butterworth bandstop filter to values

calibrate(slope: float, offset: float = None)[source]

Calibrate values using linear formula y=slope*x+offset

highpass(cutoff: Union[float, int], order: int = 4)[source]

Apply dual-pass Butterworth highpass filter to values

interp_new_fs(new_sampling_frequency: int)[source]

Interpolate values to a new sampling frequency

interp_new_times(new_times: List[float])[source]

Interpolate values to a new time axis

Parameters:new_times – New time axis for interpolated data. Cannot be longer in duration than current time axis, times. If includes only a portion of the current time axis, only values associated with that portion of the time axis will be interpolated.
linear_detrend()[source]

Remove linear trend from values

lowpass(cutoff: Union[float, int], order: int = 4)[source]

Apply dual-pass Butterworth lowpass filter to values

norm_percent_value(value: float)[source]

Normalise values to a percentage of value

norm_percentage()[source]

Normalise values to be between 0-100%

norm_proportion()[source]

Normalise values to be between 0-1

rect()[source]

Rectify values

remove_mean(first_n_samples: int = None)[source]

Subtract mean of first n samples (default is all samples)

remove_value(value: float)[source]

Subtracts value from values

plot.plot_channel

spike2py.plot.plot_channel(spike2py_channel: Union[channels.Event, channels.Keyboard, channels.Waveform, channels.Wavemark], save: Literal[True, False]) → None[source]

Plot individual channels.

Parameters:
  • spike2py_channel – Instance of spike2py.channels.<ch> where possible ch are Event, Keyboard, Wavemark and Waveform
  • save – Whether or not to save the generated figure.
Returns:

Return type:

None

plot.plot_trial

spike2py.plot.plot_trial(spike2py_trial: spike2py.trial.Trial, save: Literal[True, False]) → None[source]

read.read

spike2py.read.read(file: pathlib.Path, channels: List[str] = None) → Dict[str, Union[Dict[str, Union[numpy.ndarray, str, pathlib.Path]], Dict[str, Union[List[str], numpy.ndarray, str, pathlib.Path]], Dict[str, Union[int, numpy.ndarray, str, pathlib.Path]], Dict[str, Union[int, List[int], str, numpy.ndarray, pathlib.Path]]]][source]

Interface to read data files

Parameters:
  • file – Absolute path to data file. Only .mat files are currently supported.
  • channels – List of channel names, as they appeared in the original .smr file. Example: [‘biceps’, ‘triceps’, ‘torque’] If not included, all channels will be processed.
Raises:

WrongFileTypefile parameter is not a .mat file

Returns:

Data from a trial where keys are channel names and values are deeply nested numpy.ndarray

Return type:

dict