Example #1
0
def main(**kwargs):
    p = Path(kwargs['folder_path'])
    f_list = list(p.glob('**/*dat'))
    outdir = p / 'results_animated'
    outdir.mkdir(exist_ok=True, parents=True)
    for fi, f in enumerate(f_list):
        print(f"[info] Analysing file {f.name}")
        itr_no = 0
        seg_no = 0
        Vm_trail = []
        f_path = f
        f = str(f)
        segments = nio.StimfitIO(f).read_block().segments
        for si, segment in enumerate(segments):
            #print('analysing the segment ',segment)
            analog_signals = segment.analogsignals
            #print(analog_signals)
            for ti, trace in enumerate(analog_signals):
                itr_no += 1
                v = trace
                v = np.ravel(v)
                if '1.0 pA' == str(v.units):
                    print('x 1pA')
                    continue
                if np.isnan(v)[0] == True:
                    print('x Vnan')
                    continue
                if itr_no != 1:
                    traces = 'traces compiled'
                else:
                    traces = 'trace_alone'
                print(f'trace {ti}', end=', ')
                protocol_type = 'Current_clamp'
                v = v.magnitude
                v = ssig.resample(v, 5000)
                tf = trace.t_stop
                ti = trace.t_start
                t = np.linspace(0, float(tf - ti), len(v))
                t = ssig.resample(t, 5000)
                data = np.array([t, v])
                fig1 = plt.figure()
                l, = plt.plot([], [], 'r-')
                plt.xlim(0, 1.2)
                plt.ylim(-100, 60)
                plt.xlabel('time(s)')
                plt.ylabel('signal amplitude (mV)')
                plt.title('training the slice')
                line_ani = animation.FuncAnimation(fig1,
                                                   update_line,
                                                   5000,
                                                   fargs=(data, l),
                                                   interval=1,
                                                   blit=True)
                line_ani.save(f'{outdir}/{si}_{ti}_lines.mp4', writer=writer)
                plt.close()
"""
Created on Thu Sep 19 11:58:52 2019

@author: anzal
"""

import os
import neo.io as nio
import numpy as np
import matplotlib.pyplot as plt
from allensdk.ephys.ephys_extractor import EphysSweepFeatureExtractor

#Trace_with_features.spike_feature_keys()


file_to_read = nio.StimfitIO('/mnt/5D4B-FA71/Data/190822/trace_alone.dat')
segments = file_to_read.read_block().segments
iteration_number = 0
for segment in segments:
    #print(segment)
    analog_signals = segment.analogsignals
    #print(analog_signals)
    for trace in analog_signals:
        iteration_number += 1
        #print(trace)
        sampling_rate = trace.sampling_rate
        #print(sampling_rate)
        v = trace
        v = np.ravel(v)
        #pick only traces with current clamp data
        if '1.0 pA' == str(v.units):
    pass
try:
    os.mkdir(folder_to_read + '/Results/Current_clamp')
except:
    pass
#make the file path
results_folder = str(folder_to_read + '/Results/Current_clamp/')
#list out all the files with .dat extension for plotting
for root, dirs, files in os.walk(folder_to_read):
    for file in files:
        if file.endswith(".dat"):
            print(file)
            file_name = str(file).split(".")[0]
            print(file_name)
            #import the file of interest
            file_to_read = nio.StimfitIO(root + file)
            segments = file_to_read.read_block().segments
            #segments = ()
            iteration_number = 0
            segment_number = 0
            Vm_trail = []
            threshold_state = 0
            for segment in segments:
                segment_number += 1
                #                print(segment)
                analog_signals = segment.analogsignals
                #                print(analog_signals)
                for trace in analog_signals:
                    iteration_number += 1
                    #                    print(trace)
                    v = trace
