SignalManager
The SignalManager comes with some basic parameters.
field | description |
---|---|
fs | sampling frequency |
num_channels | number of channels |
channel_names | name for each channel |
data | the signal in the structure of (epoch x channel x signal) |
t | time vector |
epochs | number of epochs |
tags | position of tags in signal |
spectrum | matrix of spectrum |
spectrum_freqs | vector of frequencies |
phase | matrix of phase |
history | a list of all the steps taken |
When initializing the object there are two options.
Generator
A dictionary of the structure
data = {
'fs': # float,
'num_channels': # integer,
'channel_names': # list of strings,
'epochs': # integer,
't': # time array,
'tags': # list,
'data': # Signal Matrix
}
saffy.SignalManager(generator=data)
Filename
The name of the file generated by Svarog. 3 files eg. data.raw
, data.xml
, data.tag
saffy.SignalManager(filename='data')
set_tags_from_channel(self, channel_name)
Uses a channel as the tag indicator. Normalizes the value to 1 through divided by the maximum value. Sets threshold at 0.9. Sets tag at beginnings of resultant clusters.
Params
- channel_name: the string name of the channel to set tags from.
set_epochs_from_tags(self, low, high)
Uses the tag list to cut the data into epochs. The low
and high
tell us where to cut
based on the tags. They are in seconds. For example if you want to cut between 2 seconds before and 3 after the tag you would write
sig.set_epochs_from_tags(-2, 3)
.
Params
- low: In seconds. Starting time of the epoch relative to the tag. The tag is 0 seconds.
- high: In seconds. Ending time of the epoch relative to the tag. The tag is 0 seconds.
remove_channels(self, channel_names)
Removes the specified channels from the data.
Params
- channel_names: list of strings
extract_channels(self, channel_names)
Removes all channels except for those provided in the channel_names
parameter.
Params
- channel_names: list of strings
extract_time_range(self, low, high)
Cuts data to the provided low
and high
arguments.
Params
- low: starting point of new signal in seconds.
- high: end point of new signal in seconds.
copy(self, name="")
Creates a independent copy of the SignalManager object.
Params
- name: a documenting value to keep track why we are coping the signal.
call(self, func)
Used to run single custom functions on the data. Allows consistency when building analysis piplines.
Params
- func: a function that takes only self as the parameter.
Example
You should do this:
def custom_function(self):
print(self.data)
sig.call(custom_function)
instead of this:
def custom_function(sig):
print(sig.data)
custom_function(sig)
register_plugin(cls, plugin)
Use this to add a custom plugin to be used with the SignalManager
Params
- plugin: An instance of the PluginManager class.
Example
Create a custom plugin.
class CustomPlugin(saffy.PluginManager):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.custom = {
'param': 'some value'
}
def custom_function(self):
# do something
pass
Then you can regiser it and use the custom_function
.
saffy.SignalManager.register_plugin(CustomPlugin)
History
All the operations on the signal are stored in the history parameter. It allows to keep track of the changes that have been made to the signal.
Chaining
Each method returns self, so chaining of functions is possible. For example setting tags could be done this way.
sig = SignalManager(filename='path/to/file')\
.extract_channels(['C3', 'C4', 'trig'])\
.set_tags_from_channel('trig')\
.remove_channel('trig')