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
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
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
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
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
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_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.
-
lowpass
(cutoff: Union[float, int], order: int = 4)[source]¶ Apply dual-pass Butterworth lowpass filter to 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¶
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: WrongFileType
– file parameter is not a .mat fileReturns: Data from a trial where keys are channel names and values are deeply nested numpy.ndarray
Return type: dict