def main(**kwargs):
    p = Path(kwargs['folder_path'])
    f_list = list(p.glob('**/*dat'))
    outdir = p / 'results'
    outdir.mkdir(exist_ok=True, parents=True)
    for fi, f in enumerate(f_list):
        print(f"[info] Analysing file {f.name}")
        itr_no = 0
        seg_no = 0
        Vm_trail = []
        f_path = f
        f = str(f)
        segments = nio.StimfitIO(f).read_block().segments
        print(len(segments))
        fig = plt.figure(figsize=(8, 5))
        thresh_state = 0
        ax = fig.add_subplot(111)
        for si, segment in enumerate(segments):
            seg_no += 1
            fI = 10000 * fi + si
            #print('analysing the segment ',segment)
            analog_signals = segment.analogsignals
            #print(analog_signals)
            for ti, trace in enumerate(analog_signals):
                itr_no += 1
                v = trace
                v = np.ravel(v)
                if '1.0 pA' == str(v.units):
                    print('x 1pA')
                    continue
                if np.isnan(v)[0] == True:
                    print('x Vnan')
                    continue
                if itr_no != 1:
                    traces = 'traces compiled'
                else:
                    traces = 'trace_alone'
                print(f'trace {ti}', end=', ')
                protocol_type = 'Current_clamp'
                v = v.magnitude
                tf = trace.t_stop
                ti = trace.t_start
                t = np.linspace(0, float(tf - ti), len(v))
                ax.plot(t, v, label='trace numer = ' + str(itr_no))
                try:
                    Trace_with_features = extractor(
                        t=t,
                        v=v,
                        filter=float(trace.sampling_rate) / 2500,
                        min_peak=-20.0,
                        dv_cutoff=20.0,
                        max_interval=0.005,
                        min_height=2.0,
                        thresh_frac=0.05,
                        baseline_interval=0.1,
                        baseline_detect_thresh=0.3,
                        id=None)
                    Trace_with_features.process_spikes()
                    neuron_threshold_v = Trace_with_features.spike_feature(
                        "threshold_v")
                    if thresh_state == 0 and len(neuron_threshold_v) >= 1:
                        neuron_threshold_v = Trace_with_features.spike_feature(
                            "threshold_v")[0]
                        neuron_threshold_t = Trace_with_features.spike_feature(
                            "threshold_t")[0]
                        Threshold_voltage = str(
                            'threshold voltage ' +
                            str(np.around(neuron_threshold_v, decimals=2)) +
                            "mV")
                        ax.plot(neuron_threshold_t,
                                neuron_threshold_v,
                                'o',
                                color='k',
                                label='Firing threshold')
                        plt.figtext(.05,
                                    0.0,
                                    Threshold_voltage + "mV",
                                    fontsize=12,
                                    va="top",
                                    ha="left")
                        thresh_state = 1
                except Exception as e:
                    print('Could not be plotted:', e)
        ax.legend()
        ax.set_ylabel('signal amplitude in ' + str(trace[0]).split()[1])
        ax.set_xlabel('time (s)')
        ax.set_ylim([-100, 60])
        ax.set_title('recording type: ' + str(trace.name).split("-")[0] + ' ' +
                     str(seg_no) + ' of  ' + 'traces')
        outfile = str(outdir) + "/" + str(
            f_path.stem) + " " + f'{fI}_compiled.svg'
        plt.savefig(outfile, bbox_inches="tight")
        print('---> Saved to %s' % outfile)
        fig = plt.close()

        itr_no = 0
        seg_no = 0
        thresh_state = 0
        for si, segment in enumerate(segments):
            seg_no += 1
            fI = 10000 * fi + si
            #print('analysing the segment ',segment)
            analog_signals = segment.analogsignals
            #print(analog_signals)
            for ti, trace in enumerate(analog_signals):
                fig1 = plt.figure(figsize=(8, 5))
                ax1 = fig1.add_subplot(111)
                TI = 100001 * fI + ti
                itr_no += 1
                v = trace
                v = np.ravel(v)
                if '1.0 pA' == str(v.units):
                    print('x 1pA')
                    continue
                if np.isnan(v)[0] == True:
                    print('x Vnan')
                    continue
                if itr_no != 1:
                    traces = 'traces compiled'
                else:
                    traces = 'trace_alone'
                print(f'trace {ti}', end=', ')
                protocol_type = 'Current_clamp'
                trace_unit = str(v.units).split('.')[1]
                v = v.magnitude
                tf = trace.t_stop
                ti = trace.t_start
                t = np.linspace(0, float(tf - ti), len(v))
                Vm_i = np.mean(v[0:299])
                Vm_f = np.mean(v[len(v) - 300:len(v)])
                del_Vm = Vm_f - Vm_i
                ax1.plot(t, v, label='trace numer = ' + str(itr_no))
                plt.figtext(0.05,
                            0.00,
                            'sampling rate* total time = ' + str(
                                np.around(float(trace.sampling_rate) *
                                          (float(tf - ti)),
                                          decimals=2)),
                            fontsize=12,
                            va="top",
                            ha="left")
                plt.figtext(0.05,
                            -0.05,
                            'sampling rate = ' + str(trace.sampling_rate),
                            fontsize=12,
                            va="top",
                            ha="left")
                plt.figtext(0.05,
                            -0.10,
                            'total time of recording = ' +
                            str(np.around(tf - ti, decimals=2)),
                            fontsize=12,
                            va="top",
                            ha="left")
                plt.figtext(0.05,
                            -0.15,
                            'Number of data points in the trace = ' +
                            str(len(v)),
                            fontsize=12,
                            va="top",
                            ha="left")
                plt.figtext(0.05,
                            -0.20,
                            'membrane voltage variation : ' +
                            str(np.around(del_Vm, decimals=2)) + trace_unit,
                            fontsize=12,
                            va="top",
                            ha="left")
                plt.figtext(0.05,
                            -0.25,
                            'membrane voltage after : ' +
                            str(np.around(Vm_f, decimals=1)) + trace_unit,
                            fontsize=12,
                            va="top",
                            ha="left")
                plt.figtext(0.05,
                            -0.30,
                            'membrane voltage before : ' +
                            str(np.around(Vm_i, decimals=1)) + trace_unit,
                            fontsize=12,
                            va="top",
                            ha="left")
                try:
                    Trace_with_features = extractor(
                        t=t,
                        v=v,
                        filter=float(trace.sampling_rate) / 2500,
                        min_peak=-20.0,
                        dv_cutoff=20.0,
                        max_interval=0.005,
                        min_height=2.0,
                        thresh_frac=0.05,
                        baseline_interval=0.1,
                        baseline_detect_thresh=0.3,
                        id=None)
                    Trace_with_features.process_spikes()
                    neuron_threshold_v = Trace_with_features.spike_feature(
                        "threshold_v")
                    if thresh_state == 0 and len(neuron_threshold_v) >= 1:
                        neuron_threshold_v = Trace_with_features.spike_feature(
                            "threshold_v")[0]
                        neuron_threshold_t = Trace_with_features.spike_feature(
                            "threshold_t")[0]
                        Threshold_voltage = str(
                            'threshold voltage = ' +
                            str(np.around(neuron_threshold_v, decimals=2)) +
                            "mV")
                        ax1.plot(neuron_threshold_t,
                                 neuron_threshold_v,
                                 'o',
                                 color='r',
                                 label='Firing Threshold')
                        plt.figtext(.05,
                                    -0.35,
                                    Threshold_voltage + "mV",
                                    fontsize=12,
                                    va="top",
                                    ha="left")
                        thresh_state = 1
                except Exception as e:
                    print('Could not be plotted:', e)
                ax1.legend()
                ax1.set_ylabel('signal amplitude in ' +
                               str(trace[0]).split()[1])
                ax1.set_xlabel('time (s)')
                ax1.set_ylim([-100, 60])
                ax1.set_title('recording type: ' +
                              str(trace.name).split("-")[0] + ': single trace')
                outfile = str(outdir) + "/" + str(
                    f_path.stem) + " " + f'{TI}.svg'
                plt.savefig(outfile, bbox_inches="tight")
                print('---> Saved to %s' % outfile)
                fig1 = plt.close()
