Low-Level Function API
As well as providing convenient types for analysis. This package also provides low-level functions for dealing with data in its raw form. These low-level functions are described below.
Note: Currently sorting out the docs, so its a bit of a mess. Is there an automated way to list all functions using documenter?
Preprocessing
Filtering
Neuroimaging.compensate_for_filter
— Functioncompensate_for_filter(filter::FilterCoefficients, spectrum::AbstractArray, frequencies::AbstractArray, fs::Real)
Recover the spectrum of signal by compensating for filtering done.
Arguments
filter
: The filter used on the spectrumspectrum
: Spectrum of signalfrequencies
: Array of frequencies you want to apply the compensation tofs
: Sampling rate
Returns
Spectrum of the signal after comensating for the filter
Referencing
Neuroimaging.rereference
— Functionrereference(signals::Array{T,2}, refChan::Union{Int,Array{Int}}) where {T<:AbstractFloat}
rereference(signals::Array{T,2}, refChan::Union{S,Array{S}}, chanNames::Vector{S}) where {S<:AbstractString}
Re reference a signals to specific signal channel by index, or by channel name from supplied list.
If multiple channels are specififed, their average is used as the reference.
Arguments
signals
: Original signals to be modifiedrefChan
: Index or name of channels to be used as reference.chanNames
: List of channel names associated with signals array
Returns
Rereferenced signals
rereference(a::EEG, refChan::Union{AbstractString, Array{AbstractString}}; kwargs...)
Reference data to specified channel(s).
Example
a = rereference(a, "Cz")
# or
a = rereference(a, ["P9", "P10"])
Neuroimaging.remove_template
— Functionremove_template(signals::Array{T,2}, template::AbstractVector{T})
Remove a template signal from each column of an array
Arguments
signals
: Original signals to be modified (samples x channels)template
: Template to remove from each signal
Returns
Signals with template removed
Epoching
Neuroimaging.epoch_rejection
— Functionepoch_rejection(epochs::Array{T,3}, retain_percentage::AbstractFloat; rejection_method::Function = Neuroimaging.peak2peak) where {T<:Number}
Reject epochs based on the maximum peak to peak voltage within an epoch across all channels
Arguments
epochs
: Array containing the epoch data in the format samples x epochs x channelsretain_percentage
: The percentage of epochs to retainrejection_method
: Method to be used for epoch rejection (peak2peak)
Returns
- An array with a reduced amount of entries in the epochs dimension
epoch_rejection(a::EEG; retain_percentage::Number = 0.95, kwargs...)
Reject epochs such that retain_percentage
is retained.
Neuroimaging.peak2peak
— Functionpeak2peak(epochs::Array{T,3}) where {T<:Number}
Find the peak to peak value for each epoch to be returned to epoch_rejection()
Neuroimaging.extract_epochs
— FunctionExtract epoch data from array of channels.
Input
- Array of raw data. Samples x Channels
- Dictionary of trigger information
- Vector of valid trigger numbers
- Number of first triggers to remove
- Number of end triggers to remove
Example
epochs = extract_epochs(data, triggers, [1,2], 0, 0)
function extract_epochs(a::SSR; valid_triggers::Union{AbstractArray,Int} = [1, 2], remove_first::Int = 0, remove_last::Int = 0, kwargs...)
Extract epoch data from SSR
Arguments
a
: A SSR objectvalid_triggers
: Trigger numbers that are considered valid ([1,2])remove_first
: Remove the first n triggers (0)remove_last
: Remove the last n triggers (0)
Examples
epochs = extract_epochs(SSR, valid_triggers=[1,2])
Channels
Neuroimaging.match_sensors
— Functionmatch_sensors(sens::Array{S}, lbls::Array{AS}) where {AS<:AbstractString, S<:Sensor}
Match a set of electrodes to those provided
Examples
lf, valid = match_sensors(electrodes, sensor_labels)
Neuroimaging.channel_rejection
— Functionchannel_rejection(sigs::Array{T}, threshold_abs::Number, threshold_var::Number) where {T<:Number}
Reject channels with too great a variance.
Rejection can be based on a threshold or dynamicly chosen based on the variation of all channels.
Arguments
signals
: Array of data in format samples x channelsthreshold_abs
: Absolute threshold to remove channels with variance above this valuethreshold_std
: Reject channels with a variance more than n times the std of all channels
Returns
An array indicating the channels to be kept
Triggers
TODO: Make a type subsection similar to EEG and ASSR.
Neuroimaging.join_triggers
— FunctionAppend the trigger information of one EEG type to another. Places the trigger information at the end of first file
Example
join_triggers(a, b)
Neuroimaging.validate_triggers
— Functionvalidate_triggers(t::Dict)
Validate trigger channels have required keys and information.
Trigger information is stored in a dictionary containing three fields, all referenced in samples:
Index
: Start of triggerCode
: Code of triggerDuration
: Duration of trigger
Neuroimaging.clean_triggers
— Functionclean_triggers(t::Dict, valid_triggers::Array{Int}, min_epoch_length::Int, max_epoch_length::Int, remove_first::Int, max_epochs::Int)
Clean trigger channel information by removing specified epochs if they are too long or short. Can also remove the first trigger which often represent the start of a condition or measurement. Can also be used to limit the number of total epochs.
Dipoles
TODO: Make a type subsection similar to EEG and ASSR.
Neuroimaging.find_dipoles
— FunctionFind all dipole in an activity map.
Determines the local maxima in a 3 dimensional array
Input
- s: Activity in 3d matrix
- window: Windowing to use in each dimension for min max filter
- x,y,z: Coordinates associated with s matrix
Output
- dips: An array of dipoles
Neuroimaging.find_location
— FunctionFind index of location of coordinate or dipole in leadfield
Find indicies of location in VolumeImage