spkit.mea.activation_time_loc

spkit.mea.activation_time_loc(X, fs=25000, t_range=[None, None], method='min_dvdt', gradient_method='fdiff', sg_window=11, sg_polyorder=3, gauss_window=0, gauss_itr=1, plot=False, plot_dur=2, figsize=(12, 3), **kwargs)

Compute Activation Time of multi-channel signals

Compute Activation Time of multi-channel signals

Same as ‘Get Activation Time based on Gradient’

Activation Time in cardiac electrograms refered to as time at which depolarisation of cells/tissues/heart occures.

For biological signals (e.g. cardiac electorgram), an activation time in signal is reflected by maximum negative deflection, which is equal to min-dvdt, if signal is a volatge signal and function of time x = v(t) However, simply computing derivative of signal is sometime misleads the activation time location, due to noise, so derivative of a given signal has be computed after pre-processing

Parameters:
Xnd-array
  • Single Cycle of each channel containing EGM

  • with shape = (nch,n),

  • where nch: number of channels, n: number of samples,

fs: int, default=25000
  • sampling frequency of signal,

t_range: list of [t0 (ms),t1 (ms)]
  • range of time to restrict the search of activation time during t0 ms to t1 ms

  • if t_range=[None,None], whole input signal is considered for search

  • if t_range=[t0,None], excluding signal before t0 ms

  • if t_range=[None,t1], excluding signal after t1 ms for search

method: str, default=”min_dvdt”
  • Method to compute activation time

  • one of (“max_dvdt”, “min_dvdt”, “max_abs_dvdt”)

  • for more detail spkit.get_activation_time

gradient_method: str, default=’fdiff’
  • Method to compute gradient of signal

  • one of (“fdiff”, “fgrad”, “npdiff”,”sgdiff”,”sgdrift_diff”,”sgsmooth_diff”, “gauss_diff”)

  • check spkit.signal_diff

Parameters for gradient_method:
  • used if gradient_method in one of (“sgdiff”,”sgdrift_diff”,”sgsmooth_diff”, “gauss_diff”)

  • sg_window: sgolay-filter’s window length

  • sg_polyorder: sgolay-filter’s polynomial order

  • gauss_window: window size of gaussian kernel for smoothing,

  • check help(signal_diff) from sp.signal_diff

plot:int, default=False
  • If true, plot 3 figures for each channel

-(1) Full signal trace with activation time -(2) Segment of signal from loc-plot_dur to loc+plot_dur -(3) Derivative of signal, with with activation time

plot_dur: scalar, default=2,
  • duration in seconds to plot, if plot=True

  • segment of signal from loc-plot_dur to loc+plot_dur

  • default=2s

Returns:
at_loc: 1d-array
  • array of length=nch, location of activation time as index

  • to convert it in seconds, at_loc/fs

Examples

#sp.mea.activation_time_loc
import numpy as np
import matplotlib.pyplot as plt
import os, requests
import spkit as sp

# Download Sample file if not done already

file_name= 'MEA_Sample_North_1000mV_1Hz.h5'

if not(os.path.exists(file_name)):
    path = 'https://spkit.github.io/data_samples/files/MEA_Sample_North_1000mV_1Hz.h5'
    req = requests.get(path)
    with open(file_name, 'wb') as f:
            f.write(req.content)

##############################
# Step 1: Read File
fs = 25000
X,fs,ch_labels = sp.io.read_hdf(file_name,fs=fs,verbose=1)

##############################
# Step 2: Stim Localisation
stim_fhz = 1
stim_loc,_  = sp.mea.get_stim_loc(X,fs=fs,fhz=stim_fhz, plot=0,verbose=0,N=None)

##############################
# Step 3: Align Cycles

exclude_first_dur=2
dur_after_spike=500
exclude_last_cycle=True

XB = sp.mea.align_cycles(X,stim_loc,fs=fs, exclude_first_dur=exclude_first_dur,dur_after_spike=dur_after_spike,
                        exclude_last_cycle=exclude_last_cycle,pad=np.nan,verbose=True)

print('Number of EGMs/Cycles per channel =',XB.shape[2])

##############################
# Step 4: Average Cycles or Select one

egm_number = -1

if egm_number<0:
    X1B = np.nanmean(XB,axis=2)
    print(' -- Averaged All EGM')
else:
    # egm_number should be between from 0 to 'Number of EGMs/Cycles per channel '
    assert egm_number in list(range(XB.shape[2]))
    X1B = XB[:,:,egm_number]
    print(' -- Selected EGM ->',egm_number)

print('EGM Shape : ',X1B.shape)

##############################
# Step 5: Activation Time

at_range = [0, 100]

at_loc = sp.mea.activation_time_loc(X1B,fs=fs,t_range=at_range,plot=False)

at_loc_ms = 1000*at_loc/fs

AT_grid = sp.mea.arrange_mea_grid(at_loc_ms, ch_labels=ch_labels)
sp.mea.mat_1_show(AT_grid, vmax=20,title='Activation Time (ms)', label = ('ms'))
../../_images/spkit-mea-activation_time_loc-1.png

Examples using spkit.mea.activation_time_loc

MEA: Step-wise Analysis: Example

MEA: Step-wise Analysis: Example