"""

import os
import numpy as np
import neo.io as nio
import matplotlib.pyplot as plt

#set the directory path with files to read
folder_to_read = "/home/anzal/Documents/trial_sulu"
#list out all the files with .mat extension for plotting
for root, dirs, files in os.walk(folder_to_read):
    for file in files:
        if file.endswith(".abf"):
            print(file)
            #import the file of interest
            file_to_read = nio.StimfitIO(root + file)
            segments = ()
            for trace in file_to_read.read_block().segments:
                segments += (trace, )
                print(segments)
                for segment in segments:
                    for trace in segment.analogsignals:
                        print(trace.sampling_rate)
                        v = trace
                        print(trace)
                        ti = trace.t_start
                        print(trace.t_start)
                        tf = trace.t_stop
                        print(trace.t_stop)
                        tp = float(tf - ti)
                        print(float(tf - ti))
def main(**kwargs):
    p = Path(kwargs['folder_path'])
    f_list = list(p.glob('**/*.dat'))
    outdir = p / 'results'
    outdir.mkdir(exist_ok=True, parents=True)
    for fi, f in enumerate(f_list):
        print(f"[info] Analysing file {f.name}")
        itr_no = 0
        seg_no = 0
        Vm_trail = []
        thresh_state = 0
        f_path = f
        f = str(f)
        segments = nio.StimfitIO(f).read_block().segments
        fig = plt.figure(figsize=(8, 5))
        ax = fig.add_subplot(111)
        for si, segment in enumerate(segments):
            seg_no += 1
            fI = 10000 * fi + si
            #print('analysing the segment ',segment)
            analog_signals = segment.analogsignals
            #print(analog_signals)
            for ti, trace in enumerate(analog_signals):
                itr_no += 1
                v = trace
                v = np.ravel(v)
                if '1.0 pA' == str(v.units):
                    print('x 1pA')
                    continue
                if np.isnan(v)[0] == True:
                    print('x Vnan')
                    continue
                if itr_no != 1:
                    traces = 'traces compiled'
                else:
                    traces = 'trace_alone'
                print(f'trace {ti}', end=', ')
                protocol_type = 'Current_clamp'
                v = v.magnitude
                Vm_trace = np.mean(v[len(v) - 300:len(v)])
                tf = trace.t_stop
                ti = trace.t_start
                t = np.linspace(0, float(tf - ti), len(v))
                ax.plot(t, v, label='trace numer = ' + str(itr_no))

                try:
                    Trace_with_features = extractor(
                        t=t,
                        v=v,
                        filter=float(trace.sampling_rate) / 2500,
                        min_peak=-20.0,
                        dv_cutoff=20.0,
                        max_interval=0.005,
                        min_height=2.0,
                        thresh_frac=0.05,
                        baseline_interval=0.1,
                        baseline_detect_thresh=0.3,
                        id=None)
                    Trace_with_features.process_spikes()
                    neuron_threshold_v = Trace_with_features.spike_feature(
                        "threshold_v")
                    if thresh_state == 0 and len(neuron_threshold_v) >= 1:
                        neuron_threshold_v = Trace_with_features.spike_feature(
                            "threshold_v")[0]
                        neuron_threshold_t = Trace_with_features.spike_feature(
                            "threshold_t")[0]
                        trough_v = Trace_with_features.spike_feature(
                            "trough_v")[0]
                        trough_t = Trace_with_features.spike_feature(
                            "trough_t")[0]
                        ax.plot(neuron_threshold_t,
                                neuron_threshold_v,
                                'o',
                                color='k',
                                label='threshold voltage')
                        ax.plot(trough_t,
                                trough_v,
                                'o',
                                color='r',
                                label='trough_v')
                        ax.figtext(
                            1, 0.20, "trough_v = " +
                            str(np.around(trough_v, decimals=2)) + "mV")
                        ax.figtext(
                            1, 0.15, "trough_t = " +
                            str(np.around(trough_t, decimals=2)) + 's')
                        threshold_state = 1
                except Exception as e:
                    print('Could not be plotted:', e)
        ax.legend()
        ax.set_ylabel('signal amplitude in ' + str(trace[0]).split()[1])
        ax.set_xlabel('time (s)')
        ax.set_title('recording type: ' + str(trace.name).split("-")[0] + ' ' +
                     str(len(segments)) + ' ' + traces +
                     ' of segment number ' + str(seg_no))
        outfile = str(outdir) + "/" + str(
            f_path.stem) + " " + f'{fI}_compiled.png'
        plt.savefig(outfile)
        print('---> Saved to %s' % outfile)
        fig = plt.close()
Example #7
0
def main(**kwargs):
    p = Path(kwargs['folder_path'])
    f_list = list(p.glob('**/*abf'))
    outdir = p / 'results'
    outdir.mkdir(exist_ok=True, parents=True)
    for fi, f in enumerate(f_list):
        print(f"[info] Analysing file {f.name}")
        itr_no = 0
        seg_no = 0
        Vm_trail = []
        f_path = f
        f = str(f)
        segments = nio.StimfitIO(f).read_block().segments
        #        fig = plt.figure(figsize=(8,5))
        #        thresh_state = 0
        #        ax = fig.add_subplot(111)
        #        for si, segment in  enumerate(segments):
        #            seg_no +=1
        #            fI = 10000*fi + si
        #            #print('analysing the segment ',segment)
        #            analog_signals = segment.analogsignals
        #            #print(analog_signals)
        #            for ti, trace in enumerate(analog_signals):
        #                itr_no += 1
        #                v = trace
        #                v = np.ravel(v)
        #                if '1.0 mV' == str(v.units):
        #                    print('x 1mV')
        #                    continue
        #                if np.isnan(v)[0] == True:
        #                    print('x Vnan')
        #                    continue
        #                if itr_no != 1:
        #                    traces = 'traces compiled'
        #                else:
        #                    traces = 'trace_alone'
        #                print(f'trace {ti}', end=', ')
        #                protocol_type = 'Voltage_clamp'
        #                v = v.magnitude
        #                tf = trace.t_stop
        #                ti = trace.t_start
        #                t = np.linspace(0,float(tf - ti), len(v))
        #                ax.plot(t,v,label = 'trace numer = '+str(itr_no))
        ##                try:
        ##                 Trace_with_features = extractor(t=t, v=v, filter = float(trace.sampling_rate)/2500,min_peak=-20.0, dv_cutoff=20.0, max_interval=0.005, min_height=2.0, thresh_frac=0.05, baseline_interval=0.1, baseline_detect_thresh=0.3, id=None)
        ##                 Trace_with_features.process_spikes()
        ##                 neuron_threshold_v = Trace_with_features.spike_feature("threshold_v")
        ##                 if thresh_state == 0 and len(neuron_threshold_v) >=1:
        ##                     neuron_threshold_v = Trace_with_features.spike_feature("threshold_v")[0]
        ##                     neuron_threshold_t = Trace_with_features.spike_feature("threshold_t")[0]
        ##                     Threshold_voltage = str('threshold voltage ' +str(np.around(neuron_threshold_v, decimals = 2))+"mV")
        ##                     ax.plot(neuron_threshold_t,neuron_threshold_v,'o', color ='k',label = 'Firing threshold')
        ##                     plt.figtext(.05, 0.0, Threshold_voltage +"mV",fontsize=12, va="top", ha="left")
        ##                     thresh_state = 1
        ##                except Exception as e:
        ##                     print('Could not be plotted:', e)
        #        ax.legend()
        #        ax.set_ylabel('signal amplitude in '+str(trace[0]).split()[1])
        #        ax.set_xlabel('time (s)')
        #        #ax.set_ylim([0,10])
        #        ax.set_xlim([2,5])
        #        ax.set_title('recording type: '+str(trace.name).split("-")[0]+' '+str(len(segments))+' '+str(trace)+ ' of segment number '+ str(seg_no))
        #        outfile = str(outdir)+"/"+str(f_path.stem)+" "+f'{fI}_compiled.png'
        #        plt.savefig(outfile, bbox_inches = "tight")
        #        print('---> Saved to %s' % outfile)
        #        fig = plt.close()

        itr_no = 0
        seg_no = 0
        thresh_state = 0
        fig1 = plt.figure(figsize=(16, 12))
        sub_plt_no = 0
        for si, segment in enumerate(segments):
            seg_no += 1
            fI = 10000 * fi + si
            #print('analysing the segment ',segment)
            analog_signals = segment.analogsignals
            subplot_index = np.arange(
                1,
                len(segments) * len(analog_signals) + 1).reshape(
                    [len(segments), len(analog_signals)]).transpose().ravel()
            #print(analog_signals)
            for ti, trace in enumerate(analog_signals):
                ax1 = fig1.add_subplot(len(analog_signals), len(segments),
                                       subplot_index[sub_plt_no])
                sub_plt_no += 1
                TI = 100001 * fI + ti
                itr_no += 1
                v = trace
                v = np.ravel(v)
                if '1.0 mV' == str(v.units):
                    print('x 1mV')
                    continue
                if np.isnan(v)[0] == True:
                    print('x Vnan')
                    continue
                if itr_no != 1:
                    traces = 'traces compiled'
                else:
                    traces = 'trace_alone'
                print(f'trace {ti}', end=', ')
                protocol_type = 'Voltage_clamp'
                trace_unit = str(v.units).split('.')[1]
                v = v.magnitude
                tf = trace.t_stop
                ti = trace.t_start
                t = np.linspace(0, float(tf - ti), len(v))
                Vm_i = np.mean(v[0:299])
                Vm_f = np.mean(v[len(v) - 300:len(v)])
                del_Vm = Vm_f - Vm_i
                ax1.plot(t, v, label='trace numer = ' + str(itr_no))
                #                plt.figtext(0.05, 0.00, 'sampling rate* total time = ' + str(np.around(float(trace.sampling_rate)*(float(tf-ti)),decimals=2)),fontsize=12, va="top", ha="left")
                #                plt.figtext(0.05, -0.05, 'sampling rate = ' + str(trace.sampling_rate),fontsize=12, va="top", ha="left")
                #                plt.figtext(0.05, -0.10, 'total time of recording = ' + str(np.around(tf-ti, decimals=2)),fontsize=12, va="top", ha="left")
                #                plt.figtext(0.05, -0.15, 'Number of data points in the trace = ' + str(len(v)),fontsize=12, va="top", ha="left")
                #                plt.figtext(0.05, -0.20, 'membrane voltage variation : ' + str(np.around(del_Vm, decimals = 2))+trace_unit,fontsize=12, va="top", ha="left")
                #                plt.figtext(0.05, -0.25, 'membrane voltage after : ' + str(np.around(Vm_f,decimals = 1))+trace_unit,fontsize=12, va="top", ha="left")
                #                plt.figtext(0.05, -0.30, 'membrane voltage before : ' + str(np.around(Vm_i,decimals =1))+trace_unit,fontsize=12, va="top", ha="left")
                #                try:
                #                 Trace_with_features = extractor(t=t, v=v, filter = float(trace.sampling_rate)/2500,min_peak=-20.0, dv_cutoff=20.0, max_interval=0.005, min_height=2.0, thresh_frac=0.05, baseline_interval=0.1, baseline_detect_thresh=0.3, id=None)
                #                 Trace_with_features.process_spikes()
                #                 neuron_threshold_v = Trace_with_features.spike_feature("threshold_v")
                #                 if thresh_state == 0 and len(neuron_threshold_v) >=1:
                #                     neuron_threshold_v = Trace_with_features.spike_feature("threshold_v")[0]
                #                     neuron_threshold_t = Trace_with_features.spike_feature("threshold_t")[0]
                #                     Threshold_voltage = str('threshold voltage = ' +str(np.around(neuron_threshold_v, decimals = 2))+"mV")
                #                     ax1.plot(neuron_threshold_t,neuron_threshold_v,'o', color ='r',label = 'Firing Threshold')
                #                     plt.figeext(.05, -0.35, Threshold_voltage +"mV",fontsize=12, va="top", ha="left")
                #                     thresh_state = 1
                #                except Exception as e:
                #                     print('Could not be plotted:', e)
                ax1.legend()
                ax1.set_ylabel('signal amplitude in ' +
                               str(trace[0]).split()[1])
                ax1.set_xlabel('time (s)')
                #ax1.set_ylim([0,10])
                ax1.set_xlim([2, 5])
                ax1.set_title(str(trace.name).split("-")[0])
        plt.suptitle(
            "Readings from 3 different channels(subplot titlle:channel Id)",
            size=16)
        plt.subplots_adjust(left=None,
                            bottom=None,
                            right=None,
                            top=0.9,
                            wspace=0.3,
                            hspace=0.5)
        #        plt.tight_layout()
        outfile = str(outdir) + "/" + str(f_path.stem) + " " + f'{TI}.png'
        plt.savefig(outfile, bbox_inches="tight")
        print('---> Saved to %s' % outfile)
        plt.close()
except:
    pass
#make the file path
results_folder = str(folder_to_read + '/Results/Current_clamp/')
#list out all the files with .dat extension for plotting
files = glob.glob(folder_to_read + '/*.dat', recursive=True)

#for root, dirs, files in os.walk(folder_to_read):
for file in files:
    #        if file.endswith(".dat"):
    #            print(file)
    file_name = str(file).split('/')[-1].split(".")[0]
    #            print (file_name)
    #import the file of interest
    # file_to_read = nio.StimfitIO(file)
    segments = nio.StimfitIO(file).read_block().segments
    # segments = ()
    iteration_number = 0
    segment_number = 0
    Vm_trail = []
    threshold_state = 0
    for segment in segments:
        segment_number += 1
        #                print(segment)
        analog_signals = segment.analogsignals
        #                print(analog_signals)
        for trace in analog_signals:
            iteration_number += 1
            #                    print(trace)
            v = trace
            v = np.ravel(v)