wonambi.attr.chan module
Module to work with channels.
It provides a general class to work with channels. Channels is the general term that refers to the points where signal comes from, it’s an abstract concept. Electrodes, magnetometer, axiometers and gradiometers are the actual recording devices measuring the signal. For example, in the case of EEG, you need two electrodes to have one signal, where one signal is the difference between the two electrodes.
In other words, the channel is where you want to plot the signal.
- class wonambi.attr.chan.Chan(label, xyz=None, unit=None, attr=None)[source]
Bases:
object
Provide class Chan, for individual channels.
- Parameters:
label (str) – name of the channel
xyz (numpy.ndarray or list or tuple) – 1d vector of 3 elements
chtype (str, optional) – channel type (can be any string)
unit (str, optional) – units, using SI
attr (dict) – dictionary where you can store additional information per channel. Use chan.attr.update({‘new_key’: new_value})
- class wonambi.attr.chan.Channels(*args)[source]
Bases:
object
Provide class Chan, generic class for channel location.
You can read from a file, and then you pass only one argument. Or you can directly assign the chan names and the coordinates.
- Parameters:
chan (list of instance of Chan) – list of channels (which are instances of Chan)
chan_input (various formats) – information about the channels
labels (list of str) – the name of the channel
coords (numpy.ndarray) – location in 3D, with shape (n_chan, 3)
- chan
list of channels
- Type:
list of instance of wonambi.attr.chan.Chan
- Raises:
UnrecognizedFormat – If the format is not recognized
Notes
chan_input can be a csv file without header and with format: label, x-pos, y-pos, z-pos or an sfp file without header and with format: label x-pos y-pos z-pos
- export(elec_file)[source]
Export channel name and location to file.
- Parameters:
elec_file (Path or str) – path to file where to save csv
- property n_chan
Returns the number of channels.
- return_attr(attr, labels=None)[source]
return the attributes for each channels.
- Parameters:
attr (str) – attribute specified in Chan.attr.keys()
- return_label()[source]
Returns the labels for all the channels.
- Returns:
list of str – list of the channel labels.
- wonambi.attr.chan.assign_region_to_channels(channels, anat, parc_type='aparc', max_approx=3, exclude_regions=None)[source]
Assign a brain region based on the channel location.
- Parameters:
channels (instance of wonambi.attr.chan.Channels) – channels to assign regions to
anat (instance of wonambi.attr.anat.Freesurfer) – anatomical information taken from freesurfer.
parc_type (str) – ‘aparc’, ‘aparc.a2009s’, ‘BA’, ‘BA.thresh’, or ‘aparc.DKTatlas40’ ‘aparc.DKTatlas40’ is only for recent freesurfer versions
max_approx (int, optional) – approximation to define position of the electrode.
exclude_regions (list of str or empty list) – do not report regions if they contain these substrings. None means that it does not exclude any region. For example, to exclude white matter regions and unknown regions you can use exclude_regions=(‘White’, ‘WM’, ‘Unknown’)
- Returns:
instance of wonambi.attr.chan.Channels – same instance as before, now Chan have attr ‘region’
- wonambi.attr.chan.create_sphere_around_elec(xyz, template_mri, distance=8, freesurfer=None)[source]
Create an MRI mask around an electrode location,
- Parameters:
xyz (ndarray) – 3x0 array
template_mri (path or str (as path) or nibabel.Nifti) – (path to) MRI to be used as template
distance (float) – distance in mm between electrode and selected voxels
freesurfer (instance of Freesurfer) – to adjust RAS coordinates, see Notes
- Returns:
3d bool ndarray – mask where True voxels are within selected distance to the electrode
Notes
Freesurfer uses two coordinate systems: one for volumes (“RAS”) and one for surfaces (“tkReg”, “tkRAS”, and “Surface RAS”), so the electrodes might be stored in one of the two systems. If the electrodes are in surface coordinates (f.e. if you can plot surface and electrodes in the same space), then you need to convert the coordinate system. This is done by passing an instance of Freesurfer.
- wonambi.attr.chan.detect_format(filename)[source]
Detect file format of the channels based on extension.
- Parameters:
filename (Path) – name of the filename
- Returns:
str – file format
- wonambi.attr.chan.find_chan_in_region(channels, anat, region_name)[source]
Find which channels are in a specific region.
- Parameters:
channels (instance of wonambi.attr.chan.Channels) – channels, that have locations
anat (instance of wonambi.attr.anat.Freesurfer) – anatomical information taken from freesurfer.
region_name (str) – the name of the region, according to FreeSurferColorLUT.txt
- Returns:
chan_in_region (list of str) – list of the channels that are in one region.
- wonambi.attr.chan.find_channel_groups(chan)[source]
Channels are often organized in groups (different grids / strips or channels in different brain locations), so we use a simple heuristic to get these channel groups.
- Parameters:
chan (instance of Channels) – channels to group
- Returns:
groups (dict) – channel groups: key is the common string, and the item is a list of labels